Module:Str find word/doc

This is an old revision of this page, as edited by DePiep (talk | contribs) at 10:22, 14 November 2021 (/doc). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Module:User:DePiep/sfw/links/doc

prev

  • xp-f: Script error: No such module "User:DePiep/sfw".
  • xp-t: Script error: No such module "User:DePiep/sfw".
  • xp-stat: Script error: No such module "User:DePiep/sfw".
  • xp-abs: Script error: No such module "User:DePiep/sfw".

§ top

/doc

Module:check for unknown parameters

This module looks for a complete word in a comma-separated list of words. It then returns a True or False value, which can be used accordingly.

The search can be ecxtended to check for multiple words being present (

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).

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