239. String

String manipulation routines

239.1. Summary of Module Globals

List of Global Functions

  • CAlnum -

  • CAlpha -

  • CDigit -

  • CGraph -

  • CLower -

  • CPrint -

  • CPunct -

  • CSpace -

  • CUpper -

  • CXdigit -

  • CutBlanks - Remove blanks at begin and end of input string.

  • CutRegexMatch - Remove first or every match of given regular expression from a string

  • CutZeros - Remove any leading zeros

  • EscapeTags - Function for escaping (replacing) (HTML|XML...) tags with their (HTML|XML...) meaning.

  • FirstChunk - Shorthand for select (splitstring (s, separators), 0, "") Useful now that the above produces a deprecation warning.

  • FormatFilename - Format file name - truncate the middle part of the directory to fit to the reqested lenght. Path elements in the middle of the string are replaced by ellipsis (...). The result migth be longer that requested size if size of the last element (with ellipsis) is longer than the requested size. If the requested size is greater than size of the input then the string is not modified. The last part (file name) is never removed.

  • FormatSize - Return a pretty description of a byte count

  • FormatSizeWithPrecision - Return a pretty description of a byte count

  • GetCommentLines - Get comment without metadata

  • GetMetaDataLines - Get metadata lines from input string

  • NewlineItems -

  • NonEmpty -

  • OptFormat - Optional formatted text

  • OptParens - Optional parenthesized text

  • Pad - Add spaces after the text to make it long enough

  • PadZeros - Add zeros before the text to make it long enough.

  • ParseOptions - Parse string of values

  • ParseSysconfigComment - Parse metadata from a sysconfig comment

  • Quote - Quote a string with 's

  • Random - Make a random base-36 number. srandom should be called beforehand.

  • Replace - Replace substring in a string. All substrings source are replaced by string target.

  • TextTable - Function creates text table without using HTML tags. (Useful for commandline) Undefined option uses the default one.

  • UnQuote - Unquote a string with 's (quoted with quote)

  • UnderlinedHeader - Function returns underlined text header without using HTML tags. (Useful for commandline)

  • ValidCharsFilename - Characters valid in a filename (not pathname). Naturally "/" is disallowed. Otherwise, the graphical ASCII characters are allowed.

  • WrapAt - Returns text wrapped at defined margin. Very useful for translated strings used for pop-up windows or dialogs where you can't know the width. It controls the maximum width of the string so the text should allways fit into the minimal ncurses window. If you expect some long words, such us URLs or words with a hyphen inside, you can also set the additional split-characters to "/-". Then the function can wrap the word also after these characters. This function description was wrapped using the function String::WrapAt().

List of Global Variables

    239.2. Global Functions

    239.2.1. CAlnum

    Return value

    • string - the 52 upper and lowercase ASCII letters and digits

    239.2.2. CAlpha

    Return value

    • string - the 52 upper and lowercase ASCII letters

    239.2.3. CDigit

    Return value

    • string - 0123456789

    239.2.4. CGraph

    Return value

    • string - printable ASCII charcters except whitespace

    239.2.5. CLower

    Return value

    • string - the 26 lowercase ASCII letters

    239.2.6. CPrint

    Return value

    • string - printable ASCII characters including whitespace

    239.2.7. CPunct

    Return value

    • string - the ASCII printable non-blank non-alphanumeric characters

    239.2.8. CSpace

    Return value

    • string - ASCII whitespace

    239.2.9. CUpper

    Return value

    • string - the 26 uppercase ASCII letters

    239.2.10. CXdigit

    Return value

    • string - hexadecimal digits: 0123456789ABCDEFabcdef

    239.2.11. CutBlanks

    Remove blanks at begin and end of input string.

    Function parameters

    • string input

    Return value

    • string - stripped string

    Example 66. 

     CutBlanks("  any  input     ") -> "any  input"

    239.2.12. CutRegexMatch

    Remove first or every match of given regular expression from a string

    Function parameters

    • string input

    • string regex

    • boolean glob

    Return value

    • string - that has matches removed

    239.2.13. CutZeros

    Remove any leading zeros

    Function parameters

    • string input

    Return value

    • string - that has leading zeros removed

    239.2.14. EscapeTags

    Function for escaping (replacing) (HTML|XML...) tags with their (HTML|XML...) meaning.

    Function parameters

    • string text

    Return value

    • string - escaped text

    239.2.15. FirstChunk

    Shorthand for select (splitstring (s, separators), 0, "") Useful now that the above produces a deprecation warning.

    Function parameters

    • string s

    • string separators

    Return value

    • string - first component or ""

    239.2.16. FormatFilename

    Format file name - truncate the middle part of the directory to fit to the reqested lenght. Path elements in the middle of the string are replaced by ellipsis (...). The result migth be longer that requested size if size of the last element (with ellipsis) is longer than the requested size. If the requested size is greater than size of the input then the string is not modified. The last part (file name) is never removed.

    Function parameters

    • string file_path

    • integer len

    Return value

    • string - Truncated file name

    Example 67. 

     FormatFilename("/really/very/long/file/name", 15) -> "/.../file/name"
     FormatFilename("/really/very/long/file/name", 5) -> ".../name"
     FormatFilename("/really/very/long/file/name", 100) -> "/really/very/long/file/name"
    

    239.2.17. FormatSize

    Return a pretty description of a byte count

    Function parameters

    • integer bytes

    Return value

    • string - formatted string

    Example 68. 

     FormatSize(23456767890) -> "223.70 MB"

    239.2.18. FormatSizeWithPrecision

    Return a pretty description of a byte count

    Function parameters

    • integer bytes

    • integer precision

    • boolean omit_zeroes

    Return value

    • string - formatted string

    Example 69. 

     FormatSizeWithPrecision(4096, 2, true) -> "4 KB"
     FormatSizeWithPrecision(4096, 2, false) -> "4.00 KB"

    239.2.19. GetCommentLines

    Get comment without metadata

    Function parameters

    • string input

    Return value

    • string - Comment used as variable description

    239.2.20. GetMetaDataLines

    Get metadata lines from input string

    Function parameters

    • string input

    Return value

    • list<string> - Metadata lines in list

    239.2.21. NewlineItems

    Function parameters

    • string s

    Return value

    • list<string> - the items as a list, with empty lines removed

    239.2.22. NonEmpty

    Function parameters

    • list<string> l

    Return value

    • list<string> - only non-"" items

    239.2.23. OptFormat

    Optional formatted text

    Function parameters

    • string f

    • string s

    Return value

    • string - sformat (f, s) if s is neither empty or nil, else ""

    239.2.24. OptParens

    Optional parenthesized text

    Function parameters

    • string s

    Return value

    • string - " (Foo)" if Foo is neither empty or nil, else ""

    239.2.25. Pad

    Add spaces after the text to make it long enough

    Function parameters

    • string text

    • integer length

    Return value

    • string - padded text

    239.2.26. PadZeros

    Add zeros before the text to make it long enough.

    Function parameters

    • string text

    • integer length

    Return value

    • string - padded text

    239.2.27. ParseOptions

    Parse string of values

    Function parameters

    • string options

    • map parameters

    Return value

    • list<string> - List of strings

    239.2.28. ParseSysconfigComment

    Parse metadata from a sysconfig comment

    Function parameters

    • string comment

    Return value

    • map<string, string> - parsed metadata

    239.2.29. Quote

    Quote a string with 's

    Function parameters

    • string var

    Return value

    • string - quoted string

    Example 70. 

     quote("a'b") -> "a'\''b"

    239.2.30. Random

    Make a random base-36 number. srandom should be called beforehand.

    Function parameters

    • integer len

    Return value

    • string - random string of 0-9 and a-z

    239.2.31. Replace

    Replace substring in a string. All substrings source are replaced by string target.

    Function parameters

    • string s

    • string source

    • string target

    Return value

    • string - result

    239.2.32. TextTable

    Function creates text table without using HTML tags. (Useful for commandline) Undefined option uses the default one.

    Function parameters

    • list<string> header

    • list <list <string> > items

    • map <string, any> options

    Return value

    • string - table Header: [ "Id", "Configuration", "Device" ] Items: [ [ "1", "aaa", "Samsung Calex" ], [ "2", "bbb", "Trivial Trinitron" ] ] Possible Options: horizontal_padding (for columns), table_left_padding (for table)

    239.2.33. UnQuote

    Unquote a string with 's (quoted with quote)

    Function parameters

    • string var

    Return value

    • string - unquoted string

    239.2.34. UnderlinedHeader

    Function returns underlined text header without using HTML tags. (Useful for commandline)

    Function parameters

    • string header_line

    • integer left_padding

    Return value

    • string - underlined header line

    239.2.35. ValidCharsFilename

    Characters valid in a filename (not pathname). Naturally "/" is disallowed. Otherwise, the graphical ASCII characters are allowed.

    Return value

    • string - for ValidChars

    239.2.36. WrapAt

    Returns text wrapped at defined margin. Very useful for translated strings used for pop-up windows or dialogs where you can't know the width. It controls the maximum width of the string so the text should allways fit into the minimal ncurses window. If you expect some long words, such us URLs or words with a hyphen inside, you can also set the additional split-characters to "/-". Then the function can wrap the word also after these characters. This function description was wrapped using the function String::WrapAt().

    Function parameters

    • string text

    • integer width

    • string split_string

    Return value

    • string - wrapped string

    Example 71. 

     String::WrapAt("Some very long text",30,"/-");
    

    239.3. Global Variables

    239.4. Module Requirements

    none