Module lsh.stringx

String extensions.

Functions

split (inp[, sep[, max]]) Splits a string by a separator.
chomp (inp) Removes a final newline from a string.
quote (inp) Quotes a string for use as a single POSIX shell word.


Functions

split (inp[, sep[, max]])
Splits a string by a separator.

Parameters:

  • inp string input string
  • sep string separator (default is whitespace) (optional)
  • max int maximum number of splits (default is unlimited) (optional)

Returns:

    {string,...} the pieces between separators

Usage:

    local sh = require 'lsh'
    
    local parts = sh.stringx.split('a,b,c', ',', 1)
    assert(parts[1] == 'a' and parts[2] == 'b,c')
chomp (inp)
Removes a final newline from a string.

Parameters:

Returns:

    string string without the final newline
quote (inp)
Quotes a string for use as a single POSIX shell word.

A string made only of characters that are safe in a shell word is returned unchanged.

Parameters:

Returns:

    string quoted string

Usage:

    local sh = require 'lsh'
    
    assert(sh.stringx.quote('dir name') == "'dir name'")
    assert(sh.stringx.quote("it's") == "'it'\\''s'")
generated by LDoc 1.5.0 Last updated 2026-10-02 09:04:27 UTC (f69ca05)