Module std.string

Additions to the string module.

Functions

assert (v, f, ...) Extend to allow formatted arguments.
caps (s) Capitalise each word in a string.
chomp (s) Remove any final newline from a string.
escape_pattern (s) Escape a string to be used as a pattern.
escape_shell (s) Escape a string to be used as a shell token.
finds (s, p, init, plain) Do multiple finds on a string.
format (f, arg1, ...) Extend to work better with one argument.
ltrim (s, r) Remove leading matter from a string.
numbertosi (n) Write a number using SI suffixes.
ordinal_suffix (n) Return the English suffix for an ordinal.
pad (s, w, p) Justify a string.
pickle (x) Convert a value to a string.
prettytostring (t, indent, spacing) Pretty-print a table.
render (x, open, close, elem, pair, sep, roots) Turn tables into strings with recursion detection.
render_CloseRenderer (t)
render_ElementRenderer (e)
render_OpenRenderer (t)
render_PairRenderer (t, i, v, is, vs) NB.
render_SeparatorRenderer (t, i, v, j, w)
require_version (module, min, too_big, pattern) Require a module with a particular version.
rtrim (s, r) Remove trailing matter from a string.
split (s, sep) Split a string at a given separator.
tfind (s, p, init, plain) Do find, returning captures as a list.
tostring (x) Extend tostring to work better on tables.
trim (s, r) Remove leading and trailing matter from a string.
wrap (s, w, ind, ind1) Wrap a string into a paragraph.

Fields

s Give strings a subscription operator.
s Give strings an append metamethod.
s Give strings a concat metamethod.


Functions

assert (v, f, ...)
Extend to allow formatted arguments.

Parameters:

  • v value to assert
  • f format
  • ... arguments to format

Returns:

    value
caps (s)
Capitalise each word in a string.

Parameters:

  • s string

Returns:

    capitalised string
chomp (s)
Remove any final newline from a string.

Parameters:

  • s string to process

Returns:

    processed string
escape_pattern (s)
Escape a string to be used as a pattern.

Parameters:

  • s string to process

Returns:

    processed string
escape_shell (s)
Escape a string to be used as a shell token. Quotes spaces, parentheses, brackets, quotes, apostrophes and whitespace.

Parameters:

  • s string to process

Returns:

    processed string
finds (s, p, init, plain)
Do multiple finds on a string.

Parameters:

  • s target string
  • p pattern
  • init start position (default: 1)
  • plain inhibit magic characters (default: nil)

Returns:

    list of {from, to; capt = {captures}}
format (f, arg1, ...)
Extend to work better with one argument. If only one argument is passed, no formatting is attempted.

Parameters:

  • f format
  • arg1 first argument to format
  • ... arguments to format

Returns:

    formatted string
ltrim (s, r)
Remove leading matter from a string.

Parameters:

  • s string
  • r leading pattern (default: "%s+")

Returns:

    string without leading r
numbertosi (n)
Write a number using SI suffixes. The number is always written to 3 s.f.

Parameters:

  • n number

Returns:

    string
ordinal_suffix (n)
Return the English suffix for an ordinal.

Parameters:

  • n number of the day

Returns:

    suffix
pad (s, w, p)
Justify a string. When the string is longer than w, it is truncated (left or right according to the sign of w).

Parameters:

  • s string to justify
  • w width to justify to (-ve means right-justify; +ve means left-justify)
  • p string to pad with (default: " ")

Returns:

    justified string
pickle (x)
Convert a value to a string. The string can be passed to dostring to retrieve the value.

Parameters:

  • x object to pickle

Returns:

    string such that eval (s) is the same value as x
prettytostring (t, indent, spacing)
Pretty-print a table.

Parameters:

  • t table to print
  • indent indent between levels ["\t"]
  • spacing space before every line

Returns:

    pretty-printed string
render (x, open, close, elem, pair, sep, roots)
Turn tables into strings with recursion detection. N.B. Functions calling render should not recurse, or recursion detection will not work.

Parameters:

  • x object to convert to string
  • open open table renderer
  • close close table renderer
  • elem element renderer
  • pair pair renderer
  • sep separator renderer
  • roots accumulates table references to detect recursion

Returns:

  1. string representation
  2. open table string

See also:

render_CloseRenderer (t)

Parameters:

  • t table

Returns:

  1. close table string
  2. element string
render_ElementRenderer (e)

Parameters:

  • e element

Returns:

    element string
render_OpenRenderer (t)

Parameters:

  • t table

Returns:

  1. open table string
  2. close table string
render_PairRenderer (t, i, v, is, vs)
NB. the function should not try to render i and v, or treat them recursively.

Parameters:

  • t table
  • i index
  • v value
  • is index string
  • vs value string

Returns:

  1. element string
  2. separator string
render_SeparatorRenderer (t, i, v, j, w)

Parameters:

  • t table
  • i preceding index (nil on first call)
  • v preceding value (nil on first call)
  • j following index (nil on last call)
  • w following value (nil on last call)

Returns:

    separator string
require_version (module, min, too_big, pattern)
Require a module with a particular version.

Parameters:

  • module module to require
  • min lowest acceptable version (default: any)
  • too_big lowest version that is too big (default: none)
  • pattern to match version in module.version or module.VERSION (default: ".*[%.%d]+")
rtrim (s, r)
Remove trailing matter from a string.

Parameters:

  • s string
  • r trailing pattern (default: "%s+")

Returns:

    string without trailing r
split (s, sep)
Split a string at a given separator.

Parameters:

  • s string to split
  • sep separator pattern

Returns:

    list of strings
tfind (s, p, init, plain)
Do find, returning captures as a list.

Parameters:

  • s target string
  • p pattern
  • init start position (default: 1)
  • plain inhibit magic characters (default: nil)

Returns:

    start of match, end of match, table of captures
tostring (x)
Extend tostring to work better on tables.

Parameters:

  • x object to convert to string

Returns:

    string representation
trim (s, r)
Remove leading and trailing matter from a string.

Parameters:

  • s string
  • r leading/trailing pattern (default: "%s+")

Returns:

    string without leading/trailing r
wrap (s, w, ind, ind1)
Wrap a string into a paragraph.

Parameters:

  • s string to wrap
  • w width to wrap to (default: 78)
  • ind indent (default: 0)
  • ind1 indent of first line (default: ind)

Returns:

    wrapped paragraph

Fields

s
Give strings a subscription operator.
  • s string
  • i index
s
Give strings an append metamethod.
  • s string
  • c character (1-character string)
s
Give strings a concat metamethod.
  • s string
  • o object
generated by LDoc 1.4.0