Module: gears.string

String module for gears.

Static module functions

gears.string.xml_escape (text) Escape a string from XML char.
gears.string.xml_unescape (text) Unescape a string from entities.
gears.string.linecount (text) Count number of lines in a string.
gears.string.linewrap (text, width, indent) Split a string into multiple lines.
gears.string.quote_pattern (s) Escape all special pattern-matching characters so that lua interprets them literally instead of as a character class.
gears.string.query_to_pattern (q) Generate a pattern matching expression that ignores case.
gears.string.split (str, delimiter) Split separates a string containing a delimiter into the list of substrings between that delimiter.
gears.string.startswith (str, sub) Check if a string starts with another string.
gears.string.endswith (str, sub) Check if a string ends with another string.


Static module functions

gears.string.xml_escape (text)
Escape a string from XML char. Useful to set raw text in textbox.

Parameters:

  • text Text to escape.

Returns:

    string Escaped text.
gears.string.xml_unescape (text)
Unescape a string from entities.

Parameters:

  • text Text to unescape.

Returns:

    string Unescaped text.
gears.string.linecount (text)

Count number of lines in a string.

Usage example output:

Count is: 1
Count is: 3

Parameters:

Returns:

    int Number of lines.

Usage:

    local test = 'do.t'
    local res = gears.string.linecount(test)
    print('Count is: ' .. res)
    local test2 = 'do\nit\nnow'
    local res2 = gears.string.linecount(test2)
    print('Count is: ' .. res2)
gears.string.linewrap (text, width, indent)

Split a string into multiple lines.

Usage example output:

do
it

Parameters:

  • text string String to wrap.
  • width number Maximum length of each line. Default: 72.
  • indent number Number of spaces added before each wrapped line. Default: 0.

Returns:

    string The string with lines wrapped to width.

Usage:

    local test = 'do it'
    local res = gears.string.linewrap(test, 2, 0)
    print(res)
gears.string.quote_pattern (s)

Escape all special pattern-matching characters so that lua interprets them literally instead of as a character class. Source: http://stackoverflow.com/a/20778724/15690

Usage example output:

do%.it

Parameters:

  • s string String to generate pattern for

Returns:

    string string with escaped characters

Usage:

    local test = 'do.it'
    local res = gears.string.quote_pattern(test)
    print(res)
gears.string.query_to_pattern (q)
Generate a pattern matching expression that ignores case.

Parameters:

  • q string Original pattern matching expression.
gears.string.split (str, delimiter)
Split separates a string containing a delimiter into the list of substrings between that delimiter.

Parameters:

  • str string String to be splitted
  • delimiter string Character where the string will be splitted

Returns:

    table list of the substrings
gears.string.startswith (str, sub)

Check if a string starts with another string.

Usage example output:

true
false

Parameters:

  • str string String to search
  • sub string String to check for.

Returns:

    boolean true if string starts with specified string

Usage:

    local test = 'do.it'
    local res = gears.string.startswith(test,'do')
    print(tostring(res)) -- Print boolean value
    res = gears.string.startswith(test,'it')
    print(tostring(res)) -- print boolean value
gears.string.endswith (str, sub)

Check if a string ends with another string.

Usage example output:

true
false

Parameters:

  • str string String to search
  • sub string String to check for.

Returns:

    boolean true if string ends with specified string

Usage:

    local test = 'do.it'
    local res = gears.string.endswith(test,'it')
    print(tostring(res))
    res = gears.string.endswith(test,'do')
    print(tostring(res))
generated by LDoc 1.4.6 Last updated 2030-01-01 00:00:00