Module:Str find word/doc

This is an old revision of this page, as edited by DePiep (talk | contribs) at 11:31, 30 October 2021. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

§ code   § toc   m:/sfw (edit) | /report (edit)

Module:String Module:Infobox Module:Yesno  · {{Navbox wikitext-handling templates}}  ·
mw:Lua manual  · User:DePiep/sfw (/sandbox, (/sandbox2))
===show 2===
  • litF: Script error: No such module "User:DePiep/sfw".
  • litT: Script error: No such module "User:DePiep/sfw".
  • lit-dflt: Script error: No such module "User:DePiep/sfw".
  • lit-blank: Script error: No such module "User:DePiep/sfw".
  • Script error: No such module "User:DePiep/sfw".
  • Script error: No such module "User:DePiep/sfw".


basic

  • Script error: No such module "User:DePiep/sfw".
  • T: Script error: No such module "User:DePiep/sfw".
  • allup T: Script error: No such module "User:DePiep/sfw".
sep
  • sep=$: Script error: No such module "User:DePiep/sfw".
  • sep_: Script error: No such module "User:DePiep/sfw".

yes options

  • dflt T: Script error: No such module "User:DePiep/sfw".
  • dflt F: Script error: No such module "User:DePiep/sfw".
  • yes. T: Script error: No such module "User:DePiep/sfw".
  • yes.Yss T: Script error: No such module "User:DePiep/sfw".
===lit check===
  • lit.t: Script error: No such module "User:DePiep/sfw".
  • lit.t, loopcheck3x: Script error: No such module "User:DePiep/sfw".
  • lit.t, loopcheck3x: Script error: No such module "User:DePiep/sfw".


  • lit.dflt: Script error: No such module "User:DePiep/sfw".
  • lit.T: Script error: No such module "User:DePiep/sfw".
  • lit.F: Script error: No such module "User:DePiep/sfw".
multi
  • lit.dflt: Script error: No such module "User:DePiep/sfw".
spaces
  • lit.T: Script error: No such module "User:DePiep/sfw".

§ top

demos

literals

demos & tests to be oimproved
  • T lit: Script error: No such module "User:DePiep/sfw".
  • T 2lt, ws: Script error: No such module "User:DePiep/sfw".
  • T 2lt, ws: Script error: No such module "User:DePiep/sfw".
  • T 2lt, ws: Script error: No such module "User:DePiep/sfw".
litdflt, t, f
  • T lit=F: Script error: No such module "User:DePiep/sfw".
  • T lit=F: Script error: No such module "User:DePiep/sfw".
  • T lit=F: Script error: No such module "User:DePiep/sfw".
  • T lit=F: Script error: No such module "User:DePiep/sfw".
  • T lit, ws!: Script error: No such module "User:DePiep/sfw".
  • F lit, ws!: Script error: No such module "User:DePiep/sfw".
  • T lit, ws!: Script error: No such module "User:DePiep/sfw".
  • F lit, ws!: Script error: No such module "User:DePiep/sfw".


edge
  • ? lit edge, ws: Script error: No such module "User:DePiep/sfw".
  • ? lit edge, ws: Script error: No such module "User:DePiep/sfw".
  • ? lit edge, ws: Script error: No such module "User:DePiep/sfw".
  • F lit: Script error: No such module "User:DePiep/sfw".
  • test lit: Script error: No such module "User:DePiep/sfw".
minor checks
  • F lit: Script error: No such module "User:DePiep/sfw".
  • F lit: Script error: No such module "User:DePiep/sfw".
  • F lit: Script error: No such module "User:DePiep/sfw".

bool

  • T boolT: Script error: No such module "User:DePiep/sfw".
  • F boolF: Script error: No such module "User:DePiep/sfw".
  • F bool: Script error: No such module "User:DePiep/sfw".
  • T: Script error: No such module "User:DePiep/sfw".
  • F: Script error: No such module "User:DePiep/sfw".
bool check case
  • T boolT: Script error: No such module "User:DePiep/sfw".
  • F boolF: Script error: No such module "User:DePiep/sfw".
  • T boolT: Script error: No such module "User:DePiep/sfw".
  • F boolF: Script error: No such module "User:DePiep/sfw".

basic tests

  • T: Script error: No such module "User:DePiep/sfw".
  • F: Script error: No such module "User:DePiep/sfw".
  • T and: Script error: No such module "User:DePiep/sfw".
  • T or: Script error: No such module "User:DePiep/sfw".
  • T andor: Script error: No such module "User:DePiep/sfw".
  • F andor: Script error: No such module "User:DePiep/sfw".
  • F andor: Script error: No such module "User:DePiep/sfw".
  • T case: Script error: No such module "User:DePiep/sfw".
  • F blanks: Script error: No such module "User:DePiep/sfw".
  • T yn: Script error: No such module "User:DePiep/sfw".
  • F yn: Script error: No such module "User:DePiep/sfw".
  • Script error: No such module "User:DePiep/sfw".
  • Script error: No such module "User:DePiep/sfw".
  • Script error: No such module "User:DePiep/sfw".
  • Script error: No such module "User:DePiep/sfw".
  • Script error: No such module "User:DePiep/sfw".
  • Script error: No such module "User:DePiep/sfw".

yes no options

  • Script error: No such module "User:DePiep/sfw".
  • Script error: No such module "User:DePiep/sfw".
  • Script error: No such module "User:DePiep/sfw".
  • Script error: No such module "User:DePiep/sfw".

yes/no=<blank>

  • b: Script error: No such module "User:DePiep/sfw".
  • bb: Script error: No such module "User:DePiep/sfw".
  • bnoval: Script error: No such module "User:DePiep/sfw".
  • abst: Script error: No such module "User:DePiep/sfw".
  • T: Script error: No such module "User:DePiep/sfw".
  • bT: Script error: No such module "User:DePiep/sfw".
  • F ynblank: Script error: No such module "User:DePiep/sfw".

unicode html decode

  • T: Script error: No such module "User:DePiep/sfw".
  • T: Script error: No such module "User:DePiep/sfw".
  • T: Script error: No such module "User:DePiep/sfw".
  • T: Script error: No such module "User:DePiep/sfw".
  • f: Script error: No such module "User:DePiep/sfw".

case

  • dflt: Script error: No such module "User:DePiep/sfw".
  • dflt: Script error: No such module "User:DePiep/sfw".
  • cF:dflt Script error: No such module "User:DePiep/sfw".
  • cT:dflt Script error: No such module "User:DePiep/sfw".

file & table output

  • Script error: No such module "User:DePiep/sfw".
  • Script error: No such module "User:DePiep/sfw".
  • Script error: No such module "User:DePiep/sfw".
  • Script error: No such module "User:DePiep/sfw".
  • Script error: No such module "User:DePiep/sfw".
  • Script error: No such module "User:DePiep/sfw".

nowords input

  • Script error: No such module "User:DePiep/sfw".
  • Script error: No such module "User:DePiep/sfw".
  • Script error: No such module "User:DePiep/sfw".
  • Script error: No such module "User:DePiep/sfw".
  • Script error: No such module "User:DePiep/sfw".

/doc

Module:check for unknown parameters

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 'alpha, foobar' the word 'alpha' appears, but the word 'foo' does not: there only is the complete word 'foobar'. The module is aimed at template code usage. (The editor does not have to apply Lua patterns like [%a%d]*).

A word is defined to be only of these characters: alphanumerics ('a-z A-Z 0-9'), hyphen ('-') and underscore ('_')  Y. All other characters are non-word characters, and so possible word-separators (like ';,()<space>'   12pxN).

Word examples todo check+good examples
foo, foobar, foo-bar foo_bar#)($foo123   Foo. FOO..._foo] 12, -x, zob(28)
foo, foobar, foo-bar foo_bar#)($foo123   Foo. FOO..._foo] [12, -x
foo, foobar, foo-bar foo_bar#)($foo123   Foo. FOO..._foo] [12, -x

For example: your template can use your predefined options as single parameter |format= input:

|format=bg-green, uc_first, wikilink

The template then can handle formatting like this:

{{#invoke:sfw|main |explain=true |source={{{format|}}}|word=bg-green |yes=<make bg green code> |no=<do nothing>}}
{{#invoke:sfw|main |explain=true |source={{{format|}}}|word=uc_first |yes=<set uc first code> |no=<do nothing>}}

Or, using the default output:

{{#if:{{#invoke:sfw|main |explain=true |source={{{format|}}}|word=bg-green}} |<make bg green code> |<do nothing>}}
{{#if:{{#invoke:sfw|main |explain=true |source={{{format|}}}|word=uc_first}} |<set uc first code> |<do nothing>}}

newlines (failing)

  • basic: Script error: No such module "User:DePiep/sfw".
as wordseparator?

Script error: No such module "User:DePiep/sfw".

test in literals
  • T lit: Script error: No such module "User:DePiep/sfw".


Usage

Basic

Core function:

{{User:DePiep/sfw
|source =
|word   =
|yes    =
|no     =
}}
When the word is found in the source (True), the function returns the word itself (by default), or |yes= value (when entered non-empty).
When not found (False), the function returns a empty string (''), or the |no= value when entered.
|source= |word= result note
|source=alpha, foo, lima |word=foo Script error: No such module "User:DePiep/sfw".  Y
|source=alpha, uc-all |word=uc-all Script error: No such module "User:DePiep/sfw".  Y "-" (hyphen) is part of the word
|source=alpha, do_something, white |word=do_something Script error: No such module "User:DePiep/sfw".  Y "_" (underscore) is part of the word
|source=alpha, foo, lima |word=november Script error: No such module "User:DePiep/sfw".  N
|source=alpha, foobar, lima |word=foo Script error: No such module "User:DePiep/sfw".  N 'foo' is not the complete word
|source=alpha, foo, lima |word= Script error: No such module "User:DePiep/sfw".  N no |word= entered
|source=alpha, foo, lima |word=foobar Script error: No such module "User:DePiep/sfw".  N full word foo-bar not in the source
|source=alpha, foo, lima |word=foobar Script error: No such module "User:DePiep/sfw".  N word foo not in the source as full word
... |yes=Yes, hit |no=Not found
|source=alpha, foo, lima |word=foo Script error: No such module "User:DePiep/sfw".  Y
|source=alpha, foo, lima |word=foobar Script error: No such module "User:DePiep/sfw".  N

All parameters

All parameters, in three options
{{User:DePiep/sfw
|string = 
|word   =
|allwords =
|orwords  = 
|case=
|yes =
|no  =
|explain =
}}
{{User:DePiep/sfw
|s   = 
|w   =
|allw=
|orw =
|case=
|yes =
|no  =
|explain =
}}
{{User:DePiep/sfw
|    = 
|    =
|allw=
|orw =
|case=
|yes =
|no  =
|explain =
}}
{{User:DePiep/sfw |s= |w= |allw= |orw= |case= |yes= |no= |explain=}}

More options

|source=
|s= |1=
|word=
|w= |2=
|case= result note
|s=alpha, foo, lima |w=foo Script error: No such module "User:DePiep/sfw".
|s=alpha, foo, lima |w=foobar Script error: No such module "User:DePiep/sfw".
|s=alpha, foobar, lima |w=foo Script error: No such module "User:DePiep/sfw". 'foo' is not the complete word
|s=alpha, FOO, lima |w=foo Script error: No such module "User:DePiep/sfw". |case=false: a=A (default)
|s=alpha, FOO, lima |w=foo Script error: No such module "User:DePiep/sfw". |case=true: a=/=A

word list

Instead of a single word to check, a list of target words can be entered: |word=alpha, foo, bingo. This |word=-list will be treated with AND-logic: each and all of the words must be present. See:
Wordlist examples: |word=(wordlist)
|word=alpha, foo
|word=alpha-beta; _bar;all-up#foo(27) Oct Nov [Dec]
When |word= contains a wordlist, all words must be present to return the Yes value (AND-logic).

AND-, OR-wordlist checks

|word= as noted, can be a list of words. all will be checked with the AND-requirement (each word must be present).
|andwords= accepts a list of words that all will be checked with the AND-requirement (each word must be present).
When both |word=, |andwords= are present, they are combined into one single AND-wordlist.
|orwords= accepts a list of words that all will be checked with the OR-requirement (at least one of the words must be present).
|source=
|s=
|andwords=
|andw=
|orwords=
|orw=
result TODO fix note
|s=alpha, foo, lima, delta |andw=delta, lima Script error: No such module "User:DePiep/sfw". both words present in the source
|s=alpha, foo, lima, delta |andw=foo, nov Script error: No such module "User:DePiep/sfw". AND-logic: A word in the AND-list is not present (nov), so false
|s=alpha, foo, lima, delta |andw=delta Script error: No such module "User:DePiep/sfw". |w= and |andw= are combined
|s=alpha, foo, lima, delta |orw=delta, lima Script error: No such module "User:DePiep/sfw". both OR-words are present in the source
|s=alpha, foo, lima, delta Script error: No such module "User:DePiep/sfw". OR-logic: one of the words is present (|foo=), so true
|s=alpha, foo, lima, delta |andw=alpha, lima |orw=foo, nov Script error: No such module "User:DePiep/sfw".
|s=alpha, foo, lima, delta |andw=bar, april |orw=nov, dec Script error: No such module "User:DePiep/sfw". none of the OR-words is present, so false

Roundup

A word
A word can be a-z, A-Z, 0-9, - _ (not: ;,=()[]#$%)
Absent words never can make a True result
Digits are not treated as A number: "12" is a word.
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)

newlines are not recognied. (todo: check pipes, etc).
wordlists
Wordlists consist of words & word-separators (=non-word-character): |word=alpha, bravo charlie (17)
Wordlists can be entered in: |source=, |word=, |andwords=, |orwords= and their synonyms |s|w|andw| orw=)
All |word=foo, bar words are treated as AND- words (equally to, and together with |andwords=)
repeated words in a list do not change the result, |word=foo, foo = |word=foo
AND-words: if present, all must be present in the source to be True
OR-words: if present, at least one must be present in the source to be True
An empty wordslist will considered to be True (will not create a False result)
The result to be True requires: AND-check=True and OR-check=True
results
There are no "error" results. If anything logic 'fails', a False value is returned.
By default:
Result=True returns the Yeslist: all words found; the AND-hitlist and the OR-hitlist
By definition, the Yeslist cannot be empty
Each list is , -separated (comma space), between the list is a ;  (semicolon space)
Each list is ordered by their searchlist order: 1. by AND-words 2. by order OR-words (not by order of source-words)
todo example here
Result=False returns a black string

By |yes=|no= parameter

  • When entered, the result will return the |yes= or |no= value for True/False respectively.
|yes=OK, my word is found!; |no=No, my word is not in the source
Each can also be explicitly blank: |no=| (=the default no-return value for False); |yes=|: would require |no=not empty to be meaningful
no nil nor null
there is only T/F result. Not a nil situation.

errors and analysis

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).
  • |explain=true: when in Preview, display a report on input, output and the logical steps (debug).

questions

  • add − (&minus;) to accepted word chars?
  • logic: when literal, do not change case? (keep UC/lc when |case=false not valid for "LiterAl"?)
  • why allow |sep= at all?
And: pass new sep through to /report?

code