814 lines
10 KiB
HTML
814 lines
10 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
<html>
|
|
<head>
|
|
<title>string: Module Index</title>
|
|
<link rel="stylesheet" href="../luadoc.css" type="text/css" />
|
|
<!--meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/-->
|
|
</head>
|
|
|
|
<body>
|
|
<div id="container">
|
|
|
|
<div id="product">
|
|
<div id="product_logo"></div>
|
|
<div id="product_name"><big><b></b></big></div>
|
|
<div id="product_description"></div>
|
|
</div> <!-- id="product" -->
|
|
|
|
<div id="main">
|
|
|
|
<div id="navigation">
|
|
|
|
|
|
<h1>LuaDoc</h1>
|
|
<ul>
|
|
|
|
<li><a href="../index.html">Index</a></li>
|
|
|
|
</ul>
|
|
|
|
|
|
<!-- Module list -->
|
|
|
|
<h1>Modules</h1>
|
|
<ul>
|
|
|
|
<li>
|
|
<a href="../modules/base.html">base</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../modules/bin.html">bin</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../modules/debug.html">debug</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../modules/fstable.html">fstable</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../modules/getopt.html">getopt</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../modules/io.html">io</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../modules/lcs.html">lcs</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../modules/list.html">list</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../modules/math.html">math</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../modules/mbox.html">mbox</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../modules/object.html">object</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../modules/package.html">package</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../modules/parser.html">parser</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../modules/set.html">set</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../modules/std.html">std</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../modules/strbuf.html">strbuf</a>
|
|
</li>
|
|
|
|
<li><strong>string</strong></li>
|
|
|
|
<li>
|
|
<a href="../modules/table.html">table</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../modules/tree.html">tree</a>
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
<!-- File list -->
|
|
|
|
<h1>Files</h1>
|
|
<ul>
|
|
|
|
<li>
|
|
<a href="../files/base.html">base.lua</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../files/bin.html">bin.lua</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../files/debug_ext.html">debug_ext.lua</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../files/debug_init.html">debug_init.lua</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../files/fstable.html">fstable.lua</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../files/getopt.html">getopt.lua</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../files/io_ext.html">io_ext.lua</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../files/lcs.html">lcs.lua</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../files/list.html">list.lua</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../files/math_ext.html">math_ext.lua</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../files/mbox.html">mbox.lua</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../files/modules.html">modules.lua</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../files/object.html">object.lua</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../files/package_ext.html">package_ext.lua</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../files/parser.html">parser.lua</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../files/set.html">set.lua</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../files/std.html">std.lua</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../files/strbuf.html">strbuf.lua</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../files/strict.html">strict.lua</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../files/string_ext.html">string_ext.lua</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../files/table_ext.html">table_ext.lua</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../files/tree.html">tree.lua</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../files/xml.html">xml.lua</a>
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</div><!-- id="navigation" -->
|
|
|
|
<div id="content">
|
|
|
|
<h1>Module <code>string</code></h1>
|
|
|
|
<p>Additions to the string module TODO: Pretty printing (use in getopt); see source for details.</p>
|
|
|
|
|
|
|
|
|
|
|
|
<h2>Functions</h2>
|
|
<table class="function_list">
|
|
|
|
<tr>
|
|
<td class="name" nowrap><a href="#caps">caps</a> (s)</td>
|
|
<td class="summary">Capitalise each word in a string.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="name" nowrap><a href="#chomp">chomp</a> (s)</td>
|
|
<td class="summary">Remove any final newline from a string.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="name" nowrap><a href="#escapePattern">escapePattern</a> (s)</td>
|
|
<td class="summary">Escape a string to be used as a pattern </td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="name" nowrap><a href="#finds">finds</a> (s, p, init, plain)</td>
|
|
<td class="summary">Do multiple <code>find</code>s on a string.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="name" nowrap><a href="#gsubs">gsubs</a> (s, sub, n)</td>
|
|
<td class="summary">Perform multiple calls to gsub.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="name" nowrap><a href="#ltrim">ltrim</a> (s, r)</td>
|
|
<td class="summary">Remove leading matter from a string.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="name" nowrap><a href="#numbertosi">numbertosi</a> (n)</td>
|
|
<td class="summary">Write a number using SI suffixes.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="name" nowrap><a href="#ordinalSuffix">ordinalSuffix</a> (n)</td>
|
|
<td class="summary">Return the English suffix for an ordinal.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="name" nowrap><a href="#pad">pad</a> (s, w, p)</td>
|
|
<td class="summary">Justify a string.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="name" nowrap><a href="#rtrim">rtrim</a> (s, r)</td>
|
|
<td class="summary">Remove trailing matter from a string.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="name" nowrap><a href="#split">split</a> (s, sep)</td>
|
|
<td class="summary">Split a string at a given separator.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="name" nowrap><a href="#tfind">tfind</a> (s, p, init, plain)</td>
|
|
<td class="summary">Do find, returning captures as a list.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="name" nowrap><a href="#trim">trim</a> (s, r)</td>
|
|
<td class="summary">Remove leading and trailing matter from a string.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="name" nowrap><a href="#wrap">wrap</a> (s, w, ind, ind1)</td>
|
|
<td class="summary">Wrap a string into a paragraph.</td>
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<br/>
|
|
<br/>
|
|
|
|
|
|
|
|
<h2><a name="functions"></a>Functions</h2>
|
|
<dl class="function">
|
|
|
|
|
|
|
|
<dt><a name="caps"></a><strong>caps</strong> (s)</dt>
|
|
<dd>
|
|
Capitalise each word in a string.
|
|
|
|
|
|
<h3>Parameters</h3>
|
|
<ul>
|
|
|
|
<li>
|
|
s: string
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3>Return value:</h3>
|
|
capitalised string
|
|
|
|
|
|
|
|
</dd>
|
|
|
|
|
|
|
|
|
|
<dt><a name="chomp"></a><strong>chomp</strong> (s)</dt>
|
|
<dd>
|
|
Remove any final newline from a string.
|
|
|
|
|
|
<h3>Parameters</h3>
|
|
<ul>
|
|
|
|
<li>
|
|
s: string to process
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3>Return value:</h3>
|
|
processed string
|
|
|
|
|
|
|
|
</dd>
|
|
|
|
|
|
|
|
|
|
<dt><a name="escapePattern"></a><strong>escapePattern</strong> (s)</dt>
|
|
<dd>
|
|
Escape a string to be used as a pattern
|
|
|
|
|
|
<h3>Parameters</h3>
|
|
<ul>
|
|
|
|
<li>
|
|
s: string to process @return
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</dd>
|
|
|
|
|
|
|
|
|
|
<dt><a name="finds"></a><strong>finds</strong> (s, p, init, plain)</dt>
|
|
<dd>
|
|
Do multiple <code>find</code>s on a string.
|
|
|
|
|
|
<h3>Parameters</h3>
|
|
<ul>
|
|
|
|
<li>
|
|
s: target string
|
|
</li>
|
|
|
|
<li>
|
|
p: pattern
|
|
</li>
|
|
|
|
<li>
|
|
init: start position (default: 1)
|
|
</li>
|
|
|
|
<li>
|
|
plain: inhibit magic characters (default: nil)
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3>Return value:</h3>
|
|
list of <code>{from, to; capt = {captures}}</code>
|
|
|
|
|
|
|
|
</dd>
|
|
|
|
|
|
|
|
|
|
<dt><a name="gsubs"></a><strong>gsubs</strong> (s, sub, n)</dt>
|
|
<dd>
|
|
Perform multiple calls to gsub.
|
|
|
|
|
|
<h3>Parameters</h3>
|
|
<ul>
|
|
|
|
<li>
|
|
s: string to call gsub on
|
|
</li>
|
|
|
|
<li>
|
|
sub: <code>{pattern1=replacement1 ...}</code>
|
|
</li>
|
|
|
|
<li>
|
|
n: upper limit on replacements (default: infinite)
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3>Return values:</h3>
|
|
<ol>
|
|
|
|
<li>result string
|
|
|
|
<li>number of replacements made
|
|
|
|
</ol>
|
|
|
|
|
|
|
|
</dd>
|
|
|
|
|
|
|
|
|
|
<dt><a name="ltrim"></a><strong>ltrim</strong> (s, r)</dt>
|
|
<dd>
|
|
Remove leading matter from a string.
|
|
|
|
|
|
<h3>Parameters</h3>
|
|
<ul>
|
|
|
|
<li>
|
|
s: string
|
|
</li>
|
|
|
|
<li>
|
|
r: leading regex (default: <code>"%s+"</code>)
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3>Return value:</h3>
|
|
string without leading r
|
|
|
|
|
|
|
|
</dd>
|
|
|
|
|
|
|
|
|
|
<dt><a name="numbertosi"></a><strong>numbertosi</strong> (n)</dt>
|
|
<dd>
|
|
Write a number using SI suffixes. The number is always written to 3 s.f.
|
|
|
|
|
|
<h3>Parameters</h3>
|
|
<ul>
|
|
|
|
<li>
|
|
n: number
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3>Return value:</h3>
|
|
string
|
|
|
|
|
|
|
|
</dd>
|
|
|
|
|
|
|
|
|
|
<dt><a name="ordinalSuffix"></a><strong>ordinalSuffix</strong> (n)</dt>
|
|
<dd>
|
|
Return the English suffix for an ordinal.
|
|
|
|
|
|
<h3>Parameters</h3>
|
|
<ul>
|
|
|
|
<li>
|
|
n: number of the day
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3>Return value:</h3>
|
|
suffix
|
|
|
|
|
|
|
|
</dd>
|
|
|
|
|
|
|
|
|
|
<dt><a name="pad"></a><strong>pad</strong> (s, w, p)</dt>
|
|
<dd>
|
|
Justify a string. When the string is longer than w, it is truncated (left or right according to the sign of w).
|
|
|
|
|
|
<h3>Parameters</h3>
|
|
<ul>
|
|
|
|
<li>
|
|
s: string to justify
|
|
</li>
|
|
|
|
<li>
|
|
w: width to justify to (-ve means right-justify; +ve means left-justify)
|
|
</li>
|
|
|
|
<li>
|
|
p: string to pad with (default: <code>" "</code>)
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3>Return value:</h3>
|
|
justified string
|
|
|
|
|
|
|
|
</dd>
|
|
|
|
|
|
|
|
|
|
<dt><a name="rtrim"></a><strong>rtrim</strong> (s, r)</dt>
|
|
<dd>
|
|
Remove trailing matter from a string.
|
|
|
|
|
|
<h3>Parameters</h3>
|
|
<ul>
|
|
|
|
<li>
|
|
s: string
|
|
</li>
|
|
|
|
<li>
|
|
r: trailing regex (default: <code>"%s+"</code>)
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3>Return value:</h3>
|
|
string without trailing r
|
|
|
|
|
|
|
|
</dd>
|
|
|
|
|
|
|
|
|
|
<dt><a name="split"></a><strong>split</strong> (s, sep)</dt>
|
|
<dd>
|
|
Split a string at a given separator. FIXME: Consider Perl and Python versions.
|
|
|
|
|
|
<h3>Parameters</h3>
|
|
<ul>
|
|
|
|
<li>
|
|
s: string to split
|
|
</li>
|
|
|
|
<li>
|
|
sep: separator regex
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3>Return value:</h3>
|
|
list of strings
|
|
|
|
|
|
|
|
</dd>
|
|
|
|
|
|
|
|
|
|
<dt><a name="tfind"></a><strong>tfind</strong> (s, p, init, plain)</dt>
|
|
<dd>
|
|
Do find, returning captures as a list.
|
|
|
|
|
|
<h3>Parameters</h3>
|
|
<ul>
|
|
|
|
<li>
|
|
s: target string
|
|
</li>
|
|
|
|
<li>
|
|
p: pattern
|
|
</li>
|
|
|
|
<li>
|
|
init: start position (default: 1)
|
|
</li>
|
|
|
|
<li>
|
|
plain: inhibit magic characters (default: nil)
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3>Return value:</h3>
|
|
start of match, end of match, table of captures
|
|
|
|
|
|
|
|
</dd>
|
|
|
|
|
|
|
|
|
|
<dt><a name="trim"></a><strong>trim</strong> (s, r)</dt>
|
|
<dd>
|
|
Remove leading and trailing matter from a string.
|
|
|
|
|
|
<h3>Parameters</h3>
|
|
<ul>
|
|
|
|
<li>
|
|
s: string
|
|
</li>
|
|
|
|
<li>
|
|
r: leading/trailing regex (default: <code>"%s+"</code>)
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3>Return value:</h3>
|
|
string without leading/trailing r
|
|
|
|
|
|
|
|
</dd>
|
|
|
|
|
|
|
|
|
|
<dt><a name="wrap"></a><strong>wrap</strong> (s, w, ind, ind1)</dt>
|
|
<dd>
|
|
Wrap a string into a paragraph.
|
|
|
|
|
|
<h3>Parameters</h3>
|
|
<ul>
|
|
|
|
<li>
|
|
s: string to wrap
|
|
</li>
|
|
|
|
<li>
|
|
w: width to wrap to (default: 78)
|
|
</li>
|
|
|
|
<li>
|
|
ind: indent (default: 0)
|
|
</li>
|
|
|
|
<li>
|
|
ind1: indent of first line (default: ind)
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3>Return value:</h3>
|
|
wrapped paragraph
|
|
|
|
|
|
|
|
</dd>
|
|
|
|
|
|
</dl>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</div> <!-- id="content" -->
|
|
|
|
</div> <!-- id="main" -->
|
|
|
|
<div id="about">
|
|
<p><a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /></a></p>
|
|
</div> <!-- id="about" -->
|
|
|
|
</div> <!-- id="container" -->
|
|
</body>
|
|
</html>
|