Module:Str find word/doc: Difference between revisions

Content deleted Content added
...
 
(97 intermediate revisions by 2 users not shown)
Line 1:
{{Lua|Module:String|Module:TableTools|Module:Yesno}}
:TOC: [[#code]] ({{edit|Module:Str find word}})
Implements template '''{{Module:tl|Str find word/links/doc}}'''.
 
{{Module rating|pre-alpha}}
This module looks for a word being present in a comma-separated list of words. It then returns a {{code|1=True}} or {{code|1=False}} value. By default, the True-value returned is the found word itself; the False-value is a blank string.
{{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> <small>({{code|1=True}})</small> &rarr; >{{#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> <small>({{code|1=False}})</small> &rarr; >{{#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> <small>({{code|1=True}})</small> &rarr; >{{#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> <small>({{code|1=False}})</small> &rarr; >{{#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> <small>({{code|1=True}})</small> &rarr; >{{#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> <small>({{code|1=False}})</small> &rarr; >{{#invoke:Str find word |main |source=alpha, beta, gamma |orwords=beta, omega}}<
 
Complete words: the complete word is '{{mono|1=foobar}}' (example needed)
Whitespace is trimmed,
 
The module is aimed at template code usage. <small>(The editor does not have to apply Lua patterns like {{code|1=[%a%d]*}})</small>.
}}
== Usage ==
:{{red|This documentation is not up to date}}. See template {{tl|Str find word}}.
 
==Parameters==
:AllMain parameters (including their synonyms)
{|
|-
|<pre>
{{Str find word
|string source= s=
|word= andwords= andw=
|orwords= orw=
|case=
|out-true=
|yes =
|out-false=
|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= |yesout-true= |no= |explainout-false=}}</pre>
 
===Basic: source, ''word'' is in ''source-wordlist''?===
<pre>
{{Str find word
Line 74 ⟶ 46:
}}
</pre>
:<code><nowiki>{{Str find word |source=cow, horse, dog, fish |word=dog}}</nowiki></code> <small>({{code|1=True}})</small> &rarr; {{Str find word |source=cow, horse, dog, fish |word=dog}}
:<code><nowiki>{{Str find word |source=cow, horse, dog, fish |word=cat}}</nowiki></code> <small>({{code|1=False}})</small> &rarr; {{Str find word |source=cow, horse, dog, fish |word=cat}}
 
 
: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).
===True/False return value===
:When not found (False), the function returns a empty string ({{code|''}}), or the {{para|no}} value when entered.
:When the ''word'' is found in the ''source'' (True), the function returns the ''word'' itself (by default), or {{para|out-true}} value (when entered non-empty).
:When not found (False), the function returns a empty string ({{code|''}}), or the {{para|out-false}} value when entered.
 
{| class="wikitable"
Line 82 ⟶ 58:
| {{para|1=source|2=alpha, foo, lima}}
| {{para|word|foo}}
| {{#invoke:Str find word |main |explain=true |source=alpha, foo, lima |word=foo}}
| {{aye}}
|
Line 88 ⟶ 64:
| {{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
Line 94 ⟶ 70:
| {{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,AND-wordlist checks===
:{{para|word}} can be a ''list of words''. All will be checked with the ''AND''-requirement (each word must be present).
: todo: examplify
:{{para |andwords}} accepts a ''list of words'' that all will be checked with the ''AND''-requirement (each word must be present).
:Alway, ''both'' {{para|word}} and {{para |andwords}} are combined into one single ''AND''-wordlist.
 
{| class="wikitable" style=""
|-
! {{para|1=source}}<br/> {{para|1=s}}
! {{para|1=wordandwords}}<br/>{{para|1=wword}}
! result
! {{para|1=case}}
! result
! note
|-
| {{para|1=s|2=alpha, foo, lima, delta}}
| {{para |wandw|foodelta, 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 |andw|bar, april}}
| {{#invoke:Str find word |main |explain=true |s=alpha, foo, lima, delta |andw=delta}}
|
|}
| &rarr; {{#invoke:Str find word|main |explain=true |s=alpha, foo, lima|w=foo|yes=yes|no=no}}
 
|
===OR-wordlist checks===
;{{para |orwords}}, {{para |orw}}
:Accepts a ''list of words'' that all will be checked by the ''OR-requirement'' ("at least one of the words must be present).
 
{| class="wikitable" style=""
|-
|! {{para|1=ssource}}<br/>{{para|21=alpha, foo, limas}}
!
| {{para|w|foobar}}
! {{para|1=orwords}}
! result
! note
|-
| {{para|1=s|2=alpha, foo, lima, delta}}
|
|
| &rarr; {{#invoke:Str find word|main |explain=true |source=alpha, foo, lima|word=foobar|yes=yes|no=no}}
| {{#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, foobarfoo, lima, delta}}
|
| {{para|w|foo}}
|
| {{#invoke:Str find word |main |explain=true |s=alpha, foo, lima, delta}}
|
| &rarr; {{#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, FOOfoo, lima, delta}}
| {{para |wandw|foodelta}}
|
| &rarr; {{#invoke:Str find word |main |explain=true |sources=alpha, FOOfoo, lima, delta |word=foo|yes=yes|no=no|caseandw=falsedelta}}
| {{para|casew}} and {{para |falseandw}}: a=Aare ''(default)''combined
|-
| {{para|1=s|2=alpha, FOOfoo, lima, delta}}
| {{para|w|foo}}
|
| {{para |orw|delta, lima}}
| &rarr; {{#invoke:Str find word|main |explain=true |source=alpha, FOO, lima|word=foo|yes=yes|no=no|case=true}}
| {{#invoke:Str find word |main |explain=true |s=alpha, foo, lima, delta |orw=delta, lima}}
| {{para|case|true}}: a=/=A
| 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
|}
 
===both AND-,words and OR-wordlistwords to checkscheck===
;{{para |andwords}} {{para |orwords}}
:{{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 achecks ''listboth'' oflists for their own check: "ANd-words''" thatmust all will be checkedpresent, with"OR-words" themust ''AND''-requirementhave (eachat wordleast must beone present).
:Result: True if both check results are True, otherwise False.
::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=worwords}}
! result
! {{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
|-
Line 182 ⟶ 203:
|
|
| {{#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
|}
 
===Edge cases ===
===True, False rephrase options {{para|yes, no}}===
;Blank list(s)
:Empty input string(s) will conclude negative:
{| class="wikitable"
|-
! colspan="5" style="padding-left:3em; text-align:left;" | {{codepara|1=...}}source, {{para|yes|Yesandwords, hit}} {{paraorwords|no|Not found2=&lt;blank>}}
|-
| {{para|1=source|2=&lt;blank>}}
| {{para|word|beta}}
| {{#invoke:Str find word |main |source= |word=beta}}
| {{nay}}
|-
| {{para|1=source|2=alpha, beta, gamma}}
| {{para|word|&lt;blank>}}
| {{#invoke:Str find word |main |alpha, beta, gamma |word=}}
| {{nay}}
|}
<noinclude>
==untested; noinclude from main /doc==
:As of Mar 2023, not supported.
===casesensitive ===
:{{para|casesensitive|true}}, {{para|case|true}} Case-sensistive (A=/=a) DEFAULT
:{{para|casesensitive|false}}, {{para|case|false}} Not case-sensistive (A=a)
 
{| 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}}
|
| &rarr; {{#invoke:Str find word |main |explain=true |s=alpha, foo, lima|w=foo|out-true=yes|out-false=no}}
|
|-
| {{para|1=s|2=alpha, foo, lima}}
| {{para|w|foobar}}
|
| &rarr; {{#invoke:Str find word |main |explain=true |source=alpha, foo, lima |word=foobar|out-true=yes|out-false=no}}
|
|-
| {{para|1=s|2=alpha, foobar, lima}}
| {{para|w|foo}}
|
| &rarr; {{#invoke:Str find word |main |explain=true |source=alpha, foobar, lima |word=foo|out-true=yes|out-false=no}}
| 'foo' is not the complete word
|-
| {{para|1=s|2=alpha, FOO, lima}}
| {{para|w|foo}}
|
| &rarr; {{#invoke:Str find word |main |explain=true |source=alpha, FOO, lima |word=foo|out-true=yes|out-false=no|case=false}}
| {{para|case|false}}: a=A ''(default)''
|-
| {{para|1=s|2=alpha, FOO, lima}}
| {{para|w|foo}}
|
| &rarr; {{#invoke:Str find word |main |explain=true |source=alpha, FOO, lima |word=foo|out-true=yes|out-false=no|case=true}}
| {{para|case|true}}: a=/=A
|}
 
===Rephrase True, False result: {{para|1=out-true=, out-false|2=}}===
{| class="wikitable"
|-
! colspan="5" style="padding-left:3em; text-align:left;" | {{para|out-true|out-true, a hit}}<br/>{{para|out-false|out-falset found}}
|-
| {{para|1=source|2=alpha, foo, lima}}
| {{para|word|foo}}
| {{#invoke:Str find word |main |explain=true |source=alpha, foo, lima |word=foo|yesout-true=Yes, a hit|noout-false=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|yesout-true=Yes, a hit|noout-false=No, not found}}
| {{nay}}
|}
 
===boolean words===
===Edge cases: (blank input,) ===
;{{para|booleans}}
:''todo''
:{{para|booleans|true}} will convert ''all boolean words'' into "True/False".
:per [[:module:Yesno]] ({{code|1=Yes, true, yes, 1}} = true) (todo: document value 2?, nil, blanketc. Irrespective of case?)
:other words not changed ("horse" remains horse, not T/F).
:Note: per logic definition, the ''word'' "false" is returned (as being found).
 
{| class="wikitable"
==issues and ideas==
|-
* Keep the order, Foo, bar -> foo(1), bar(2)
! colspan="5" style="padding-left:3em; text-align:left;" | {{para|1=booleans|2=true}}
::eg table col userinput options, then cols in that order?
|-
 
| {{para|1=source|2=YeS}}
* Check comma example above ({{code|1="Hello, world"}}) (currently returns: 2 hitwords & sep=comma Dec2022)
| {{para|1=word|2=true}}
 
| {{#invoke:Str find word |main |booleans=true |source=YeS |word=1}}
*Make sure all boolean logic is by [[:Module:Yesno]]
|
:''and'' resolve {{code|nil}}
|-
| {{para|1=source|2=0}}
| {{para|1=word|2=FalSe}}
| {{#invoke:Str find word |main |booleans=true |source=0 |word=FalSe}}
| ''note:'' the ''word'' "false" is found and returned
|}
 
===quotes, escape===
*option {{para|sep}} for output list >,&nbsp;< dflt
:under construction
 
===synonyms===
* allow pattern input = recognise ({{code|150%, 175%, ..}}) so patterns again ;-)
:under construction
* ignore characters "/"?
</noinclude>
 
==Errors and analysis==
Line 240 ⟶ 336:
* {{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).
{{String-handling templates|state=collapsed}}
===code===
<includeonly>{{sandbox other||
[[:Category:Modules that manipulate strings]]