Module:Str find word/doc: Difference between revisions

Content deleted Content added
...
 
(178 intermediate revisions by 2 users not shown)
Line 1:
{{Lua|Module:String|Module:TableTools|Module:Yesno}}
{{Module:User:DePiep/sfw/links/doc}}
Implements template '''{{tl|Str find word}}'''.
===prev===
*xp-dflt: {{#invoke:User:DePiep/sfw|main |explain=false|s=alpha$, Foo @, bar, Z|andw=bar}}
*xp-t: {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha$, Foo @, bar, Z|andw=bar}}
*xp-f: {{#invoke:User:DePiep/sfw|main |explain=false|s=alpha$, Foo @, bar, Z|andw=bar}}
 
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.
__TOC__
 
For example, in the source string '{{mono|1=foo, bar}}' the word '{{mono|1=bar}}' appears, but the word '{{mono|1=november}}' does not.
===show 2===
:<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}}
*{{#invoke:User:DePiep/sfw|main |explain=true |s=alpha$, Foo @, "(12)A", bar, yoo |orw="(12)A", Z|andw=bar}}
:<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}}
 
''Multiple word check'': The search can be extended to check for multiple words being present.
*{{#invoke:User:DePiep/sfw|main |explain=true |s=alpha$, Foo @, "(12)A", "Hello, worlds", bar(12), yoo |orw="(12)A", " Hello, worlds "|andw=" bar ", "Foo" bar(12);zop}}
 
''AND''-list of words, all words must be present:
*lit-dflt: {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, Foo %$, "(12)A", bar(12)|orw="(12)A", Z|andw=" bar ", "Foo", bar(12), zop}}
:<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}}
:<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:
*lit-blank: {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, Foo %$, "(12)A", bar(12)|orw="(12)A", Z|andw=" bar ", "Foo", bar(12), zop|lit=}}
:<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}}
:<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)
*{{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, Foo, "(12)A", bar|orw="(12)A", Z|andw=" bar ", "Foo"|lit=true}}
Whitespace is trimmed,
*{{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, Foo, "(12)A", bar|orw="()=^%|andw=}}
 
The module is aimed at template code usage. <small>(The editor does not have to apply Lua patterns like {{code|1=[%a%d]*}})</small>.
*sp {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, Foo, "(12) A", bar|orw="(12)&nbsp; A", Z|andw=" bar ", "Foo"|lit=true}}
}}
==Parameters==
:Main parameters (including their synonyms)
{|
|<pre>
{{Str find word
|source= s=
|word= andwords= andw=
|orwords= orw=
|case=
|out-true=
|out-false=
}}
</pre>
|}
<pre>{{Str find word |s= |w= |andw= |orw= |case= |out-true= |out-false=}}</pre>
 
===Basic: ''word'' is in ''source-wordlist''?===
 
*litF/use": {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha$, Foo @, "(12)"A", bar("12"), yoo |orw="(12)A", Z|andw=" bar ", "Foo" bar("12"), zop|lit=false}}
 
*litT: {{#invoke:User:DePiep/sfw|main |explain=true |s="alpha$", "Foo @",,,, "(12)A", "bar(12)", "yoo,." |orw="(12)A", Z|andw=" bar ",,, "Foo" "bar(12)", "zop"|lit=true}}
 
===basic===
*{{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, Foo, "(12)A", bar|orw="(12)A", Z|andw=" bar ", "Foo"|lit=true|bool=true}}
*T: {{#invoke:User:DePiep/sfw|main|explain=true |s=alpha|w=alpha}}
*allup T: {{#invoke:User:DePiep/sfw|main|explain=true |s=alpha, foo, "A(12) $!" true, Z|w=alpha|andw=Z, "A(12) $!", |orw= Z, nov}}
 
===yes options===
*dflt T: {{#invoke:User:DePiep/sfw|main |explain=true |s=bar, foo Z|orw=foo}}
*dflt F: {{#invoke:User:DePiep/sfw|main |explain=true |s=bar, foo Z|orw=nov|no=Nooo}}
*yes. T: {{#invoke:User:DePiep/sfw|main |explain=true |s=bar, foo Z|orw=foo|yes=}}
*yes.Yss T: {{#invoke:User:DePiep/sfw|main |explain=true |s=bar, foo Z|orw=foo|yes=Yess}}
;===lit check===
*lit.t: {{#invoke:User:DePiep/sfw|main |explain=true |s="(12) A?", foo Z|orw="(12) A?", Z|lit=true}}
 
*lit.t, loopcheck3x: {{#invoke:User:DePiep/sfw|main |explain=true |s="(12) A?", foo, "de ux", Z, " drei "|orw="(12) A?"" drei " ,"de ux", |lit=true}}
*lit.t, loopcheck3x: {{#invoke:User:DePiep/sfw|main |explain=true |s="(12) A?", foo, "de ux", Z, " drei "|orw="(12) A?"" drei " ,"de ux", |lit=false}}
 
 
*lit.dflt: {{#invoke:User:DePiep/sfw|main |explain=true |s="(12) A?"|orw=bar, "(12) A?" }}
*lit.T: {{#invoke:User:DePiep/sfw|main |explain=true |s="(12) A?"|orw=bar, "(12) A?" |lit=T}}
*lit.F: {{#invoke:User:DePiep/sfw|main |explain=true |s="(12) A?"|orw=bar, "(12) A?" |lit=F}}
:multi
*lit.dflt: {{#invoke:User:DePiep/sfw|main |explain=true |s="(12) A?", foo, "deux", Z, "drei"|orw="(12) A?""drei" ,"deux", }}
:spaces
*lit.T: {{#invoke:User:DePiep/sfw|main |explain=true |s="(12) A?", foo, "deux", Z, "drei", "" NOSP|orw="(12) A?" " drei " ," " HASSP|lit=T}}
 
{{anchor|toc}}{{slink||top}}
__TOC__
 
==demos==
====literals====
:demos & tests to be oimproved
* T lit: {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, "(12) A?", lima, bar|word=bar, "(12) A?" }}
* T 2lt, ws: {{#invoke:User:DePiep/sfw|main |explain=true |s="(12) A?", lima, "deux", "nov"|orwords="(12) A?", "deux", "paris" }}
* T 2lt, ws: {{#invoke:User:DePiep/sfw|main |explain=true |s="(12) A?", lima, "deux", nov|word=deux, "(12) A?", }}
* T 2lt, ws: {{#invoke:User:DePiep/sfw|main |explain=true |s="(12) A?", lima, "deux", nov|word=deux, "(12) A?", |lit=true}}
 
:litdflt, t, f
* T lit=F: {{#invoke:User:DePiep/sfw|main |explain=true |s="(12) A?", lima, "deux", nov|word=deux, "(12) A?", |lit=false}}
* T lit=F: {{#invoke:User:DePiep/sfw|main |explain=true |s="(12) A?", lima, "deux", nov|word=deux, "(12) A?", |lit=false}}
* T lit=F: {{#invoke:User:DePiep/sfw|main |explain=true |s="(12) A?", lima, "deux", nov|word=deux, "(12) A?", |lit=false}}
* T lit=F: {{#invoke:User:DePiep/sfw|main |explain=true |s="(12) A?", lima, "deux", nov|word=deux, "(12) A?", |lit=false}}
 
* T lit, ws!: {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, " (12) A? ", lima,|word=foo, " (12) A? " }}
* F lit, ws!: {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, " (12) A? ", lima,|word=foo, "(12) A?" }}
 
* T lit, ws!: {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, " (12) A? ", lima,|word=foo, " (12) A? " }}
* F lit, ws!: {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, " (12) A? ", lima,|word=foo, "(12) A?" }}
 
 
:edge
* ? lit edge, ws: {{#invoke:User:DePiep/sfw|main |explain=true |s="(12) A?", lima, " ", nov|word="lima", nov , " ", }}
* ? lit edge, ws: {{#invoke:User:DePiep/sfw|main |explain=true |s="(12) A?", lima, "", nov|word=nov, "(12) A?", ""}}
* ? lit edge, ws: {{#invoke:User:DePiep/sfw|main |explain=true |s="(12) A?", lima, ", nov|word=nov, "(12) A?", }}
 
* F lit: {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, "(12) A?", foo, lima, bar|word=12}}
* test lit: {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha"(12) A?"foo, lima, bar|orw=12, foo}}
 
:minor checks
* F lit: {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha; foo, "lima", bar|orw=12, lima}}
* F lit: {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha"(12) A?"foo, "lima", bar|orw=12, lima}}
* F lit: {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha"(12) A?"foo, "lima", bar|andw=lima, "(12) A?"}}
 
====bool====
* T boolT: {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, 1, foo, lima, bar|word=foo, true |bool=true}}
* F boolF: {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, 1, foo, lima, bar|word=foo, true |bool=false}}
* F bool: {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, foo, lima, bar|word=november|bool=true}}
 
* T: {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, foo, lima, bar|word=foo}}
* F: {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, foo, lima, bar|word=november}}
 
:bool check case
* T boolT: {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, 1, foo, lima, bar|word=foo, true |bool=true|case=true}}
* F boolF: {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, 1, foo, lima, bar|word=foo, true |bool=false|case=false}}
 
* T boolT: {{#invoke:User:DePiep/sfw|main |explain=true |s=Alpha, 1, Foo, Lima, Bar|word=Foo, true |bool=true|case=true}}
* F boolF: {{#invoke:User:DePiep/sfw|main |explain=true |s=Alpha, 1, Foo, Lima, Bar|word=foo, true |bool=false|case=false}}
 
====basic tests====
* T: {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, foo, lima, bar|word=foo}}
* F: {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, foo, lima, bar|word=november}}
 
* T and: {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, foo, lima, bar|andwords=foo, bar}}
* T or: {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, foo, lima, bar|orwords=foo, bar}}
* T andor: {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, foo, lima, bar|andwords=foo, bar|orwords=nov, alpha}}
* F andor: {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, foo, lima, bar|andwords=foo, bar|orwords=nov, dec}}
* F andor: {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, foo, lima, bar|andwords=foo, nov|orwords=bar, dec}}
 
* T case: {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, Foo, |word=FOO|case=true}}
* F blanks: {{#invoke:User:DePiep/sfw|main |explain=true |s=|word=}}
 
* T yn: {{#invoke:User:DePiep/sfw|main |explain=true |s=foo, bar|word=bar|yes=Yessss|no=Noooo}}
* F yn: {{#invoke:User:DePiep/sfw|main |explain=true |s=foo, bar|word=nov|yes=Yessss|no=Noooo}}
 
*{{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, foo, lima, bar|andw=foo}}
*{{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, foo, lima, bar|andw=foo, nov}}
*{{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, foo, lima ,bar |orw=alpha, nov}}
*{{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, foo, lima,bar|andw=delta, lima |orw=bar, nov}}
*{{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, foo, lima,bar|andw=delta, lima |orw=oct, nov}}
*{{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, foo, lima,bar|orw=lima alpha}}
 
====yes no options====
*{{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, foo, lima, bar|w=foo|yes=yes|no=no}}
*{{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, foo, lima, bar|w=nov|yes=yes|no=noooo}}
*{{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, foo, lima, bar|w=nov|yes={{lorem ipsum}}|no=nooo}}
*{{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, foo, lima,bar|andw=foo|orw=|yes=|no=noooo}}
 
====yes/no=<blank> ====
*b: {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, foo, lima, bar|andw=foo|yes=}}
*bb: {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, foo, lima, bar|andw=foo|yes=|no=}}
*bnoval: {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, foo, lima, bar|andw=foo|yes=|no=}}
*abst: {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, foo, lima, bar|andw=foo|no=}}
* T: {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, foo, lima, bar|andw=foo|yes=Yess}}
*bT: {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, foo, lima, bar|andw=foo|yes=|no=nonono}}
* F ynblank: {{#invoke:User:DePiep/sfw|main |explain=true |s=foo, bar|word=bar|yes=|no=}}
 
====unicode html decode====
* T: {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, foo, lima, bar|andw=foo}}
* T: {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, &#x0046;oo, lima, bar|andw=foo}}
* T: {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, foo, lima, bar|w=&#x0066;oo}}
* T: {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, &#x0066;oo, lima, bar|w=&#x0046;oo|case=false}}
* f: {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, &#x0066;oo, lima, bar|w=&#x0046;oo|case=true}}
 
====case====
*dflt: {{#invoke:User:DePiep/sfw|main |explain=true |s=FOO, bar|w=foo}}
*dflt: {{#invoke:User:DePiep/sfw|main |explain=true |s=foo, bar|w=fOo}}
*cF:dflt {{#invoke:User:DePiep/sfw|main |explain=true |s=foo, Bar|w=fOo|orw=bAr|case=false}}
*cT:dflt {{#invoke:User:DePiep/sfw|main |explain=true |s=foo, Bar|w=fOo|orw=bAr|case=true}}
 
====file & table output====
*{{#invoke:User:DePiep/sfw|main |explain=true |s=foo, bar|w=foo|yes={{lorem ipsum}}}}
*{{#invoke:User:DePiep/sfw|main |explain=true |s=foo, bar|w=foo|yes=[[File:example.png]]}}
*{{#invoke:User:DePiep/sfw|main |explain=true |s=sbar|w=sbar|yes={{Periodic table (micro)}}}}
*{{#invoke:User:DePiep/sfw|main |explain=true |s=|w=}}
*{{#invoke:User:DePiep/sfw|main |explain=true |s=|andw=|yes=Y|no=N}}
*{{#invoke:User:DePiep/sfw|main |explain=true |s=;;|andw=;;|orw=}}
 
====nowords input====
*{{#invoke:User:DePiep/sfw|main |explain=true |s=|w=foo}}
*{{#invoke:User:DePiep/sfw|main |explain=true |s=sbar|w=}}
*{{#invoke:User:DePiep/sfw|main |explain=true |s=|w=}}
*{{#invoke:User:DePiep/sfw|main |explain=true |s=|andw=|yes=Y|no=N}}
*{{#invoke:User:DePiep/sfw|main |explain=true |s=;;|andw=;;""," "|orw=}}
 
==/doc==
{{Module rating|pre-alpha}}
:[[:Module:check for unknown parameters]]<!-- {{#invoke:check for unknown parameters|check
|unknown=[[Category:Some tracking category]]
|arg1|arg2|arg3|argN}} -->
This module is intended to find ''complete words'' in a string. It returns a True or False value, which can be used accordingly. For example, in the string '{{mono|1=alpha, foobar}}' the word '{{mono|1=alpha}}' appears, but the word '{{mono|1=foo}}' does not: there only is the complete word '{{mono|1=foobar}}'. The module is aimed at template code usage. <small>(The editor does not have to apply Lua patterns like {{code|1=[%a%d]*}})</small>.
 
A '''word''' is defined to be only of these characters: alphanumerics ('{{mono|1=a-z A-Z 0-9}}'), hyphen ('{{mono|1=-}}') and underscore ('{{mono|1=_}}'){{nbsp|1}}{{aye|12px}}. All other characters are non-word characters, and so possible word-separators (like {{nowrap|1='{{mono|1=;,()&lt;space&gt;}}'}}{{nbsp}}{{nay|12px}}).
 
:Word examples ''todo check+good examples''
:{{mono|1=foo, foobar, foo-bar foo_bar#)($foo123{{nbsp|3}}Foo. FOO..._foo] 12, -x, zob(28)}}
:{{mono|1={{bg|yellow|foo}}, {{bg|yellow|foobar}}, {{bg|yellow|foo-bar}} {{bg|yellow|foo_bar}}#)(${{bg|yellow|foo123}}{{nbsp|3}}{{bg|yellow|Foo}}. {{bg|yellow|FOO}}...{{bg|yellow|_foo}}] [{{bg|yellow|12}}, {{bg|yellow|-x}}}}
:{{mono|1=foo{{bg|orange|, }}foobar{{bg|orange|, }}foo-bar{{bg|orange| }}foo_bar{{bg|1=orange|2=#)($}}foo123{{bg|1=orange|2={{nbsp|3}}}}Foo{{bg|orange|. }}FOO{{bg|orange|...}}_foo{{bg|1=orange|2=] [}}12{{bg|orange|, }}-x}}
 
'''For example''': your template can use your predefined options as single parameter {{para|format}} input:
:{{para|1=format|2=bg-green, uc_first, wikilink}}
The template then can handle formatting like this:
:<code><nowiki>{{#invoke:sfw|main |explain=true |source={{{format|}}}|word=bg-green |yes=&lt;make bg green code&gt; |no=&lt;do nothing&gt;}}</nowiki></code>
:<code><nowiki>{{#invoke:sfw|main |explain=true |source={{{format|}}}|word=uc_first |yes=&lt;set uc first code&gt; |no=&lt;do nothing&gt;}}</nowiki></code>
Or, using the default output:
:<code><nowiki>{{#if:{{#invoke:sfw|main |explain=true |source={{{format|}}}|word=bg-green}} |&lt;make bg green code&gt; |&lt;do nothing&gt;}}</nowiki></code>
:<code><nowiki>{{#if:{{#invoke:sfw|main |explain=true |source={{{format|}}}|word=uc_first}} |&lt;set uc first code&gt; |&lt;do nothing&gt;}}</nowiki></code>
 
====newlines (failing) ====
* basic: {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, "(12) A?", lima, bar|word=foo, "(12) A?" }}
:as wordseparator?
{{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, foo lima, bar|word=foo, bar
 
 
, lima}}
 
:test in literals
* T lit: {{#invoke:User:DePiep/sfw|main |explain=true |s=alpha, "(12)
 
 
A?", lima, bar|word=foo, "(12)
 
 
A?" }}
 
 
== Usage ==
===Basic===
Core function:
<pre>
{{Str find word
{{User:DePiep/sfw
|source =
|word =
|yes =
|no =
}}
</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"
|-
! {{para|1=source}}
! {{para|1=word}}
! colspan="2" | result
! note
|-
| {{para|1=source|2=alpha, foo, lima}}
| {{para|word|foo}}
| {{#invoke:User:DePiep/sfwStr find word |main |explain=true |source=alpha, foo, lima |word=foo}}
| {{aye}}
|
|-
| {{para|1=source|2=alpha, uc-all}}
| {{para|word|uc-all}}
| {{#invoke:User:DePiep/sfw|main |explain=true |source=alpha, uc-all|word=uc-all}}
| {{aye}}
| "-" (hyphen) is part of the word
|-
| {{para|1=source|2=alpha, do_something, white}}
| {{para|word|do_something}}
| {{#invoke:User:DePiep/sfw|main |explain=true |source=alpha, do_something, white|word=do_something}}
| {{aye}}
| "_" (underscore) is part of the word
|-
| {{para|1=source|2=alpha, foo, lima}}
| {{para|word|november}}
| {{#invoke:User:DePiep/sfw|main |explain=true |source=alpha, foo, lima|word=november}}
| {{nay}}
|
|-
| {{para|1=source|2=alpha, foobar, lima}}
| {{para|word|foo}}
| {{#invoke:User:DePiep/sfw|main |explain=true |source=alpha, foobar, lima|word=foo}}
| {{nay}}
| 'foo' is not the complete word
|-
| {{para|1=source|2=alpha, foo, lima}}
| {{para|word|bar}}
| {{#invoke:User:DePiep/sfwStr find word |main |explain=true |source=alpha, foo, lima |word=foo-bar}}
| {{nay}}
| full word ''bar'' not in the source
| no {{para|word}} entered
|-
| {{para|1=source|2=alpha, foo, lima}}
| {{para|word|foobar}}
| {{#invoke:User:DePiep/sfwStr find word |main |explain=true |source=alpha, foo, lima|word=foo-bar|yes=Yes, hit|no=No, not found}}
| {{nay}}
| full word ''foo-barfoobar'' not in the source as full word
|}
 
===AND-wordlist checks===
:{{para|word}} 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).
:Alway, ''both'' {{para|word}} and {{para |andwords}} are combined into one single ''AND''-wordlist.
 
{| class="wikitable" style=""
|-
|! {{para|1=source}}<br/>{{para|21=alpha, foo, limas}}
|! {{para|word1=andwords}}<br/>{{para|foobar1=word}}
! result
| {{#invoke:User:DePiep/sfw|main |explain=true |source=alpha, foo-bar, lima|word=foo|yes=Yes, hit|no=No, not found}}
! note
| {{nay}}
| word ''foo'' not in the source as full word
|- <!-- ===== ===== ===== ===== ===== ===== ===== -->
! colspan="5" style="padding-left:3em; text-align:left;" | {{code|1=...}} {{para|yes|Yes, hit}} {{para|no|Not found}}
|-
| {{para|1=sources|2=alpha, foo, lima, delta}}
| {{para |wordandw|foodelta, lima}}
| {{#invoke:User:DePiep/sfwStr find word |main |explain=true |sources=alpha, foo, lima|word=foo|yes=Yes, hitdelta |noandw=Nodelta, not foundlima}}
| both words present in the source
| {{aye}}
|
|-
| {{para|1=sources|2=alpha, foo, lima, delta}}
| {{para |wordandw|foobarfoo, nov}}
| {{#invoke:User:DePiep/sfwStr find word |main |explain=true |sources=alpha, foo, lima|word=foobar|yes=Yes, hit|no=No, not founddelta}}
| AND-logic: A word in the ''AND''-list is not present ({{mono|nov}}), so false
| {{nay}}
| -
| {{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}}
===All parameters===
| {{para|w}} and {{para |andw}} are combined
:All parameters, in three options
{|
|-
| {{para|1=s|2=alpha, foo, lima, delta}}
|<pre>
| {{para |andw|bar, april}}
{{User:DePiep/sfw
| {{#invoke:Str find word |main |explain=true |s=alpha, foo, lima, delta |andw=delta}}
|string =
|
|word =
|allwords =
|orwords =
|case=
|yes =
|no =
|explain =
}}
</pre>
|<pre>
{{User:DePiep/sfw
|s =
|w =
|allw=
|orw =
|case=
|yes =
|no =
|explain =
}}
</pre>
| <pre>
{{User:DePiep/sfw
| =
| =
|allw=
|orw =
|case=
|yes =
|no =
|explain =
}}
</pre>
|}
<pre>{{User:DePiep/sfw |s= |w= |allw= |orw= |case= |yes= |no= |explain=}}</pre>
 
===MoreOR-wordlist optionschecks===
;{{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=source}}<br/> {{para|1=s}}
!
! {{para|1=1orwords}}
! result
! {{para|1=word}}<br/>{{para|1=w}} {{para|1=2}}
! {{para|1=case}}
! colspan="2" | result
! note
|-
| {{para|1=s|2=alpha, foo, lima, delta}}
| {{para|w|foo}}
|
|
| {{#invoke:User:DePiep/sfwStr find word |main |explain=true |s=alpha, foo, lima, delta |wandw=foo|yes=yes|no=nodelta, lima}}
| both words present in the source
|
|-
| {{para|1=s|2=alpha, foo, lima, delta}}
| {{para|w|foobar}}
|
|
| {{#invoke:User:DePiep/sfwStr find word |main |explain=true |sources=alpha, foo, lima|word=foobar|yes=yes|no=no, delta}}
|
|-
| {{para|1=s|2=alpha, foobarfoo, lima, delta}}
| {{para |wandw|foodelta}}
|
| {{#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:User:DePiep/sfw|main |explain=true |source=alpha, foobar, lima|word=foo|yes=yes|no=no}}
| {{#invoke:Str find word |main |explain=true |s=alpha, foo, lima, delta |orw=delta, lima}}
| 'foo' is not the complete word
| both OR-words are present in the source
|-
| {{para|1=s|2=alpha, FOOfoo, lima, delta}}
| {{para|w|foo}}
|
|
| {{#invoke:User:DePiep/sfwStr find word |main |explain=true |sources=alpha, FOOfoo, lima, delta |wordorw=foo|yes=yes|no=no|case=false, nov}}
| OR-logic: one of the words is present ({{para|foo}}), so true
| {{para|case|false}}: a=A ''(default)''
|-
| {{para|1=s|2=alpha, FOOfoo, lima, delta}}
| {{para |wandw|fooalpha, lima}}
| {{para |orw|foo, nov}}
|
| {{#invoke:Str find word |main |explain=true |s=alpha, foo, lima, delta |andw=alpha, lima |orw=foo, nov}}
|
|
| {{#invoke:User:DePiep/sfw|main |explain=true |source=alpha, FOO, lima|word=foo|yes=yes|no=no|case=true}}
|-
| {{para|case|true}}: a=/=A
| {{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-words to check===
===word list===
;{{para |andwords}} {{para |orwords}}
:Instead of a single word to check, a '''list of target words''' can be entered: {{para|word|alpha, foo, bingo}}. This {{para|word}}-list will be treated with ''AND''-logic: each and all of the words ''must'' be present. See:
:checks ''both'' lists for their own check: "ANd-words" must all be present, "OR-words" must have at least one present.
:Wordlist examples: {{para|word|''(wordlist)''}}
:Result: True if both check results are True, otherwise False.
::{{para|word|{{bg|yellow|alpha}}, {{bg|yellow|foo}}}}
::{{para|word|{{bg|yellow|alpha-beta}}; {{bg|yellow|_bar}};{{bg|yellow|all-up}}#{{bg|yellow|foo}}({{bg|yellow|27}}) {{bg|yellow|Oct}} {{bg|yellow| Nov}} [{{bg|yellow|Dec}}]}}
::When {{para|word}} contains a wordlist, all words must be present to return the Yes value (''AND''-logic).
 
===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}}<br/>{{para|1=andwword}}
! {{para|1=orwords}}<br/>{{para|1=orw}}
! result TODO fix
! note
|-
| {{para|1=s|2=alpha, foo, lima, delta}}
| {{para |andw|delta, lima}}
|
| {{#invoke:User:DePiep/sfwStr 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:User:DePiep/sfwStr 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:User:DePiep/sfwStr 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:User:DePiep/sfwStr find word |main |explain=true |s=alpha, foo, lima, delta |orw=delta, lima}}
| both OR-words are present in the source
|-
Line 432 ⟶ 203:
|
|
| {{#invoke:User:DePiep/sfwStr 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:User:DePiep/sfwStr 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:User:DePiep/sfwStr find word |main |explain=true |s=alpha, foo, lima, delta |andw=delta |orw=nov, dec}}
| none of the OR-words is present, so false
|}
 
==Roundup=Edge cases ===
;Blank list(s)
;A ''word''
:Empty input string(s) will conclude negative:
:A word can be {{mono|1=a-z, A-Z, 0-9, - _}} (not: {{mono|1=;,=()[]#$%}})
{| class="wikitable"
:Absent words never can make a True result
|-
:Digits are not treated as A number: "12" is a word.
! colspan="5" style="padding-left:3em; text-align:left;" | {{para|1=source, andwords, orwords|2=&lt;blank>}}
::Thus, the digital point "." is a ''word separato'', and so will split "-17.5" into ''words'' "-17" and "5".
|-
no numerical treatment: integers only (16.5 -> 16, 5)
| {{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=""
:newlines are not recognied. (todo: check pipes, etc).
|-
! {{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=}}===
;wordlists
{| class="wikitable"
:Wordlists consist of words & word-separators (=non-word-character): {{para|word|alpha, bravo charlie (17)}}
|-
:Wordlists can be entered in: {{para|source}}, {{para|word}}, {{para|andwords}}, {{para|orwords}} and their synonyms {{para|1=s{{!}}w{{!}}andw{{!}} orw}})
! colspan="5" style="padding-left:3em; text-align:left;" | {{para|out-true|out-true, a hit}}<br/>{{para|out-false|out-falset found}}
:All {{para|word|foo, bar}} words are treated as ''AND''- words (equally to, and together with {{para|andwords}})
|-
:repeated words in a list do not change the result, {{para|word|foo, foo}} = {{para|word|foo}}
| {{para|1=source|2=alpha, foo, lima}}
| {{para|word|foo}}
| {{#invoke:Str find word |main |explain=true |source=alpha, foo, lima |word=foo|out-true=Yes, a hit|out-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|out-true=Yes, a hit|out-false=No, not found}}
| {{nay}}
|}
 
===boolean words===
:''AND''-words: if present, ''all'' must be present in the source to be True
;{{para|booleans}}
:''OR''-words: if present, ''at least one'' must be present in the source to be True
:{{para|booleans|true}} will convert ''all boolean words'' into "True/False".
:An ''empty wordslist'' will considered to be True (will not create a False result)
:per [[:module:Yesno]] ({{code|1=Yes, true, yes, 1}} = true) (todo: document value 2?, nil, blanketc. Irrespective of case?)
:The result to be True requires: AND-check=True ''and'' OR-check=True
:other words not changed ("horse" remains horse, not T/F).
;results
:Note: per logic definition, the ''word'' "false" is returned (as being found).
:There are no "error" results. If anything logic 'fails', a False value is returned.
 
{| class="wikitable"
:By default:
|-
::'''Result=True''' returns the Yeslist: ''all'' words found; the AND-hitlist and the OR-hitlist
! colspan="5" style="padding-left:3em; text-align:left;" | {{para|1=booleans|2=true}}
::By definition, the Yeslist cannot be empty
|-
::Each list is <code>, <nowiki/></code>-separated (comma&nbsp;space), between the list is a <code>; </code>&nbsp;(semicolon&nbsp;space)
| {{para|1=source|2=YeS}}
:Each list is ordered by their searchlist order: 1. by AND-words 2. by order OR-words (not by order of source-words)
| {{para|1=word|2=true}}
::todo example here
| {{#invoke:Str find word |main |booleans=true |source=YeS |word=1}}
::'''Result=False''' returns a black string
|
|-
| {{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===
By {{para|1=yes={{!}}no}} parameter
:under construction
*When entered, the result will return the {{para|yes|}} or {{para|no|}} value for True/False respectively.
::{{para|yes|OK, my word is found!}}; {{para|no|No, my word is not in the source}}
::Each can also be explicitly blank: {{para|no|{{!}}}} (=the default no-return value for False); {{para|yes|{{!}}}}: would require {{para|no|2=not empty}} to be meaningful
 
===synonyms===
; no nil nor null
:under construction
:there is only T/F result. Not a nil situation.
</noinclude>
 
==errorsErrors 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:Unknown parameters}} (todo)
: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).
 
* Pages with Unknown parameters are listed in {{clc|Category:Pages using str find word with unknown parameters}}.
* {{para|explain|true}}: when in {{button|Preview}}, display a report on input, output and the logical steps (debug).
 
: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).
==questions==
* add &minus; (&amp;minus;) to accepted word chars?
* logic: when literal, do not change case? (keep UC/lc when {{para|case|false}} not valid for "LiterAl"?)
* why allow {{para|sep}} at all?
::And: pass new sep through to /report?
 
==code==
<includeonly>{{Sandbox other||
<!-- Categories below this line; interwikis at Wikidata -->
 
* {{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}}
<includeonly>{{sandbox other||
[[:Category:Modules that manipulate strings]]
}}</includeonly>