Module pl.stringx

Python-style extended string library.

see 3.6.1 of the Python reference. If you want to make these available as string methods, then say `stringx.import()` to bring them into the standard `string` table.

See the Guide

Dependencies: `pl.utils`

Functions

isalpha (s) does s only contain alphabetic characters?.
isdigit (s) does s only contain digits?.
isalnum (s) does s only contain alphanumeric characters?.
isspace (s) does s only contain spaces?.
islower (s) does s only contain lower case characters?.
isupper (s) does s only contain upper case characters?.
join (self, seq) concatenate the strings using this string as a delimiter.
startswith (self, s2) does string start with the substring?.
endswith (s, send) does string end with the given substring?.
expandtabs (self, n) replace all tabs in s with n spaces.
lfind (self, sub, i1) find index of first instance of sub in s from the left.
rfind (self, sub, first, last) find index of first instance of sub in s from the right.
replace (s, old, new, n) replace up to n instances of old by new in the string s.
split (self, re, n) split a string into a list of strings using a delimiter.
splitv (self, re) split a string using a pattern.
count (self, sub) count all instances of substring in string.
ljust (self, w, ch) left-justify s with width w.
rjust (s, w, ch) right-justify s with width w.
center (s, w, ch) center-justify s with width w.
lstrip (self, chrs) trim any whitespace on the left of s.
rstrip (s, chrs) trim any whitespace on the right of s.
strip (self, chrs) trim any whitespace on both left and right of s.
partition (self, ch) partition the string using first occurance of a delimiter
rpartition (self, ch) partition the string p using last occurance of a delimiter
at (self, idx) return the 'character' at the index.
lines (self) return an interator over all lines in a string
title (self) iniital word letters uppercase ('title case').
shorten (self, sz, tail) return a shorted version of a string.


Functions

isalpha (s)
does s only contain alphabetic characters?.

Parameters:

  • s a string
isdigit (s)
does s only contain digits?.

Parameters:

  • s a string
isalnum (s)
does s only contain alphanumeric characters?.

Parameters:

  • s a string
isspace (s)
does s only contain spaces?.

Parameters:

  • s a string
islower (s)
does s only contain lower case characters?.

Parameters:

  • s a string
isupper (s)
does s only contain upper case characters?.

Parameters:

  • s a string
join (self, seq)
concatenate the strings using this string as a delimiter.

Parameters:

  • self the string
  • seq a table of strings or numbers

Usage:

    (' '):join {1,2,3} == '1 2 3'
startswith (self, s2)
does string start with the substring?.

Parameters:

  • self the string
  • s2 a string
endswith (s, send)
does string end with the given substring?.

Parameters:

  • s a string
  • send a substring or a table of suffixes
expandtabs (self, n)
replace all tabs in s with n spaces. If not specified, n defaults to 8. with 0.9.5 this now correctly expands to the next tab stop (if you really want to just replace tabs, use :gsub('\t',' ') etc)

Parameters:

  • self the string
  • n number of spaces to expand each tab, (default 8)
lfind (self, sub, i1)
find index of first instance of sub in s from the left.

Parameters:

  • self the string
  • sub substring
  • i1 start index
rfind (self, sub, first, last)
find index of first instance of sub in s from the right.

Parameters:

  • self the string
  • sub substring
  • first first index
  • last last index
replace (s, old, new, n)
replace up to n instances of old by new in the string s. if n is not present, replace all instances.

Parameters:

  • s the string
  • old the target substring
  • new the substitution
  • n optional maximum number of substitutions

Returns:

  1. result string
  2. the number of substitutions
split (self, re, n)
split a string into a list of strings using a delimiter.

Parameters:

  • self the string
  • re a delimiter (defaults to whitespace)
  • n maximum number of results

Usage:

  • #(('one two'):split()) == 2
  • ('one,two,three'):split(',') == List{'one','two','three'}
  • ('one,two,three'):split(',',2) == List{'one','two,three'}
splitv (self, re)
split a string using a pattern. Note that at least one value will be returned!

Parameters:

  • self the string
  • re a Lua string pattern (defaults to whitespace)

Returns:

    the parts of the string

Usage:

    a,b = line:splitv('=')
count (self, sub)
count all instances of substring in string.

Parameters:

  • self the string
  • sub substring
ljust (self, w, ch)
left-justify s with width w.

Parameters:

  • self the string
  • w width of justification
  • ch padding character, default ' '
rjust (s, w, ch)
right-justify s with width w.

Parameters:

  • s the string
  • w width of justification
  • ch padding character, default ' '
center (s, w, ch)
center-justify s with width w.

Parameters:

  • s the string
  • w width of justification
  • ch padding character, default ' '
lstrip (self, chrs)
trim any whitespace on the left of s.

Parameters:

  • self the string
  • chrs default any whitespace character (%s), can be a string of characters to be trimmed
rstrip (s, chrs)
trim any whitespace on the right of s.

Parameters:

  • s the string
  • chrs default any whitespace character (%s), can be a string of characters to be trimmed
strip (self, chrs)
trim any whitespace on both left and right of s.

Parameters:

  • self the string
  • chrs default any whitespace character (%s), can be a string of characters to be trimmed
partition (self, ch)
partition the string using first occurance of a delimiter

Parameters:

  • self the string
  • ch delimiter

Returns:

  1. part before ch
  2. ch
  3. part after ch
rpartition (self, ch)
partition the string p using last occurance of a delimiter

Parameters:

  • self the string
  • ch delimiter

Returns:

  1. part before ch
  2. ch
  3. part after ch
at (self, idx)
return the 'character' at the index.

Parameters:

  • self the string
  • idx an index (can be negative)

Returns:

    a substring of length 1 if successful, empty string otherwise.
lines (self)
return an interator over all lines in a string

Parameters:

  • self the string

Returns:

    an iterator
title (self)
iniital word letters uppercase ('title case'). Here 'words' mean chunks of non-space characters.

Parameters:

  • self the string

Returns:

    a string with each word's first letter uppercase
shorten (self, sz, tail)
return a shorted version of a string.

Parameters:

  • self the string
  • sz the maxinum size allowed
  • tail true if we want to show the end of the string (head otherwise)
generated by LDoc 1.3.12