File string.extra.lua

String manipulation functions.

Release: $Id: string.extra.lua,v 1.2 2008/01/03 18:09:15 raphael Exp $

Functions

notempty (s) Removes leading, trailing and redundant spaces from a string and returns the result if it's not empty.
rmsp (s) Removes spaces from the beginning and from the end of a string.
split (s, f, sep) Applies a function to the substrings of a given string.
toarray (s, sep, dest) Splits a string into a table producing an array.
torecord (s, sep, dest) Splits a string into a table producing a record.


Functions

notempty (s)
Removes leading, trailing and redundant spaces from a string and returns the result if it's not empty. nil is returned otherwise.

Parameters

  • s: String to be processed.

Return value:

String or nil, if it results in an empty string.

See also:

rmsp (s)
Removes spaces from the beginning and from the end of a string. Also removes space multiplicity (by substituting it by a single space).

Parameters

  • s: String to be processed.

Return value:

String or nil if no string was given.
split (s, f, sep)
Applies a function to the substrings of a given string. It also takes care of separator inside quoted strings.

Parameters

  • s: String to be processed.
  • f: Function to process each substring.
  • sep: String with the separator character (default = ';').
toarray (s, sep, dest)
Splits a string into a table producing an array.

Parameters

  • s: String to be processed.
  • sep: String with the separator character (optional).
  • dest: Table to receive the result (optional).

Return value:

Table representing a record.
torecord (s, sep, dest)
Splits a string into a table producing a record. The fields of the record are the strings; the values are its initial position in the original string.

Parameters

  • s: String to be processed.
  • sep: String with the separator character (optional).
  • dest: Table to receive the result (optional).

Return value:

Table representing a record.

Valid XHTML 1.0!