https://oddworldlibrary.net/oddenc/index.php?title=Module:String&feed=atom&action=history
Module:String - Revision history
2024-03-29T15:55:27Z
Revision history for this page on the wiki
MediaWiki 1.39.3
https://oddworldlibrary.net/oddenc/index.php?title=Module:String&diff=2297&oldid=prev
Wil: 1 revision imported
2021-04-18T13:01:15Z
<p>1 revision imported</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<tr class="diff-title" lang="en">
<td colspan="1" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="1" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 06:01, 18 April 2021</td>
</tr><tr><td colspan="2" class="diff-notice" lang="en"><div class="mw-diff-empty">(No difference)</div>
</td></tr></table>
Wil
https://oddworldlibrary.net/oddenc/index.php?title=Module:String&diff=2296&oldid=prev
Oddlib>RexxS: separate annotations for str.match from those for str._match
2020-08-02T15:49:42Z
<p>separate annotations for str.match from those for str._match</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 08:49, 2 August 2020</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l107">Line 107:</td>
<td colspan="2" class="diff-lineno">Line 107:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>--[[</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>--[[</div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">match</del></div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">_match</ins></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>This function returns a substring from the source string that matches a</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>This function returns a substring from the source string that matches a</div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>specified pattern.</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>specified pattern. <ins style="font-weight: bold; text-decoration: none;">It is exported for use in other modules</ins></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Usage:</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Usage:</div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">{{#invoke</del>:String<del style="font-weight: bold; text-decoration: none;">|match|source_string|pattern_string|start_index|match_number|plain_flag|nomatch_output}}</del></div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">strmatch = require("Module</ins>:String<ins style="font-weight: bold; text-decoration: none;">")._match</ins></div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">OR</del></div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">sresult = strmatch( </ins>s<ins style="font-weight: bold; text-decoration: none;">, </ins>pattern<ins style="font-weight: bold; text-decoration: none;">, </ins>start<ins style="font-weight: bold; text-decoration: none;">, </ins>match<ins style="font-weight: bold; text-decoration: none;">, </ins>plain<ins style="font-weight: bold; text-decoration: none;">, </ins>nomatch <ins style="font-weight: bold; text-decoration: none;">)</ins></div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">{{#invoke:String|match|</del>s<del style="font-weight: bold; text-decoration: none;">=source_string|</del>pattern<del style="font-weight: bold; text-decoration: none;">=pattern_string|</del>start<del style="font-weight: bold; text-decoration: none;">=start_index</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;"> |</del>match<del style="font-weight: bold; text-decoration: none;">=match_number|</del>plain<del style="font-weight: bold; text-decoration: none;">=plain_flag|</del>nomatch<del style="font-weight: bold; text-decoration: none;">=nomatch_output}}</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Parameters</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Parameters</div></td></tr>
<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l131">Line 131:</td>
<td colspan="2" class="diff-lineno">Line 129:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> text. Defaults to false.</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> text. Defaults to false.</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> nomatch: If no match is found, output the "nomatch" value rather than an error.</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> nomatch: If no match is found, output the "nomatch" value rather than an error.</div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;"></del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">If invoked using named parameters, Mediawiki will automatically remove any leading or</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">trailing whitespace from each string. In some circumstances this is desirable, in</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">other cases one may want to preserve the whitespace.</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;"></del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">If the match_number or start_index are out of range for the string being queried, then</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">this function generates an error. An error is also generated if no match is found.</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">If one adds the parameter ignore_errors=true, then the error will be suppressed and</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">an empty string will be returned on any failure.</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>For information on constructing Lua patterns, a form of [regular expression], see:</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>For information on constructing Lua patterns, a form of [regular expression], see:</div></td></tr>
<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l209">Line 209:</td>
<td colspan="2" class="diff-lineno">Line 198:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> end</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> end</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>end</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>end</div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">--[[</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">match</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">This function returns a substring from the source string that matches a</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">specified pattern.</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">Usage:</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">{{#invoke:String|match|source_string|pattern_string|start_index|match_number|plain_flag|nomatch_output}}</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">OR</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">{{#invoke:String|match|s=source_string|pattern=pattern_string|start=start_index</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> |match=match_number|plain=plain_flag|nomatch=nomatch_output}}</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">Parameters</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> s: The string to search</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> pattern: The pattern or string to find within the string</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> start: The index within the source string to start the search. The first</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> character of the string has index 1. Defaults to 1.</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> match: In some cases it may be possible to make multiple matches on a single</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> string. This specifies which match to return, where the first match is</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> match= 1. If a negative number is specified then a match is returned</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> counting from the last match. Hence match = -1 is the same as requesting</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> the last match. Defaults to 1.</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> plain: A flag indicating that the pattern should be understood as plain</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> text. Defaults to false.</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> nomatch: If no match is found, output the "nomatch" value rather than an error.</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">If invoked using named parameters, Mediawiki will automatically remove any leading or</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">trailing whitespace from each string. In some circumstances this is desirable, in</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">other cases one may want to preserve the whitespace.</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">If the match_number or start_index are out of range for the string being queried, then</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">this function generates an error. An error is also generated if no match is found.</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">If one adds the parameter ignore_errors=true, then the error will be suppressed and</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">an empty string will be returned on any failure.</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">For information on constructing Lua patterns, a form of [regular expression], see:</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">* http://www.lua.org/manual/5.1/manual.html#5.4.1</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">* http://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Patterns</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">* http://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Ustring_patterns</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">]]</ins></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>-- This is the entry point for #invoke:String|match</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>-- This is the entry point for #invoke:String|match</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>function str.match( frame )</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>function str.match( frame )</div></td></tr>
</table>
Oddlib>RexxS
https://oddworldlibrary.net/oddenc/index.php?title=Module:String&diff=1758&oldid=prev
Wil: 1 revision imported
2019-07-14T18:58:54Z
<p>1 revision imported</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 11:58, 14 July 2019</td>
</tr>
<!-- diff cache key oddlib_wiki-wiki_:diff::1.12:old-1757:rev-1758 -->
</table>
Wil
https://oddworldlibrary.net/oddenc/index.php?title=Module:String&diff=1757&oldid=prev
en>Dinoguy1000: copy fixed comment from sandbox: this has been wrong for years, and when I corrected it years ago, it just got overwritten later, so rather tan see it happen again, I'm just making the change in the live module now
2019-06-27T17:35:16Z
<p>copy fixed comment from sandbox: this has been wrong for years, and when I <a href="/wiki/Special:Diff/759708044" title="Special:Diff/759708044">corrected</a> it years ago, it just got overwritten later, so rather tan see it happen again, I'm just making the change in the live module now</p>
<a href="https://oddworldlibrary.net/oddenc/index.php?title=Module:String&diff=1757&oldid=1203">Show changes</a>
en>Dinoguy1000
https://oddworldlibrary.net/oddenc/index.php?title=Module:String&diff=1203&oldid=prev
Max: 1 revision imported
2018-04-07T11:49:53Z
<p>1 revision imported</p>
<p><b>New page</b></p><div>--[[ <br />
<br />
This module is intended to provide access to basic string functions.<br />
<br />
Most of the functions provided here can be invoked with named parameters, <br />
unnamed parameters, or a mixture. If named parameters are used, Mediawiki will <br />
automatically remove any leading or trailing whitespace from the parameter. <br />
Depending on the intended use, it may be advantageous to either preserve or<br />
remove such whitespace.<br />
<br />
Global options<br />
ignore_errors: If set to 'true' or 1, any error condition will result in <br />
an empty string being returned rather than an error message. <br />
<br />
error_category: If an error occurs, specifies the name of a category to <br />
include with the error message. The default category is <br />
[Category:Errors reported by Module String].<br />
<br />
no_category: If set to 'true' or 1, no category will be added if an error<br />
is generated.<br />
<br />
Unit tests for this module are available at Module:String/tests.<br />
]]<br />
<br />
local str = {}<br />
<br />
--[[<br />
len<br />
<br />
This function returns the length of the target string.<br />
<br />
Usage:<br />
{{#invoke:String|len|target_string|}}<br />
OR<br />
{{#invoke:String|len|s=target_string}}<br />
<br />
Parameters<br />
s: The string whose length to report<br />
<br />
If invoked using named parameters, Mediawiki will automatically remove any leading or<br />
trailing whitespace from the target string. <br />
]]<br />
function str.len( frame )<br />
local new_args = str._getParameters( frame.args, {'s'} );<br />
local s = new_args['s'] or '';<br />
return mw.ustring.len( s )<br />
end<br />
<br />
--[[<br />
sub<br />
<br />
This function returns a substring of the target string at specified indices.<br />
<br />
Usage:<br />
{{#invoke:String|sub|target_string|start_index|end_index}}<br />
OR<br />
{{#invoke:String|sub|s=target_string|i=start_index|j=end_index}}<br />
<br />
Parameters<br />
s: The string to return a subset of<br />
i: The fist index of the substring to return, defaults to 1.<br />
j: The last index of the string to return, defaults to the last character.<br />
<br />
The first character of the string is assigned an index of 1. If either i or j<br />
is a negative value, it is interpreted the same as selecting a character by <br />
counting from the end of the string. Hence, a value of -1 is the same as <br />
selecting the last character of the string.<br />
<br />
If the requested indices are out of range for the given string, an error is <br />
reported.<br />
]]<br />
function str.sub( frame )<br />
local new_args = str._getParameters( frame.args, { 's', 'i', 'j' } );<br />
local s = new_args['s'] or '';<br />
local i = tonumber( new_args['i'] ) or 1;<br />
local j = tonumber( new_args['j'] ) or -1;<br />
<br />
local len = mw.ustring.len( s );<br />
<br />
-- Convert negatives for range checking<br />
if i < 0 then<br />
i = len + i + 1;<br />
end<br />
if j < 0 then<br />
j = len + j + 1;<br />
end<br />
<br />
if i > len or j > len or i < 1 or j < 1 then<br />
return str._error( 'String subset index out of range' );<br />
end<br />
if j < i then<br />
return str._error( 'String subset indices out of order' );<br />
end<br />
<br />
return mw.ustring.sub( s, i, j )<br />
end<br />
<br />
--[[<br />
This function implements that features of {{str sub old}} and is kept in order<br />
to maintain these older templates.<br />
]]<br />
function str.sublength( frame )<br />
local i = tonumber( frame.args.i ) or 0<br />
local len = tonumber( frame.args.len )<br />
return mw.ustring.sub( frame.args.s, i + 1, len and ( i + len ) )<br />
end<br />
<br />
--[[<br />
match<br />
<br />
This function returns a substring from the source string that matches a <br />
specified pattern.<br />
<br />
Usage:<br />
{{#invoke:String|match|source_string|pattern_string|start_index|match_number|plain_flag|nomatch_output}}<br />
OR<br />
{{#invoke:String|pos|s=source_string|pattern=pattern_string|start=start_index<br />
|match=match_number|plain=plain_flag|nomatch=nomatch_output}}<br />
<br />
Parameters<br />
s: The string to search<br />
pattern: The pattern or string to find within the string<br />
start: The index within the source string to start the search. The first<br />
character of the string has index 1. Defaults to 1.<br />
match: In some cases it may be possible to make multiple matches on a single <br />
string. This specifies which match to return, where the first match is <br />
match= 1. If a negative number is specified then a match is returned <br />
counting from the last match. Hence match = -1 is the same as requesting<br />
the last match. Defaults to 1.<br />
plain: A flag indicating that the pattern should be understood as plain<br />
text. Defaults to false.<br />
nomatch: If no match is found, output the "nomatch" value rather than an error.<br />
<br />
If invoked using named parameters, Mediawiki will automatically remove any leading or<br />
trailing whitespace from each string. In some circumstances this is desirable, in <br />
other cases one may want to preserve the whitespace.<br />
<br />
If the match_number or start_index are out of range for the string being queried, then<br />
this function generates an error. An error is also generated if no match is found.<br />
If one adds the parameter ignore_errors=true, then the error will be suppressed and <br />
an empty string will be returned on any failure.<br />
<br />
For information on constructing Lua patterns, a form of [regular expression], see:<br />
<br />
* http://www.lua.org/manual/5.1/manual.html#5.4.1<br />
* http://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Patterns<br />
* http://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Ustring_patterns<br />
<br />
]]<br />
function str.match( frame )<br />
local new_args = str._getParameters( frame.args, {'s', 'pattern', 'start', 'match', 'plain', 'nomatch'} );<br />
local s = new_args['s'] or '';<br />
local start = tonumber( new_args['start'] ) or 1;<br />
local plain_flag = str._getBoolean( new_args['plain'] or false );<br />
local pattern = new_args['pattern'] or '';<br />
local match_index = math.floor( tonumber(new_args['match']) or 1 );<br />
local nomatch = new_args['nomatch'];<br />
<br />
if s == '' then<br />
return str._error( 'Target string is empty' );<br />
end<br />
if pattern == '' then<br />
return str._error( 'Pattern string is empty' );<br />
end<br />
if math.abs(start) < 1 or math.abs(start) > mw.ustring.len( s ) then<br />
return str._error( 'Requested start is out of range' );<br />
end<br />
if match_index == 0 then<br />
return str._error( 'Match index is out of range' );<br />
end<br />
if plain_flag then<br />
pattern = str._escapePattern( pattern );<br />
end<br />
<br />
local result<br />
if match_index == 1 then<br />
-- Find first match is simple case<br />
result = mw.ustring.match( s, pattern, start )<br />
else<br />
if start > 1 then<br />
s = mw.ustring.sub( s, start );<br />
end<br />
<br />
local iterator = mw.ustring.gmatch(s, pattern);<br />
if match_index > 0 then<br />
-- Forward search<br />
for w in iterator do<br />
match_index = match_index - 1;<br />
if match_index == 0 then<br />
result = w;<br />
break;<br />
end<br />
end <br />
else<br />
-- Reverse search<br />
local result_table = {};<br />
local count = 1;<br />
for w in iterator do<br />
result_table[count] = w;<br />
count = count + 1;<br />
end<br />
<br />
result = result_table[ count + match_index ]; <br />
end<br />
end <br />
<br />
if result == nil then<br />
if nomatch == nil then<br />
return str._error( 'Match not found' );<br />
else<br />
return nomatch;<br />
end<br />
else<br />
return result;<br />
end<br />
end<br />
<br />
--[[<br />
pos<br />
<br />
This function returns a single character from the target string at position pos.<br />
<br />
Usage:<br />
{{#invoke:String|pos|target_string|index_value}}<br />
OR<br />
{{#invoke:String|pos|target=target_string|pos=index_value}}<br />
<br />
Parameters<br />
target: The string to search<br />
pos: The index for the character to return<br />
<br />
If invoked using named parameters, Mediawiki will automatically remove any leading or<br />
trailing whitespace from the target string. In some circumstances this is desirable, in <br />
other cases one may want to preserve the whitespace.<br />
<br />
The first character has an index value of 1.<br />
<br />
If one requests a negative value, this function will select a character by counting backwards <br />
from the end of the string. In other words pos = -1 is the same as asking for the last character.<br />
<br />
A requested value of zero, or a value greater than the length of the string returns an error.<br />
]]<br />
function str.pos( frame )<br />
local new_args = str._getParameters( frame.args, {'target', 'pos'} );<br />
local target_str = new_args['target'] or '';<br />
local pos = tonumber( new_args['pos'] ) or 0;<br />
<br />
if pos == 0 or math.abs(pos) > mw.ustring.len( target_str ) then<br />
return str._error( 'String index out of range' );<br />
end <br />
<br />
return mw.ustring.sub( target_str, pos, pos );<br />
end<br />
<br />
--[[<br />
str_find<br />
<br />
This function duplicates the behavior of {{str_find}}, including all of its quirks.<br />
This is provided in order to support existing templates, but is NOT RECOMMENDED for <br />
new code and templates. New code is recommended to use the "find" function instead.<br />
<br />
Returns the first index in "source" that is a match to "target". Indexing is 1-based,<br />
and the function returns -1 if the "target" string is not present in "source".<br />
<br />
Important Note: If the "target" string is empty / missing, this function returns a<br />
value of "1", which is generally unexpected behavior, and must be accounted for<br />
separatetly.<br />
]]<br />
function str.str_find( frame )<br />
local new_args = str._getParameters( frame.args, {'source', 'target'} );<br />
local source_str = new_args['source'] or '';<br />
local target_str = new_args['target'] or '';<br />
<br />
if target_str == '' then<br />
return 1;<br />
end <br />
<br />
local start = mw.ustring.find( source_str, target_str, 1, true )<br />
if start == nil then<br />
start = -1<br />
end<br />
<br />
return start<br />
end<br />
<br />
--[[<br />
find<br />
<br />
This function allows one to search for a target string or pattern within another<br />
string.<br />
<br />
Usage:<br />
{{#invoke:String|find|source_str|target_string|start_index|plain_flag}}<br />
OR<br />
{{#invoke:String|find|source=source_str|target=target_str|start=start_index|plain=plain_flag}}<br />
<br />
Parameters<br />
source: The string to search<br />
target: The string or pattern to find within source<br />
start: The index within the source string to start the search, defaults to 1<br />
plain: Boolean flag indicating that target should be understood as plain<br />
text and not as a Lua style regular expression, defaults to true<br />
<br />
If invoked using named parameters, Mediawiki will automatically remove any leading or<br />
trailing whitespace from the parameter. In some circumstances this is desirable, in <br />
other cases one may want to preserve the whitespace.<br />
<br />
This function returns the first index >= "start" where "target" can be found <br />
within "source". Indices are 1-based. If "target" is not found, then this <br />
function returns 0. If either "source" or "target" are missing / empty, this<br />
function also returns 0.<br />
<br />
This function should be safe for UTF-8 strings.<br />
]]<br />
function str.find( frame )<br />
local new_args = str._getParameters( frame.args, {'source', 'target', 'start', 'plain' } ); <br />
local source_str = new_args['source'] or '';<br />
local pattern = new_args['target'] or '';<br />
local start_pos = tonumber(new_args['start']) or 1;<br />
local plain = new_args['plain'] or true;<br />
<br />
if source_str == '' or pattern == '' then<br />
return 0;<br />
end <br />
<br />
plain = str._getBoolean( plain );<br />
<br />
local start = mw.ustring.find( source_str, pattern, start_pos, plain )<br />
if start == nil then<br />
start = 0<br />
end<br />
<br />
return start<br />
end<br />
<br />
--[[<br />
replace<br />
<br />
This function allows one to replace a target string or pattern within another<br />
string.<br />
<br />
Usage:<br />
{{#invoke:String|replace|source_str|pattern_string|replace_string|replacement_count|plain_flag}}<br />
OR<br />
{{#invoke:String|replace|source=source_string|pattern=pattern_string|replace=replace_string|<br />
count=replacement_count|plain=plain_flag}}<br />
<br />
Parameters<br />
source: The string to search<br />
pattern: The string or pattern to find within source<br />
replace: The replacement text<br />
count: The number of occurences to replace, defaults to all.<br />
plain: Boolean flag indicating that pattern should be understood as plain<br />
text and not as a Lua style regular expression, defaults to true <br />
]]<br />
function str.replace( frame )<br />
local new_args = str._getParameters( frame.args, {'source', 'pattern', 'replace', 'count', 'plain' } ); <br />
local source_str = new_args['source'] or '';<br />
local pattern = new_args['pattern'] or '';<br />
local replace = new_args['replace'] or '';<br />
local count = tonumber( new_args['count'] );<br />
local plain = new_args['plain'] or true;<br />
<br />
if source_str == '' or pattern == '' then<br />
return source_str;<br />
end <br />
plain = str._getBoolean( plain );<br />
<br />
if plain then<br />
pattern = str._escapePattern( pattern );<br />
replace = mw.ustring.gsub( replace, "%%", "%%%%" ); --Only need to escape replacement sequences.<br />
end<br />
<br />
local result;<br />
<br />
if count ~= nil then<br />
result = mw.ustring.gsub( source_str, pattern, replace, count );<br />
else<br />
result = mw.ustring.gsub( source_str, pattern, replace );<br />
end <br />
<br />
return result;<br />
end<br />
<br />
--[[ <br />
simple function to pipe string.rep to templates.<br />
]]<br />
<br />
function str.rep( frame )<br />
local repetitions = tonumber( frame.args[2] )<br />
if not repetitions then <br />
return str._error( 'function rep expects a number as second parameter, received "' .. ( frame.args[2] or '' ) .. '"' )<br />
end<br />
return string.rep( frame.args[1] or '', repetitions )<br />
end<br />
<br />
--[[<br />
Helper function that populates the argument list given that user may need to use a mix of<br />
named and unnamed parameters. This is relevant because named parameters are not<br />
identical to unnamed parameters due to string trimming, and when dealing with strings<br />
we sometimes want to either preserve or remove that whitespace depending on the application.<br />
]]<br />
function str._getParameters( frame_args, arg_list )<br />
local new_args = {};<br />
local index = 1;<br />
local value;<br />
<br />
for i,arg in ipairs( arg_list ) do<br />
value = frame_args[arg]<br />
if value == nil then<br />
value = frame_args[index];<br />
index = index + 1;<br />
end<br />
new_args[arg] = value;<br />
end<br />
<br />
return new_args;<br />
end <br />
<br />
--[[<br />
Helper function to handle error messages.<br />
]]<br />
function str._error( error_str )<br />
local frame = mw.getCurrentFrame();<br />
local error_category = frame.args.error_category or 'Errors reported by Module String';<br />
local ignore_errors = frame.args.ignore_errors or false;<br />
local no_category = frame.args.no_category or false;<br />
<br />
if str._getBoolean(ignore_errors) then<br />
return '';<br />
end<br />
<br />
local error_str = '<strong class="error">String Module Error: ' .. error_str .. '</strong>';<br />
if error_category ~= '' and not str._getBoolean( no_category ) then<br />
error_str = '[[Category:' .. error_category .. ']]' .. error_str;<br />
end <br />
<br />
return error_str;<br />
end<br />
<br />
--[[<br />
Helper Function to interpret boolean strings<br />
]]<br />
function str._getBoolean( boolean_str )<br />
local boolean_value;<br />
<br />
if type( boolean_str ) == 'string' then<br />
boolean_str = boolean_str:lower();<br />
if boolean_str == 'false' or boolean_str == 'no' or boolean_str == '0' <br />
or boolean_str == '' then<br />
boolean_value = false;<br />
else<br />
boolean_value = true;<br />
end <br />
elseif type( boolean_str ) == 'boolean' then<br />
boolean_value = boolean_str;<br />
else<br />
error( 'No boolean value found' );<br />
end <br />
return boolean_value<br />
end<br />
<br />
--[[<br />
Helper function that escapes all pattern characters so that they will be treated <br />
as plain text.<br />
]]<br />
function str._escapePattern( pattern_str )<br />
return mw.ustring.gsub( pattern_str, "([%(%)%.%%%+%-%*%?%[%^%$%]])", "%%%1" );<br />
end<br />
<br />
return str</div>
Max