Module:Str find word/sandbox/doc: Difference between revisions
Appearance
Content deleted Content added
No edit summary |
←Blanked the page Tag: Blanking |
||
Line 1: | Line 1: | ||
Str find word/sandbox/doc |
|||
{{sandbox other|1=|2={{Module rating|pre-alpha}}}} |
|||
:TOC: [[#code]] ({{edit|Module:Str find word/sandbox}}) |
|||
{{Module:Str find word/links/doc}} |
|||
{{Lua|Module:Yesno|Module:TableTools|Module:String}} |
|||
This module looks for a word being present in a comma-separated list of words. It then returns a {{code|True}} or {{code|False}} value. |
|||
By default, the True-value returned is the found word itself; the False-value is a blank string. Implements {{tl|Str find word}}. |
|||
For example, in the source string '{{mono|1=foo, bar}}' the word '{{mono|1=bar}}' appears, but the word '{{mono|1=november}}' does not. |
|||
:True: <code><nowiki>{{#invoke:Str find word|main |source=foo, bar|word=bar}}</nowiki></code> → >{{#invoke:Str find word|main |source=foo, bar|word=bar}}< |
|||
:False: <code><nowiki>{{#invoke:Str find word|main |source=alpha, beta, gamma|word=november}}</nowiki></code> → >{{#invoke:Str find word|main |source=alpha, beta, gamma|word=november}}< |
|||
Complete words: the complete word is '{{mono|1=foobar}}' ... example needed ... |
|||
''Multiple word check'': The search can be extended to check for multiple words being present. |
|||
''AND''-list of words, all words must be present: |
|||
:True: <code><nowiki>{{#invoke:Str find word|main |source=alpha, beta, gamma|andwords=beta, alpha}}</nowiki></code> → >{{#invoke:Str find word|main |source=alpha, beta, gamma|andwords=beta, alpha}}< |
|||
:False: <code><nowiki>{{#invoke:Str find word|main |source=alpha, beta, gamma|andwords=beta, omega}}</nowiki></code> → >{{#invoke:Str find word|main |source=alpha, beta, gamma|andwords=beta, omega}}< |
|||
''OR''-list of words, at least one off the words must be present: |
|||
:True: <code><nowiki>{{#invoke:Str find word|main |source=alpha, beta, gamma|orwords=beta, alpha}}</nowiki></code> → >{{#invoke:Str find word|main |source=alpha, beta, gamma|orwords=beta, alpha}}< |
|||
:False: <code><nowiki>{{#invoke:Str find word|main |source=alpha, beta, gamma|orwords=beta, omega}}</nowiki></code> → >{{#invoke:Str find word|main |source=alpha, beta, gamma|orwords=beta, omega}}< |
|||
The module is aimed at template code usage. <small>(The editor does not have to apply Lua patterns like {{code|1=[%a%d]*}})</small>. |
|||
==Parameters== |
|||
:All parameters (synonyms) |
|||
{| |
|||
|- |
|||
|<pre> |
|||
{{Str find word |
|||
|string = |
|||
|word = |
|||
|orwords = |
|||
|case= |
|||
|yes = |
|||
|no = |
|||
|explain = |
|||
}} |
|||
</pre> |
|||
|<pre> |
|||
{{Str find word |
|||
|s = |
|||
|w = |
|||
|orw = |
|||
|case= |
|||
|yes = |
|||
|no = |
|||
|explain = |
|||
}} |
|||
</pre> |
|||
|<pre> |
|||
{{Str find word |
|||
|s= source= |
|||
|word= andwords= andw= |
|||
|orwords= orw= |
|||
|case= |
|||
|yes= |
|||
|no= |
|||
|explain= |
|||
<!-- |sep=todo --> |
|||
}} |
|||
</pre> |
|||
|} |
|||
<pre>{{Str find word |s= |w= |andw= |orw= |case= |yes= |no= |explain=}}</pre> |
|||
===Basic: source, word=== |
|||
<pre> |
|||
{{Str find word |
|||
|source = |
|||
|word = |
|||
}} |
|||
</pre> |
|||
:When the ''word'' is found in the ''source'' (True), the function returns the ''word'' itself (by default), or {{para|yes}} value (when entered non-empty). |
|||
:When not found (False), the function returns a empty string ({{code|''}}), or the {{para|no}} value when entered. |
|||
{| class="wikitable" |
|||
|- |
|||
| {{para|1=source|2=alpha, foo, lima}} |
|||
| {{para|word|foo}} |
|||
| {{#invoke:Str find word|main |explain=true |source=alpha, foo, lima|word=foo}} |
|||
| {{aye}} |
|||
| |
|||
|- |
|||
| {{para|1=source|2=alpha, foo, lima}} |
|||
| {{para|word|bar}} |
|||
| {{#invoke:Str find word|main |explain=true |source=alpha, foo, lima|word=foo-bar}} |
|||
| {{nay}} |
|||
| full word ''bar'' not in the source |
|||
|- |
|||
| {{para|1=source|2=alpha, foo, lima}} |
|||
| {{para|word|foobar}} |
|||
| {{#invoke:Str find word|main |explain=true |source=alpha, foo, lima}} |
|||
| {{nay}} |
|||
| word ''foobar'' not in the source as full word |
|||
|} |
|||
===Case, Literal, === |
|||
: todo: examplify |
|||
{| class="wikitable" style="" |
|||
|- |
|||
! {{para|1=source}}<br/> {{para|1=s}} |
|||
! {{para|1=word}}<br/>{{para|1=w}} |
|||
! {{para|1=case}} |
|||
! result |
|||
! note |
|||
|- |
|||
| {{para|1=s|2=alpha, foo, lima}} |
|||
| {{para|w|foo}} |
|||
| |
|||
| → {{#invoke:Str find word|main |explain=true |s=alpha, foo, lima|w=foo|yes=yes|no=no}} |
|||
| |
|||
|- |
|||
| {{para|1=s|2=alpha, foo, lima}} |
|||
| {{para|w|foobar}} |
|||
| |
|||
| → {{#invoke:Str find word|main |explain=true |source=alpha, foo, lima|word=foobar|yes=yes|no=no}} |
|||
| |
|||
|- |
|||
| {{para|1=s|2=alpha, foobar, lima}} |
|||
| {{para|w|foo}} |
|||
| |
|||
| → {{#invoke:Str find word|main |explain=true |source=alpha, foobar, lima|word=foo|yes=yes|no=no}} |
|||
| 'foo' is not the complete word |
|||
|- |
|||
| {{para|1=s|2=alpha, FOO, lima}} |
|||
| {{para|w|foo}} |
|||
| |
|||
| → {{#invoke:Str find word|main |explain=true |source=alpha, FOO, lima|word=foo|yes=yes|no=no|case=false}} |
|||
| {{para|case|false}}: a=A ''(default)'' |
|||
|- |
|||
| {{para|1=s|2=alpha, FOO, lima}} |
|||
| {{para|w|foo}} |
|||
| |
|||
| → {{#invoke:Str find word|main |explain=true |source=alpha, FOO, lima|word=foo|yes=yes|no=no|case=true}} |
|||
| {{para|case|true}}: a=/=A |
|||
|} |
|||
===AND-, OR-wordlist checks=== |
|||
:{{para|word}} as noted, can be a ''list of words''. All will be checked with the ''AND''-requirement (each word must be present). |
|||
:{{para|andwords}} accepts a ''list of words'' that all will be checked with the ''AND''-requirement (each word must be present). |
|||
::When both {{para|word}}, {{para|andwords}} are present, they are combined into one single ''AND''-wordlist. |
|||
:{{para|orwords}} accepts a ''list of words'' that all will be checked with the ''OR''-requirement (at least one of the words must be present). |
|||
{| class="wikitable" style="" |
|||
|- |
|||
! {{para|1=source}}<br/>{{para|1=s}} |
|||
! {{para|1=andwords}}, {{para|1=andw}}<br/>{{para|1=word}}<br/>{{para|1=w}} |
|||
! {{para|1=orwords}}<br/>{{para|1=orw}} |
|||
! result TODO fix |
|||
! note |
|||
|- |
|||
| {{para|1=s|2=alpha, foo, lima, delta}} |
|||
| {{para|andw|delta, lima}} |
|||
| |
|||
| {{#invoke:Str find word|main |explain=true |s=alpha, foo, lima, delta|andw=delta, lima}} |
|||
| both words present in the source |
|||
|- |
|||
| {{para|1=s|2=alpha, foo, lima, delta}} |
|||
| {{para|andw|foo, nov}} |
|||
| |
|||
| {{#invoke:Str find word|main |explain=true |s=alpha, foo, lima, delta}} |
|||
| AND-logic: A word in the ''AND''-list is not present ({{mono|nov}}), so false |
|||
|- |
|||
| {{para|1=s|2=alpha, foo, lima, delta}} |
|||
| {{para|andw|delta}} |
|||
| |
|||
| {{#invoke:Str find word|main |explain=true |s=alpha, foo, lima, delta|andw=delta}} |
|||
| {{para|w}} and {{para|andw}} are combined |
|||
|- |
|||
| {{para|1=s|2=alpha, foo, lima, delta}} |
|||
| |
|||
| {{para|orw|delta, lima}} |
|||
| {{#invoke:Str find word|main |explain=true |s=alpha, foo, lima, delta|orw=delta, lima}} |
|||
| both OR-words are present in the source |
|||
|- |
|||
| {{para|1=s|2=alpha, foo, lima, delta}} |
|||
| |
|||
| |
|||
| {{#invoke:Str find word|main |explain=true |s=alpha, foo, lima, delta|orw=foo, nov}} |
|||
| OR-logic: one of the words is present ({{para|foo}}), so true |
|||
|- |
|||
| {{para|1=s|2=alpha, foo, lima, delta}} |
|||
| {{para|andw|alpha, lima}} |
|||
| {{para|orw|foo, nov}} |
|||
| {{#invoke:Str find word|main |explain=true |s=alpha, foo, lima, delta|andw=alpha, lima|orw=foo, nov}} |
|||
| |
|||
|- |
|||
| {{para|1=s|2=alpha, foo, lima, delta}} |
|||
| {{para|andw|bar, april}} |
|||
| {{para|orw|nov, dec}} |
|||
| {{#invoke:Str find word|main |explain=true |s=alpha, foo, lima, delta|andw=delta|orw=nov, dec}} |
|||
| none of the OR-words is present, so false |
|||
|} |
|||
===True, False rephrase options {{para|yes, no}}=== |
|||
{| class="wikitable" |
|||
|- |
|||
! colspan="5" style="padding-left:3em; text-align:left;" | {{code|1=...}} {{para|yes|Yes, hit}} {{para|no|Not found}} |
|||
|- |
|||
| {{para|1=source|2=alpha, foo, lima}} |
|||
| {{para|word|foo}} |
|||
| {{#invoke:Str find word|main |explain=true |source=alpha, foo, lima|word=foo|yes=Yes, hit|no=No, not found}} |
|||
| {{aye}} |
|||
|- |
|||
| {{para|1=source|2=alpha, foo, lima}} |
|||
| {{para|word|foobar}} |
|||
| {{#invoke:Str find word|main |explain=true |source=alpha, foo, lima|word=foobar|yes=Yes, hit|no=No, not found}} |
|||
| {{nay}} |
|||
|} |
|||
===Edge cases: (blank input,) === |
|||
:''todo'' |
|||
==issues and ideas== |
|||
* Keep the order, Foo, bar -> foo(1), bar(2) |
|||
::eg table col userinput options, then cols in that order? |
|||
* Check comma example above ({{code|1="Hello, world"}}) (currently returns: 2 hitwords & sep=comma Dec2022) |
|||
*Make sure all boolean logic is by [[:Module:Yesno]] |
|||
:''and'' resolve {{code|nil}} |
|||
*option {{para|sep}} for output list >, < dflt |
|||
* allow pattern input = recognise ({{code|150%, 175%, ..}}) so patterns again ;-) |
|||
* ignore characters eg "/"? |
|||
* cleanup (RLM), stated: named params only (wrt WS) |
|||
* option add prefix, suffix -- when success only |
|||
* list presentation.. |
|||
==Errors and analysis== |
|||
* The logic itself does not produce errors. There is always a True of False result. |
|||
* Pages with Unknown parameters are listed in {{clc|Category:Pages using str find word with unknown parameters}}. |
|||
:There are no logical errors foreseen: any flaw in the input will return a False result (for example, no input strings to check were entered). |
|||
* {{para|explain|true}}: when in {{button|Preview}}, display a report on input, output and the logical steps (debug). |
|||
* {{para|explain|testcases}}: When set in ns {{mono|1=Template}} or {{mono|1=User}} on subpage {{mono|1=/testcases}}, the Preview report is static (shown permanently). |
|||
===code=== |
|||
<includeonly>{{sandbox other|| |
|||
[[:Category:Modules that manipulate strings]] |
|||
}}</includeonly> |