Str
This Library provides advanced methods on Strings. If the first argument to any of the methods is nil, the result is
unspecified.
Static methods:
Lib.Str.urlEncode(s) |
Encode an URL by using the standard format. |
s - String |
Lib.Str.urlDecode(s) |
Decode an URL using the standard format. |
s - String |
Lib.Str.htmlEscape(s, quotes) |
Escapes HTML special characters of the string `s`. The following replacements are made: - `&` becomes `&`; - `<` becomes `<`; - `>` becomes `>`; If `quotes` is true, the following characters are also replaced: - `"` becomes `"`; - `'` becomes `'`; |
s - String quotes - true/false |
Lib.Str.htmlUnescape(s) |
Unescapes HTML special characters of the string `s`. This is the inverse operation to htmlEscape, i.e. the following always holds: `Lib.Str.htmlUnescape(Lib.Str.htmlEscape(s)) == s` The replacements follow: - `&` becomes `&` - `<` becomes `<` - `>` becomes `>` - `"` becomes `"` - `'` becomes `'` |
s - String |
Lib.Str.startsWith(s, start) |
Tells if the string `s` starts with the string `start`. If `start` is `nil`, the result is unspecified. If `start` is the empty String `""`, the result is true. |
s - String start - int, start position |
Lib.Str.endsWith(s, end) |
Tells if the string `s` ends with the string `end`. If `end` is `nil`, the result is unspecified. If `end` is the empty String `""`, the result is true. |
s - String end - int, end position |
Lib.Str.isSpace(s, pos) |
Tells if the character in the string `s` at position `pos` is a space. A character is considered to be a space character if its character code is 9,10,11,12,13 or 32. If `s` is the empty String `""`, or if pos is not a valid position within `s`, the result is false. |
s - String pos - int, position |
Lib.Str.ltrim(s) |
Removes leading space characters of `s`. This function internally calls `Lib.Str.isSpace()` to decide which characters to remove. If `s` is the empty String `""` or consists only of space characters, the result is the empty String `""`. |
s - String |
Lib.Str.rtrim(s) |
Removes trailing space characters of `s`. This function internally calls `Lib.Str.isSpace()` to decide which characters to remove. If `s` is the empty String `""` or consists only of space characters, the result is the empty String `""`. |
s - String |
Lib.Str.trim(s) |
Removes leading and trailing space characters of `s`. This is a convenience function for `Lib.Str.ltrim(Lib.Str.rtrim(s))`. |
s - String |
Lib.Str.lpad(s, c, l) |
Concatenates `c` to `s` until `s` length is at least `l`. If `c` is the empty String `""` or if `l` does not exceed `s` length, `s` is returned unchanged. If `c` length is 1, the resulting String length is exactly `l`. Otherwise the length may exceed `l`. If `c` is nil, the result is unspecified. |
s - String c - String l - int, length limit |
Lib.Str.rpad(s, c, l) |
Appends `c` to `s` until `s` length is at least `l`. If `c` is the empty String `""` or if `l` does not exceed `s` length, `s` is returned unchanged. If `c` length is 1, the resulting String length is exactly `l`. Otherwise the length may exceed `l`. If `c` is nil, the result is unspecified. |
s - String c - String l - int, length limit |
Lib.Str.replace(s, sub, by) |
Replace all occurrences of the String `sub` in the String `s` by the String `by`. If `sub` is the empty String `""`, `by` is inserted after each character of `s`. If `by` is also the empty String `""`, `s` remains unchanged. This is a convenience function for `Lib.Str.join(Lib.Str.split(s, sub), by)`. If `sub` or `by` are nil, the result is unspecified. |
s - String sub - String, for replacement by - String, replaced to |
Lib.Str.hex(n, digits) |
Encodes `n` into a hexadecimal representation. The resulting String is padded with "0" until its `length` equals `digits` |
n - int, number for encode digits - int, 0 padded limit |
Lib.Str.quoteUnixArg(argument) |
Returns a String that can be used as a single command line argument on Unix. The input will be quoted, or escaped if necessary. |
argument - String |
Lib.Str.quoteWinArg(argument, escapeMetaCharacters) |
Returns a String that can be used as a single command line argument on Windows. The input will be quoted, or escaped if necessary, such that the output will be parsed as a single argument using the rule specified in http://msdn.microsoft.com/en-us/library/ms880421 Examples: ``` Lib.Str.quoteWinArg("abc") == "abc" Lib.Str.quoteWinArg("ab c") == '"ab c"' ``` |
|
Lib.Str.join(st, sep) |
Returns a string representation of `st` table of String values, with `sep` separating each element. If `st' not a table of Strings, the result is unspecified. The result of this operation is equal to `Lib.Str.string(st[1]) + sep + Lib.Str.string(st[2]) + sep + ... + sep + Lib.Str.string(st[#st])` If `st` is the empty table `{}`, the result is the empty String `""`. If `st` has exactly one element, the result is equal to a call to `Lib.Str.string(st[1])`. If `sep` is nil, the result is unspecified. |
st - table of Strings sep - String separator |
Lib.Str.string(s) |
Converts any value to a String. If `s` is of `String`, `Int`, `Float` or `Bool`, its value is returned. If `s` is an instance of a Lib object and that class or one of its parent objects has a `toString` method, that method is called. If no such method is present, the result is unspecified. If `s` is an enum constructor without argument, the constructor's name is returned. If arguments exists, the constructor's name followed by the String representations of the arguments is returned. If `s` is a structure, the field names along with their values are returned. The field order and the operator separating field names and values are unspecified. If s is nil, "nil" is returned. |
s - any value with type Lib compatible. |
Lib.Str.parseInt(x) |
Converts a `String` to an `Int`. Leading whitespaces are ignored. If `x` starts with 0x or 0X, hexadecimal notation is recognized where the following digits may contain 0-9 and A-F. Otherwise `x` is read as decimal number with 0-9 being allowed characters. `x` may also start with a - to denote a negative value. In decimal mode, parsing continues until an invalid character is detected, in which case the result up to that point is returned. For hexadecimal notation, the effect of invalid characters is unspecified. Leading 0s that are not part of the 0x/0X hexadecimal notation are ignored, which means octal notation is not supported. If the input cannot be recognized, the result is `nil`. |
x - String |
Lib.Str.parseFloat(x) |
Converts a `String` to a `Float`. The parsing rules for `parseInt` apply here as well Additionally, decimal notation may contain a single `.` to denote the start of the fractions. |
x - String |
Lib.Str.split(s, delimiter) |
Splits `s` String at each occurrence of `delimiter`. If `s` String is the empty String `""`, the result is `{}`. If `delimiter` is the empty String `""`, `s` String is split into an table of `s` length elements, where the elements correspond to the characters of `s` String. If `delimiter` is not found within `s` String, the result is an table with one element, which equals `s` String. If `delimiter` is nil, the result is unspecified. Otherwise, `s` String is split into parts at each occurrence of `delimiter`. If `s` String starts (or ends) with `delimiter`, the result table contains a leading (or trailing) empty String `""` element. Two subsequent delimiters also result in an empty String `""` element. |
s - String delimiter - Delimiter String |
Lib.Str.length(s) |
The number of characters in `s` String. |
s - String |
Lib.Str.toUpperCase(s) |
Returns a String where all characters of `s` String are upper case. Affects the characters `a-z`. Other characters remain unchanged. |
s - String |
Lib.Str.toLowerCase(s) |
Returns a String where all characters of `s` String are lower case. Affects the characters `A-Z`. Other characters remain unchanged. |
s - String |
Lib.Str.charAt(s, index) |
Returns the character at position `index` of `s` String. If `index` is negative or exceeds `s` length, the empty String `""` is returned. |
s - String index - int, position |
Lib.Str.charCodeAt(s, index) |
Returns the character code at position `index` of `s` String. If `index` is negative or exceeds `s` length, `nil` is returned. Note that this only works on String literals of length 1. |
s - String index - int, position |
Lib.Str.indexOf(s, str, startIndex) |
Returns the position of the leftmost occurrence of `str` within `s` String. The search is performed within the substring of `s` String starting from `startIndex`. If `str` cannot be found, -1 is returned. |
s - String str - String, for search startIndex - int, starting position (0) |
Lib.Str.lastIndexOf(s, str, startIndex) |
Returns the position of the rightmost occurrence of `str` within `s` String. The search is performed within the substring of `s` String from 0 to `startIndex`. If `str` cannot be found, -1 is returned. |
s - String str - String, for search startIndex - int, starting position (0) |
Lib.Str.substr(s, pos, len) |
Returns `len` characters of `s` String, starting at position `pos`. If `pos` is negative, its value is calculated from the end of `s` String by `s` length + `pos`. If this yields a negative value, 0 is used instead. If the calculated position + `len` exceeds `s` length, the characters from that position to the end of `s` String are returned. If `len` is negative, the result is unspecified. |
s - String pos - int, position len - int, length |
Lib.Str.substring(s, startIndex, endIndex) |
Returns the part of `s` String from `startIndex` to but not including `endIndex`. If `startIndex` or `endIndex` are negative, 0 is used instead. If `startIndex` exceeds `endIndex`, they are swapped. If the (possibly swapped) `endIndex` is omitted or exceeds `s` length, `s` length is used instead. If the (possibly swapped) `startIndex` exceeds `s` length, the empty String `""` is returned. |
s - String startIndex - int, starting position (0) endIndex - int, ending position (0) |
Lib.Str.fromCharCode(code) |
Returns the String corresponding to the character code `code`. If `code` is negative or has another invalid value, the result is unspecified. |
code - int, char code |
Lib.Str.parseUrl(url) |
Returns parsed from url String object with fields: url : String source : String protocol : String authority : String userInfo : String user : String password : String host : String port : String relative : String path : String directory : String file : String query : String anchor : String |
url - URL String |
Static values:
Lib.Str.winMetaCharacters |
Character codes of the characters that will be escaped by `Lib.String.Tools.quoteWinArg(...., true) |
Created with the Personal Edition of HelpNDoc: Full-featured Documentation generator