<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <head> <title>Penlight Documentation</title> <link rel="stylesheet" href="../ldoc.css" type="text/css" /> </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"> <!-- Menu --> <div id="navigation"> <br/> <h1>Penlight</h1> <ul> <li><a href="../index.html">Index</a></li> </ul> <h2>Contents</h2> <ul> <li><a href="#Functions">Functions</a></li> </ul> <h2>Modules</h2> <ul> <li><a href="../modules/config.html">config</a></li> <li><a href="../modules/pl.html">pl</a></li> <li><a href="../modules/pl.Date.html">pl.Date</a></li> <li><a href="../modules/pl.List.html">pl.List</a></li> <li><a href="../modules/pl.Map.html">pl.Map</a></li> <li><a href="../modules/pl.MultiMap.html">pl.MultiMap</a></li> <li><a href="../modules/pl.OrderedMap.html">pl.OrderedMap</a></li> <li><a href="../modules/pl.Set.html">pl.Set</a></li> <li><a href="../modules/pl.app.html">pl.app</a></li> <li><a href="../modules/pl.array2d.html">pl.array2d</a></li> <li><a href="../modules/pl.class.html">pl.class</a></li> <li><a href="../modules/pl.comprehension.html">pl.comprehension</a></li> <li><a href="../modules/pl.data.html">pl.data</a></li> <li><a href="../modules/pl.dir.html">pl.dir</a></li> <li><a href="../modules/pl.file.html">pl.file</a></li> <li><a href="../modules/pl.func.html">pl.func</a></li> <li><a href="../modules/pl.import_into.html">pl.import_into</a></li> <li><a href="../modules/pl.input.html">pl.input</a></li> <li><a href="../modules/pl.lapp.html">pl.lapp</a></li> <li><a href="../modules/pl.lexer.html">pl.lexer</a></li> <li><a href="../modules/pl.luabalanced.html">pl.luabalanced</a></li> <li><a href="../modules/pl.operator.html">pl.operator</a></li> <li><a href="../modules/pl.path.html">pl.path</a></li> <li><a href="../modules/pl.permute.html">pl.permute</a></li> <li><a href="../modules/pl.platf.luajava.html">pl.platf.luajava</a></li> <li><a href="../modules/pl.pretty.html">pl.pretty</a></li> <li><a href="../modules/pl.seq.html">pl.seq</a></li> <li><a href="../modules/pl.sip.html">pl.sip</a></li> <li><a href="../modules/pl.strict.html">pl.strict</a></li> <li><a href="../modules/pl.stringio.html">pl.stringio</a></li> <li><strong>pl.stringx</strong></li> <li><a href="../modules/pl.tablex.html">pl.tablex</a></li> <li><a href="../modules/pl.template.html">pl.template</a></li> <li><a href="../modules/pl.test.html">pl.test</a></li> <li><a href="../modules/pl.text.html">pl.text</a></li> <li><a href="../modules/pl.utils.html">pl.utils</a></li> <li><a href="../modules/pl.xml.html">pl.xml</a></li> </ul> <h2>Topics</h2> <ul> <li><a href="../topics/01-introduction.md.html">01-introduction.md</a></li> <li><a href="../topics/02-arrays.md.html">02-arrays.md</a></li> <li><a href="../topics/03-strings.md.html">03-strings.md</a></li> <li><a href="../topics/04-paths.md.html">04-paths.md</a></li> <li><a href="../topics/05-dates.md.html">05-dates.md</a></li> <li><a href="../topics/06-data.md.html">06-data.md</a></li> <li><a href="../topics/07-functional.md.html">07-functional.md</a></li> <li><a href="../topics/08-additional.md.html">08-additional.md</a></li> <li><a href="../topics/09-discussion.md.html">09-discussion.md</a></li> </ul> <h2>Examples</h2> <ul> <li><a href="../examples/seesubst.lua.html">seesubst.lua</a></li> <li><a href="../examples/sipscan.lua.html">sipscan.lua</a></li> <li><a href="../examples/symbols.lua.html">symbols.lua</a></li> <li><a href="../examples/test-cmp.lua.html">test-cmp.lua</a></li> <li><a href="../examples/test-data.lua.html">test-data.lua</a></li> <li><a href="../examples/test-listcallbacks.lua.html">test-listcallbacks.lua</a></li> <li><a href="../examples/test-pretty.lua.html">test-pretty.lua</a></li> <li><a href="../examples/test-symbols.lua.html">test-symbols.lua</a></li> <li><a href="../examples/testapp.lua.html">testapp.lua</a></li> <li><a href="../examples/testclone.lua.html">testclone.lua</a></li> <li><a href="../examples/testconfig.lua.html">testconfig.lua</a></li> <li><a href="../examples/testglobal.lua.html">testglobal.lua</a></li> <li><a href="../examples/testinputfields.lua.html">testinputfields.lua</a></li> <li><a href="../examples/testinputfields2.lua.html">testinputfields2.lua</a></li> <li><a href="../examples/testxml.lua.html">testxml.lua</a></li> <li><a href="../examples/which.lua.html">which.lua</a></li> </ul> </div> <div id="content"> <h1>Module <code>pl.stringx</code></h1> <p>Python-style extended string library.</p> <p> see 3.6.1 of the Python reference. If you want to make these available as string methods, then say <code>stringx.import()</code> to bring them into the standard <a href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a> table.</p> <p> See <a href="../topics/03-strings.md.html#">the Guide</a></p> <p> Dependencies: <a href="../modules/pl.utils.html#">pl.utils</a> </p> <h2><a href="#Functions">Functions</a></h2> <table class="function_list"> <tr> <td class="name" nowrap><a href="#isalpha">isalpha (s)</a></td> <td class="summary">does s only contain alphabetic characters?.</td> </tr> <tr> <td class="name" nowrap><a href="#isdigit">isdigit (s)</a></td> <td class="summary">does s only contain digits?.</td> </tr> <tr> <td class="name" nowrap><a href="#isalnum">isalnum (s)</a></td> <td class="summary">does s only contain alphanumeric characters?.</td> </tr> <tr> <td class="name" nowrap><a href="#isspace">isspace (s)</a></td> <td class="summary">does s only contain spaces?.</td> </tr> <tr> <td class="name" nowrap><a href="#islower">islower (s)</a></td> <td class="summary">does s only contain lower case characters?.</td> </tr> <tr> <td class="name" nowrap><a href="#isupper">isupper (s)</a></td> <td class="summary">does s only contain upper case characters?.</td> </tr> <tr> <td class="name" nowrap><a href="#join">join (self, seq)</a></td> <td class="summary">concatenate the strings using this string as a delimiter.</td> </tr> <tr> <td class="name" nowrap><a href="#startswith">startswith (self, s2)</a></td> <td class="summary">does string start with the substring?.</td> </tr> <tr> <td class="name" nowrap><a href="#endswith">endswith (s, send)</a></td> <td class="summary">does string end with the given substring?.</td> </tr> <tr> <td class="name" nowrap><a href="#expandtabs">expandtabs (self, n)</a></td> <td class="summary">replace all tabs in s with n spaces.</td> </tr> <tr> <td class="name" nowrap><a href="#lfind">lfind (self, sub, i1)</a></td> <td class="summary">find index of first instance of sub in s from the left.</td> </tr> <tr> <td class="name" nowrap><a href="#rfind">rfind (self, sub, first, last)</a></td> <td class="summary">find index of first instance of sub in s from the right.</td> </tr> <tr> <td class="name" nowrap><a href="#replace">replace (s, old, new, n)</a></td> <td class="summary">replace up to n instances of old by new in the string s.</td> </tr> <tr> <td class="name" nowrap><a href="#split">split (self, re, n)</a></td> <td class="summary">split a string into a list of strings using a delimiter.</td> </tr> <tr> <td class="name" nowrap><a href="#splitv">splitv (self, re)</a></td> <td class="summary">split a string using a pattern.</td> </tr> <tr> <td class="name" nowrap><a href="#count">count (self, sub)</a></td> <td class="summary">count all instances of substring in string.</td> </tr> <tr> <td class="name" nowrap><a href="#ljust">ljust (self, w, ch)</a></td> <td class="summary">left-justify s with width w.</td> </tr> <tr> <td class="name" nowrap><a href="#rjust">rjust (s, w, ch)</a></td> <td class="summary">right-justify s with width w.</td> </tr> <tr> <td class="name" nowrap><a href="#center">center (s, w, ch)</a></td> <td class="summary">center-justify s with width w.</td> </tr> <tr> <td class="name" nowrap><a href="#lstrip">lstrip (self, chrs)</a></td> <td class="summary">trim any whitespace on the left of s.</td> </tr> <tr> <td class="name" nowrap><a href="#rstrip">rstrip (s, chrs)</a></td> <td class="summary">trim any whitespace on the right of s.</td> </tr> <tr> <td class="name" nowrap><a href="#strip">strip (self, chrs)</a></td> <td class="summary">trim any whitespace on both left and right of s.</td> </tr> <tr> <td class="name" nowrap><a href="#partition">partition (self, ch)</a></td> <td class="summary">partition the string using first occurance of a delimiter</td> </tr> <tr> <td class="name" nowrap><a href="#rpartition">rpartition (self, ch)</a></td> <td class="summary">partition the string p using last occurance of a delimiter</td> </tr> <tr> <td class="name" nowrap><a href="#at">at (self, idx)</a></td> <td class="summary">return the 'character' at the index.</td> </tr> <tr> <td class="name" nowrap><a href="#lines">lines (self)</a></td> <td class="summary">return an interator over all lines in a string</td> </tr> <tr> <td class="name" nowrap><a href="#title">title (self)</a></td> <td class="summary">iniital word letters uppercase ('title case').</td> </tr> <tr> <td class="name" nowrap><a href="#shorten">shorten (self, sz, tail)</a></td> <td class="summary">return a shorted version of a string.</td> </tr> </table> <br/> <br/> <h2><a name="Functions"></a>Functions</h2> <dl class="function"> <dt> <a name = "isalpha"></a> <strong>isalpha (s)</strong> </dt> <dd> does s only contain alphabetic characters?. <h3>Parameters:</h3> <ul> <li><span class="parameter">s</span> a string</li> </ul> </dd> <dt> <a name = "isdigit"></a> <strong>isdigit (s)</strong> </dt> <dd> does s only contain digits?. <h3>Parameters:</h3> <ul> <li><span class="parameter">s</span> a string</li> </ul> </dd> <dt> <a name = "isalnum"></a> <strong>isalnum (s)</strong> </dt> <dd> does s only contain alphanumeric characters?. <h3>Parameters:</h3> <ul> <li><span class="parameter">s</span> a string</li> </ul> </dd> <dt> <a name = "isspace"></a> <strong>isspace (s)</strong> </dt> <dd> does s only contain spaces?. <h3>Parameters:</h3> <ul> <li><span class="parameter">s</span> a string</li> </ul> </dd> <dt> <a name = "islower"></a> <strong>islower (s)</strong> </dt> <dd> does s only contain lower case characters?. <h3>Parameters:</h3> <ul> <li><span class="parameter">s</span> a string</li> </ul> </dd> <dt> <a name = "isupper"></a> <strong>isupper (s)</strong> </dt> <dd> does s only contain upper case characters?. <h3>Parameters:</h3> <ul> <li><span class="parameter">s</span> a string</li> </ul> </dd> <dt> <a name = "join"></a> <strong>join (self, seq)</strong> </dt> <dd> concatenate the strings using this string as a delimiter. <h3>Parameters:</h3> <ul> <li><span class="parameter">self</span> the string</li> <li><span class="parameter">seq</span> a table of strings or numbers</li> </ul> <h3>Usage:</h3> <ul> <pre class="example">(<span class="string">' '</span>):join {<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>} == <span class="string">'1 2 3'</span></pre> </ul> </dd> <dt> <a name = "startswith"></a> <strong>startswith (self, s2)</strong> </dt> <dd> does string start with the substring?. <h3>Parameters:</h3> <ul> <li><span class="parameter">self</span> the string</li> <li><span class="parameter">s2</span> a string</li> </ul> </dd> <dt> <a name = "endswith"></a> <strong>endswith (s, send)</strong> </dt> <dd> does string end with the given substring?. <h3>Parameters:</h3> <ul> <li><span class="parameter">s</span> a string</li> <li><span class="parameter">send</span> a substring or a table of suffixes</li> </ul> </dd> <dt> <a name = "expandtabs"></a> <strong>expandtabs (self, n)</strong> </dt> <dd> 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) <h3>Parameters:</h3> <ul> <li><span class="parameter">self</span> the string</li> <li><span class="parameter">n</span> number of spaces to expand each tab, (default 8)</li> </ul> </dd> <dt> <a name = "lfind"></a> <strong>lfind (self, sub, i1)</strong> </dt> <dd> find index of first instance of sub in s from the left. <h3>Parameters:</h3> <ul> <li><span class="parameter">self</span> the string</li> <li><span class="parameter">sub</span> substring</li> <li><span class="parameter">i1</span> start index</li> </ul> </dd> <dt> <a name = "rfind"></a> <strong>rfind (self, sub, first, last)</strong> </dt> <dd> find index of first instance of sub in s from the right. <h3>Parameters:</h3> <ul> <li><span class="parameter">self</span> the string</li> <li><span class="parameter">sub</span> substring</li> <li><span class="parameter">first</span> first index</li> <li><span class="parameter">last</span> last index</li> </ul> </dd> <dt> <a name = "replace"></a> <strong>replace (s, old, new, n)</strong> </dt> <dd> replace up to n instances of old by new in the string s. if n is not present, replace all instances. <h3>Parameters:</h3> <ul> <li><span class="parameter">s</span> the string</li> <li><span class="parameter">old</span> the target substring</li> <li><span class="parameter">new</span> the substitution</li> <li><span class="parameter">n</span> optional maximum number of substitutions</li> </ul> <h3>Returns:</h3> <ol> <li> result string</li> <li> the number of substitutions</li> </ol> </dd> <dt> <a name = "split"></a> <strong>split (self, re, n)</strong> </dt> <dd> split a string into a list of strings using a delimiter. <h3>Parameters:</h3> <ul> <li><span class="parameter">self</span> the string</li> <li><span class="parameter">re</span> a delimiter (defaults to whitespace)</li> <li><span class="parameter">n</span> maximum number of results</li> </ul> <h3>Usage:</h3> <ul> <li><pre class="example">#((<span class="string">'one two'</span>):split()) == <span class="number">2</span></pre></li> <li><pre class="example">(<span class="string">'one,two,three'</span>):split(<span class="string">','</span>) == List{<span class="string">'one'</span>,<span class="string">'two'</span>,<span class="string">'three'</span>}</pre></li> <li><pre class="example">(<span class="string">'one,two,three'</span>):split(<span class="string">','</span>,<span class="number">2</span>) == List{<span class="string">'one'</span>,<span class="string">'two,three'</span>}</pre></li> </ul> </dd> <dt> <a name = "splitv"></a> <strong>splitv (self, re)</strong> </dt> <dd> split a string using a pattern. Note that at least one value will be returned! <h3>Parameters:</h3> <ul> <li><span class="parameter">self</span> the string</li> <li><span class="parameter">re</span> a Lua string pattern (defaults to whitespace)</li> </ul> <h3>Returns:</h3> <ol> the parts of the string </ol> <h3>Usage:</h3> <ul> <pre class="example">a,b = line:splitv(<span class="string">'='</span>)</pre> </ul> </dd> <dt> <a name = "count"></a> <strong>count (self, sub)</strong> </dt> <dd> count all instances of substring in string. <h3>Parameters:</h3> <ul> <li><span class="parameter">self</span> the string</li> <li><span class="parameter">sub</span> substring</li> </ul> </dd> <dt> <a name = "ljust"></a> <strong>ljust (self, w, ch)</strong> </dt> <dd> left-justify s with width w. <h3>Parameters:</h3> <ul> <li><span class="parameter">self</span> the string</li> <li><span class="parameter">w</span> width of justification</li> <li><span class="parameter">ch</span> padding character, default ' '</li> </ul> </dd> <dt> <a name = "rjust"></a> <strong>rjust (s, w, ch)</strong> </dt> <dd> right-justify s with width w. <h3>Parameters:</h3> <ul> <li><span class="parameter">s</span> the string</li> <li><span class="parameter">w</span> width of justification</li> <li><span class="parameter">ch</span> padding character, default ' '</li> </ul> </dd> <dt> <a name = "center"></a> <strong>center (s, w, ch)</strong> </dt> <dd> center-justify s with width w. <h3>Parameters:</h3> <ul> <li><span class="parameter">s</span> the string</li> <li><span class="parameter">w</span> width of justification</li> <li><span class="parameter">ch</span> padding character, default ' '</li> </ul> </dd> <dt> <a name = "lstrip"></a> <strong>lstrip (self, chrs)</strong> </dt> <dd> <p>trim any whitespace on the left of s. </p> <pre><code> can be a string of characters to be trimmed </code></pre> <h3>Parameters:</h3> <ul> <li><span class="parameter">self</span> the string</li> <li><span class="parameter">chrs</span> default any whitespace character (%s),</li> </ul> </dd> <dt> <a name = "rstrip"></a> <strong>rstrip (s, chrs)</strong> </dt> <dd> <p>trim any whitespace on the right of s. </p> <pre><code> can be a string of characters to be trimmed </code></pre> <h3>Parameters:</h3> <ul> <li><span class="parameter">s</span> the string</li> <li><span class="parameter">chrs</span> default any whitespace character (%s),</li> </ul> </dd> <dt> <a name = "strip"></a> <strong>strip (self, chrs)</strong> </dt> <dd> <p>trim any whitespace on both left and right of s. </p> <pre><code> can be a string of characters to be trimmed </code></pre> <h3>Parameters:</h3> <ul> <li><span class="parameter">self</span> the string</li> <li><span class="parameter">chrs</span> default any whitespace character (%s),</li> </ul> </dd> <dt> <a name = "partition"></a> <strong>partition (self, ch)</strong> </dt> <dd> partition the string using first occurance of a delimiter <h3>Parameters:</h3> <ul> <li><span class="parameter">self</span> the string</li> <li><span class="parameter">ch</span> delimiter</li> </ul> <h3>Returns:</h3> <ol> <li> part before ch</li> <li> ch</li> <li> part after ch</li> </ol> </dd> <dt> <a name = "rpartition"></a> <strong>rpartition (self, ch)</strong> </dt> <dd> partition the string p using last occurance of a delimiter <h3>Parameters:</h3> <ul> <li><span class="parameter">self</span> the string</li> <li><span class="parameter">ch</span> delimiter</li> </ul> <h3>Returns:</h3> <ol> <li> part before ch</li> <li> ch</li> <li> part after ch</li> </ol> </dd> <dt> <a name = "at"></a> <strong>at (self, idx)</strong> </dt> <dd> return the 'character' at the index. <h3>Parameters:</h3> <ul> <li><span class="parameter">self</span> the string</li> <li><span class="parameter">idx</span> an index (can be negative)</li> </ul> <h3>Returns:</h3> <ol> a substring of length 1 if successful, empty string otherwise. </ol> </dd> <dt> <a name = "lines"></a> <strong>lines (self)</strong> </dt> <dd> return an interator over all lines in a string <h3>Parameters:</h3> <ul> <li><span class="parameter">self</span> the string</li> </ul> <h3>Returns:</h3> <ol> an iterator </ol> </dd> <dt> <a name = "title"></a> <strong>title (self)</strong> </dt> <dd> iniital word letters uppercase ('title case'). Here 'words' mean chunks of non-space characters. <h3>Parameters:</h3> <ul> <li><span class="parameter">self</span> the string</li> </ul> <h3>Returns:</h3> <ol> a string with each word's first letter uppercase </ol> </dd> <dt> <a name = "shorten"></a> <strong>shorten (self, sz, tail)</strong> </dt> <dd> return a shorted version of a string. <h3>Parameters:</h3> <ul> <li><span class="parameter">self</span> the string</li> <li><span class="parameter">sz</span> the maxinum size allowed</li> <li><span class="parameter">tail</span> true if we want to show the end of the string (head otherwise)</li> </ul> </dd> </dl> </div> <!-- id="content" --> </div> <!-- id="main" --> <div id="about"> <i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.3</a></i> </div> <!-- id="about" --> </div> <!-- id="container" --> </body> </html>