Module string
Additions to the string module TODO: Pretty printing (use in getopt); see source for details.
Functions
caps (s) | Capitalise each word in a string. |
chomp (s) | Remove any final newline from a string. |
escapePattern (s) | Escape a string to be used as a pattern |
finds (s, p, init, plain) | Do multiple find s on a string. |
gsubs (s, sub, n) | Perform multiple calls to gsub. |
ltrim (s, r) | Remove leading matter from a string. |
numbertosi (n) | Write a number using SI suffixes. |
ordinalSuffix (n) | Return the English suffix for an ordinal. |
pad (s, w, p) | Justify a string. |
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. |
trim (s, r) | Remove leading and trailing matter from a string. |
wrap (s, w, ind, ind1) | Wrap a string into a paragraph. |
Functions
- caps (s)
-
Capitalise each word in a string.
Parameters
- s: string
Return value:
capitalised string - chomp (s)
-
Remove any final newline from a string.
Parameters
- s: string to process
Return value:
processed string - escapePattern (s)
-
Escape a string to be used as a pattern
Parameters
- s: string to process @return
- finds (s, p, init, plain)
-
Do multiple
find
s on a string.Parameters
- s: target string
- p: pattern
- init: start position (default: 1)
- plain: inhibit magic characters (default: nil)
Return value:
list of{from, to; capt = {captures}}
- gsubs (s, sub, n)
-
Perform multiple calls to gsub.
Parameters
- s: string to call gsub on
-
sub:
{pattern1=replacement1 ...}
- n: upper limit on replacements (default: infinite)
Return values:
- result string
- number of replacements made
- ltrim (s, r)
-
Remove leading matter from a string.
Parameters
- s: string
-
r: leading regex (default:
"%s+"
)
Return value:
string without leading r - numbertosi (n)
-
Write a number using SI suffixes. The number is always written to 3 s.f.
Parameters
- n: number
Return value:
string - ordinalSuffix (n)
-
Return the English suffix for an ordinal.
Parameters
- n: number of the day
Return value:
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:
" "
)
Return value:
justified string - rtrim (s, r)
-
Remove trailing matter from a string.
Parameters
- s: string
-
r: trailing regex (default:
"%s+"
)
Return value:
string without trailing r - split (s, sep)
-
Split a string at a given separator. FIXME: Consider Perl and Python versions.
Parameters
- s: string to split
- sep: separator regex
Return value:
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)
Return value:
start of match, end of match, table of captures - trim (s, r)
-
Remove leading and trailing matter from a string.
Parameters
- s: string
-
r: leading/trailing regex (default:
"%s+"
)
Return value:
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)
Return value:
wrapped paragraph