Advertisement
Guest User

Untitled

a guest
Oct 21st, 2014
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var lib = window.lib || {};
  2.  
  3.  
  4. lib.StringUtils = {
  5.  
  6.     //*********************   methods ***********************
  7.  
  8.     /**
  9.      * Removes the outermost quotes (pair of ' or ") from the string.
  10.      *
  11.      * @return If <code>s</code> contains no quotes as the first and last character, it is returned unchanged.
  12.      */
  13.     removeQuotes: function (s) {
  14.     },
  15.  
  16.     /**
  17.      * Checks if the string is a digit. (0-9)
  18.      *
  19.      * @usage if (StringUtils.isDigit(myChar)) {...}
  20.      * @param x; the string to test (only 1 character)
  21.      * @return true if the string is a digit, otherwise false
  22.      */
  23.     isDigit: function (x) {
  24.         if ((x.length == 0) || isNaN(x) || (x<0 || x>9)){
  25.             return false;
  26.         }
  27.         return true;
  28.     },
  29.  
  30.     /**
  31.      * Checks if the string is a letter.
  32.      *
  33.      * @usage if (StringUtils.isAlpha(myChar)) {...}
  34.      * @param x; the string to test (only 1 character)
  35.      // ---------------------------------------------------------------------------------------
  36.      // ---------------------------------------------------------------------------------------
  37.      // ---------------------------------------------------------------------------------------
  38.      * @param bUnderscore: Boolean, optional; default:false; if true, the returns true also for the the underscore "_": function
  39.      // ---------------------------------------------------------------------------------------
  40.      // ---------------------------------------------------------------------------------------
  41.      // ---------------------------------------------------------------------------------------
  42.      * @return true if the string is an alpha character A-Za-z. If the parameter bUnderscore is true, and the String is the underscore "_", the returns true, too.: function
  43.      */
  44.     isAlpha: function (x, bUnderscore) {
  45.         var ascii = x.charCodeAt(0);
  46.         // check if x is an undersore
  47.         if (ascii == 95 && bUnderscore == true)
  48.             return true;
  49.         // check if x is an alpha character
  50.         else if ((ascii > 64 && ascii < 91) || (ascii > 96 && ascii < 123))
  51.             return true;
  52.         return false;
  53.     },
  54.  
  55.     /**
  56.      * Checks if the string is an alphanumerical character.
  57.      *
  58.      * @usage if (StringUtils.isAlNum(myChar)) {...}
  59.      * @param x; the string to test (only 1 character)
  60.      * @param bUnderscore, optional; default:false; if true, the returns true also for the the underscore "_": function
  61.      * @return true, if the the string is the character 0-9a-zA-Z or (if bUnderscore is true), the underscore "_"
  62.      */
  63.     isAlNum: function (x, bUnderscore) {
  64.     },
  65.  
  66.     /**
  67.      * Converts common characters to their HTML character entities.
  68.      *
  69.      * @usage var sHTML = StringUtils.htmlEncode(myString);
  70.      * @param x; the string
  71.      * @return the HTML-encoded string.
  72.      */
  73.     htmlEncode: function (x) {
  74.     },
  75.  
  76.     /**
  77.      * Compares a string to a given list of srings
  78.      *
  79.      * @usage if (StringUtils.mEquals(myString,"a","aa","abc")) {...}
  80.      * @param s The string which is being compared
  81.      * @param compareStrings A variable list of compare strings
  82.      * @return true, if the string matches any of the compare strings (logical or)
  83.      */
  84.     mEquals: function (s) {
  85.     },
  86.  
  87.     /**
  88.      * Checks if a string starts with the compare string.
  89.      *
  90.      * @usage if (StringUtils.startsWith("hello world", "hel")) {...}
  91.      * @param s The string which is being checked
  92.      * @param compareString The compare string
  93.      * @return true, if the string <code>s</code> starts with the string <code>compareString</code>.
  94.      */
  95.     startsWith: function (s, compareString) {
  96.         if (s.indexOf(compareString) == 0)
  97.             return true;
  98.         return false;
  99.     },
  100.  
  101.     /**
  102.      * Checks, if s starts with at least one of the compare strings
  103.      *
  104.      * @usage if (StringUtils.mStartsWith("hello world","hal","hel","hello")) {...}
  105.      * @param s The string wich is being checked
  106.      * @param compareString A variable list of compare strings
  107.      * @return true, if the string starts with at least one of the compare strings
  108.      */
  109.     mStartsWith: function (s) {
  110.     },
  111.  
  112.     /**
  113.      * Checks if a string ends with the compare string.
  114.      *
  115.      * @usage if (StringUtils.endsWith("hello world", "hel")) {...}
  116.      * @param s The string which is being checked
  117.      * @param compareString The compare string
  118.      * @return true, if the string <code>s</code> ends with the string <code>compareString</code>.
  119.      */
  120.     endsWith: function (s, compareString) {
  121.     },
  122.  
  123.     /**
  124.      * Checks, if s ends with at least one of the compare strings
  125.      *
  126.      * @usage if (StringUtils.mEndsWith("hello world","hal","hel","hello")) {...}
  127.      * @param s The string wich is being checked
  128.      * @param compareString A variable list of compare strings
  129.      * @return true, if the string ends with at least one of the compare strings
  130.      */
  131.     mEndsWith: function (s) {
  132.     },
  133.  
  134.     /**
  135.      * Repeats a string "count" times.
  136.      *
  137.      * @usage var result = StringUtils.repeat("hello", 3); // "hellohellohello"
  138.      * @param s The string wich is repeated.
  139.      * @param count How often should the string be repeated. If value <= 0, the empty string is returned.
  140.      * @return The repeated string
  141.      */
  142.     repeat: function (x, count) {
  143.     },
  144.  
  145.     /**
  146.      * Returns a string where every occurrence of toReplace is being replaced by replaceBy.
  147.      *
  148.      * @usage console.log(StringUtils.replace("hello world", "o", "xx")); // outputs "hellxx wxxrld"
  149.      * @param s The string
  150.      * @param toReplace Substring to be replaced. If <code>toReplace</code> is the empty string, <code>replaceBy</code> is inserted after every character.
  151.      * @param replaceBy The replacement string
  152.      * @return the string with the replacements done
  153.      */
  154.     replace: function (s, toReplace, replaceBy) {
  155.     },
  156.  
  157.     /**
  158.      * Returns a string where all occurruences of the compare strings in the variable parameter list
  159.      * are replaced by the last string in the parameter list.
  160.      *
  161.      * @usage console.log(StringUtils.mReplace("hello world","o","l","xx")); // outputs "hexxxxxx wxxrxxd"
  162.      * @param x; the string
  163.      * @param variable parameter list of n strings
  164.      * @param strings 1 to (n-1): all strings to be replaced
  165.      * @param string n: replacement string
  166.      * @return
  167.      */
  168.     mReplace: function (x) {
  169.     },
  170.  
  171.     /**
  172.      * Inserts at the beginning of this the character character until the string has the length of len.
  173.      * If the original string is longer than len, no characters are inserted but the string is not truncated.
  174.      *
  175.      * @usage
  176.      *        console.log(StringUtils.lead("hello",8," ")); // outputs "   hello"
  177.      *        console.log(StringUtils.lead("hello",3," ")); // outputs "hello"
  178.      * @param s The string
  179.      * @param len Desired length of the string after inserting of leading characters character
  180.      * @param character Character to be inserted (must be a string with length of 1)
  181.      * @return the new string with the inserted characters
  182.      */
  183.     lead: function (s, len, character) {
  184.     },
  185.  
  186.     /**
  187.      * Appends at the beginning of this the character character until the string has the length of len.
  188.      * If the original string is longer than len, no characters are appended but the string is not truncated.
  189.      *
  190.      * @usage
  191.      *        console.log(StringUtils.trail("hello",8,".")); // outputs "hello..."
  192.      *        console.log(StringUtils.trail("hello",3,".")); // outputs "hello"
  193.      * @param s The string
  194.      * @param len Desired length of the string after appending of trailing characters character
  195.      * @param character Character to be appended (must be a string with length=1)
  196.      * @return the new string with the appended characters
  197.      */
  198.     trail: function (s, len, character) {
  199.     },
  200.  
  201.     /**
  202.      * Checks if the string contains only whitespace.
  203.      *
  204.      * @usage console.log(StringUtils.isWhite("  \t  ")); // outputs true
  205.      * @param s The string
  206.      * @return true if the string contains only whitespace.
  207.      */
  208.     isWhite: function (s) {
  209.     },
  210.  
  211.     /**
  212.      * Returns the number of occurences of compareString in this.
  213.      *
  214.      * @usage console.log(StringUtils.numberOf("hello world","l")); // outputs 3
  215.      * @param s The string
  216.      * @param compareString The string whose occurrence has to be counted
  217.      * @return the number of occurences of compareString in this.
  218.      */
  219.     numberOf: function (s, compareString, offset, count) {
  220.     },
  221.  
  222.     /**
  223.      * Replaces nCount occurrences of the string sFrom by the replacement string sTo.
  224.      *
  225.      * @usage
  226.      *        console.log(StringUtils.replaceNum("hello world","l","-",1); // outputs "he-lo world"
  227.      *        console.log(StringUtils.replaceNum("hello world","l","-",0); // outputs "hello world"
  228.      * @param x; the string
  229.      * @param sFrom; string to be replaced
  230.      * @param sTo; replacement string
  231.      * @param nCount; number of desired replacements; for 0 or null or undefined, nothing is replaced
  232.      * @return the string with the replacemenst applied
  233.      */
  234.     replaceNum: function (x, sFrom, sTo, nCount) {
  235.     },
  236.  
  237.     /**
  238.      * Removes one ore more occurrences of the string toRemove from the beginning and/or end of this.
  239.      *
  240.      * @usage
  241.      *        console.log(StringUtils.trim("aabbccddccccbba","a"));                // bbccddccccbb
  242.      *        console.log(StringUtils.trim("aabbccddccccbba","a",true,false));    // bbccddccccbba
  243.      *        console.log(StringUtils.trim("aabbccddccccbba","a",false,true));    // bbccddccccbb
  244.      *        console.log(StringUtils.trim("aabbccddccccbba","a",false,false));    // aabbccddccccbba
  245.      * @param s The string
  246.      * @param toRemove String to be removed
  247.      * @param trimLeading If true, occurrences of toRemove are removed from the beginning of the string
  248.      * @param trimTrailing Iftrue, occurrences of toRemove are removed from the end of the string
  249.      * @return the trimmed string
  250.      */
  251.     trim: function (s, toRemove, trimLeading, trimTrailing) {
  252.     },
  253.  
  254.     /**
  255.      * Like StringUtils.trim but more compare strings can be specified in an array.
  256.      *
  257.      * @usage
  258.      *        console.log(StringUtils.mTrim("aabbabccddccccbba",["a"])); // bbccddccccbb
  259.      *        console.log(StringUtils.mTrim("aabbabccddccccbba",["a","b"])); // ccddcccc
  260.      *        console.log(StringUtils.mTrim("aabbabccddccccbba",["a","c"],true,true)); // bbccddccccbb
  261.      * @param s The string
  262.      * @param stringsToRemove Array of compare strings which will all be removed from beginning/end of the string
  263.      * @param trimLeading If true, remove from the beginning of the string
  264.      * @param trimTrailing If true, remove from the end of the string
  265.      */
  266.     mTrim: function (s, stringsToRemove, trimLeading, trimTrailing) {
  267.     },
  268.  
  269.     /**
  270.      * Removes all of the following characters/string from the beginning/end of the string: " ","\t","\n","\r"
  271.      *
  272.      * @usage console.log(StringUtils.trimWhite("  hello \t ")); // outputs "hello"
  273.      * @param s The string
  274.      * @param trimLeading If true, remove from the beginning of the string
  275.      * @param trimTrailing If true, remove from the end of the string
  276.      * @return the trimmed string
  277.      */
  278.     trimWhite: function (s, trimLeading, trimTrailing) {
  279.     },
  280.  
  281.     /**
  282.      * Removes all of the following characters/string from the beginning/end of the string: " ","\t","\n","\r","<br>","&nbsp;"
  283.      *
  284.      * @usage console.log(StringUtils.trimHtmlWhite("  hello <br>&nbsp; ")); // outputs "hello"
  285.      * @param s; the string
  286.      * @param trimLeading; optional, default:true; if true, remove from the beginning of the string
  287.      * @param trimTrailing; optional, default:true; if true, remove from the end of the string
  288.      * @return the trimmed string
  289.      */
  290.     trimHtmlWhite: function (s, trimLeading, trimTrailing) {
  291.     },
  292.  
  293.     /**
  294.      * Converts the following special charactes into their Escape-Sequences.
  295.      *
  296.      *    <p>\\    will be converted to \\\\ </p>
  297.      *    <p>\'    will be converted to \\\'</p>
  298.      *    <p>\"    will be converted to \\\"</p>
  299.      *    <p>\n    will be converted to \\n</p>
  300.      *    <p>\r    will be converted to \\r</p>
  301.      *    <p>\t    will be converted to \\t</p>
  302.      *    <p>\b    will be converted to \\b</p>
  303.      *    <p>\f    will be converted to \\f</p>
  304.      *
  305.      * @usage StringUtils.escapeCharSequences(myString)
  306.      * @param s; the string
  307.      * @return the converted string
  308.      */
  309.     escapeCharSequences: function (s) {
  310.     },
  311.  
  312.     /**
  313.      * Make a string's first character uppercase
  314.      *
  315.      * @usage StringUtils.toUpperCaseFirst(myString)
  316.      * @param x; the string
  317.      * @return the converted string
  318.      */
  319.     toUpperCaseFirst: function (s) {
  320.     }
  321. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement