Modulo:mchkparametrojn: Malsamoj inter versioj

Enhavo forigita Enhavo aldonita
Taylor 49 (diskuto | kontribuoj)
forviŝas cimojn
Taylor 49 (diskuto | kontribuoj)
fixing bugs
Linio 1:
--[[
 
MODULE "mchkparametrojnMPIKSUBSTRIND" (checkpick parametrojnsubstring by index)
 
"eo.wiktionary.org/wiki/Modulo:mchkparametrojnmpiksubstrind"
 
Benefit: performspicks 2a comparisonssubstring infrom ordera tocomma-separated checkstring, validitythis
ofhelps theto parameterspick ofa thestring caller,from onlya nontwo-emptydimensional table
parameters do count
 
Utilo: elprenas subsignocxenon el perkome apartigita signocxeno, tio
Utilo: efektivigas 2 komparojn por kontroli validecon
helpas elpreni signocxenon el dudimensia tabelo
de parametroj de la vokanto, nur nemalplenaj
parametroj estas alsumigataj
 
Used by templates / Uzata far sxablonoj:
- eltblkemele
- multaj
- eltbllingvokodoinfo
- eltblmonato
- eltblnumeralo
- eltbltagodesemajno
 
Incoming: - 2string integers(length with lower limit (must be >=1...9) andchar, comma-separated uppersubstrings,
limitempty (mustsubstrings biggerdo orcount equalas theerror lowerif limit andthe lesssearch thanreaches 64such)
- index of the substring (ZERO-based, must be integer 0...63,
Returned: - string "1" if the parameters are OK, string "0" if
thetoo parametershigh suppliedindex toie the"not callerfound" arecounts bad,as or thiserror)
Returned: - found substring if success or string "eraro" if something
module itself became victim of misuze
goes wrong (when copying, possible leading and trailing
whitespace is being removed, while inner whitespace is
preserved but reduced and converted to exactly one space)
 
This module is unbreakable. /Every Cxiimaginable tiuinput modulowill estas nerompebla.output
either a useful result or the string "eraro".
 
Cxi tiu modulo estas nerompebla. Cxiu imagebla enigo eldonas aux
utilan rezulton aux signocxenon "eraro".
 
Usage examples with results / Ekzemploj de uzo kun rezultoj:
 
"{{#invoke:mpiksubstrong}}"
 
-> Lua error
 
"{{#invoke:mpiksubstrind|fek}}"
 
-> Lua error
 
"{{#invoke:mpiksubstrind|ek}}"
 
-> "eraro"
 
"{{#invoke:mpiksubstrind|ek|}}"
 
-> "eraro"
 
"{{#invoke:mpiksubstrind|ek||}}"
 
-> "eraro"
 
"{{#invoke:mpiksubstrind|ek|||}}"
 
-> "eraro"
 
"{{#invoke:mpiksubstrind|ek|X}}"
 
-> "eraro"
 
"{{#invoke:mpiksubstrind|ek|X|}}"
 
-> "eraro"
 
"{{#invoke:mpiksubstrind|ek|X|999}}"
 
-> "eraro"
 
"{{#invoke:mpiksubstrind|ek||XX|}}"
 
-> "eraro"
 
"{{#invoke:mpiksubstrind|ek|XX|XX|}}"
 
-> "eraro"
 
"{{#invoke:mpiksubstrind|ek||0}}"
 
-> "eraro"
 
"{{#invoke:mpiksubstrind|ek|X|0}}"
 
-> "X"
 
"{{#invoke:mpiksubstrind|ek|nul,unu,du,tri,kvar,kvin|4}}"
 
-> "kvar"
 
"{{#invoke:mpiksubstrind|ek|nul,unu,du,tri,kvar,kvin|5}}"
 
-> "kvin"
 
"{{#invoke:mpiksubstrind|ek|nul,unu,du,tri,kvar,kvin|6}}"
 
-> "eraro"
 
"{{#invoke:mpiksubstrind|ek| nul ,unu,du , tri,kvar, kvin |5}}"
 
-> "kvin"
 
"{{#invoke:mpiksubstrind|ek| nul,unu, du
,
tri ,kvar,kvin |4}}"
 
-> "kvar"
 
"{{#invoke:mpiksubstrind|ek|nul,unu,du,tri,kvar,kv i
n|5}}"
 
-> "kv i n"
 
"{{#invoke:mpiksubstrind|ek|nul,unu,du,tri,kvar, |5}}"
 
-> "eraro"
 
"{{#invoke:mpiksubstrind|ek|nul,unu,du,tri,kvar,|5}}"
 
-> "eraro"
 
"{{#invoke:mpiksubstrind|ek|nul,unu,du,tri,kvar,,|5}}"
 
-> "eraro"
 
"{{#invoke:mpiksubstrind|ek|nul,unu,du,tri,,kvar,kvin|3}}"
 
-> "tri"
 
"{{#invoke:mpiksubstrind|ek|nul,unu,du,tri,,kvar,kvin|4}}"
 
-> "eraro"
 
"{{#invoke:mpiksubstrind|ek|nul,unu,du,tri,,kvar,kvin|5}}"
 
-> "eraro"
 
"{{#invoke:mpiksubstrind|ek|nul,unu,du,tri, ,kvar,kvin|5}}"
 
-> "eraro"
 
"{{#invoke:mpiksubstrind|ek|nul,unu,du,tri,unu,kvin|4}}"
 
-> "unu"
 
"{{#invoke:mpiksubstrind|ek|nul,unu,du,tri,kvar,kvin|0}}"
 
-> "nul"
 
"{{#invoke:mpiksubstrind|ek|nul,unu,du,tri,kvar,kvin|00}}"
 
-> "nul"
 
"{{#invoke:mpiksubstrind|ek|nul,unu,du,tri,kvar,kvin|000}}"
 
-> "eraro"
 
"{{#invoke:mpiksubstrind|ek|nul,unu,du,tri,kvar,kvin|4.99}}"
 
-> "eraro"
 
"{{#invoke:mpiksubstrind|ek|nul,unu,du,tri,kvar,kvin|-1}}"
 
-> "eraro"
 
"{{#invoke:mpiksubstrind|ek|a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,
a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,
a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,
a,b,x,y,z,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t|63}}"
 
-> "y"
 
"{{#invoke:mpiksubstrind|ek|a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,
a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,
a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,
a,b,x,y,z,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t|64}}"
 
-> "eraro"
 
]]
 
local chkparametrojnpiksubstrind = {}
function chkparametrojnpiksubstrind.ek (frame)
local strtmpstrarg = "" ; -- the long input string, also temp for decimal conversionconve
local strret = "0" ; -- output string
local numlongnumsim = 0 ; -- temp for decimal conversion (length of parameter)
local numuppmnumsin = 0 255 ; -- tempindex forof decimalthe conversionstring, (noalso needtemp tofor decimal preset)convers
local numupplnumlength = 2550 ; -- upperlength limitof (presetthe toinput invalid)string, also temp for dec conv
local numlowlnumchar = 2550 ; -- lowerunicode codepoint limitof (preseta tosingle invalid)char
local numiternumite = 0 ; -- iteration index, iteratingcounts throughunicode parameterschars, of the callerONE-based
local boofnd = false ; -- multipurpose found flag
local boospc = false ; -- flag for whitespace reduction feature
local boouch = false ; -- flag for found a useful char when skipping string
if ((frame.args [1]) and (frame.args [2])) then
strtmpstrarg = frame.args [12] ; -- lowerindex limitof (1 digit)substring
numlongnumlength = mw.ustring.len (strtmpstrarg) ; -- temp for decimal conversion
if (numlong(numlength==1) or (numlength==2)) then
numlowlnumsin = mw.ustring.codepoint (strtmpstrarg,1,1) - 48 ; -- may be invalid
if ((numlowl<0) or (numlowl>9)) then
numlowl = 255 ; -- 255 is invalid, note that ZERO would be invalid too
end--if
end--if
if (numlength==2) then
strtmp = frame.args [2] ; -- upper limit (1 or 2 digits)
numlong numsim = mw.ustring.lencodepoint (strtmpstrarg,2,2) - 48 ; -- temp formay decimalbe conversioninvalid
if ((numlong==1) or (numlong==2)) then
numuppl = mw.ustring.codepoint (strtmp,1,1) - 48 ; -- may be invalid
if ((numuppl<0) or (numuppl>9)) then
numuppl = 255 ; -- 255 is invalid, note that ZERO would be invalid too
end--if
end--if
if (numlong==2(numsin<0) or (numsin>9) or (numsim<0) or (numsim>9)) then
numsin = 255 ; -- 255 is invalid, note that ZERO would be valid
numuppm = mw.ustring.codepoint (strtmp,2,2) - 48 ; -- may be invalid
else
if ((numuppm<0) or (numuppm>9)) then
if (numlength==2) then
numuppl = 255 ; -- 255 is invalid, note that ZERO would be invalid too
numsin = numsin * 10 + numsim ; -- valid integer number 0...99 now
else
numuppl = numuppl * 10 + numuppm ; -- valid integer number 0...99 now
end--if
end--if
strarg = frame.args [1] ; -- the long input string
numlength = mw.ustring.len (strarg) ; -- length of the input string
end--if
if ((numlowlnumlength>10) and (numlowl<10) and (numuppl>=numlowl) and (numupplnumsin<64)) then
while (true) do -- iterate through parameterssubstrings ofin theorder callerto skip them
if (numsin==0) then -- nothing to skip anymore
if (not (mw.getCurrentFrame():getParent().args[numiter+1])) then
boofnd = true ;
break ; -- no more parameters, "numiter" holds amount of those found
break ; -- exit the outer loop, nothing to skip anymore
else
end--if
if (mw.ustring.len (mw.getCurrentFrame():getParent().args[numiter+1])==0) then
numsin = numsin - 1 ;
break ; -- empty doesnt count, "numiter" holds amount of those found
boofnd = false ;
boouch = false ;
while (true) do -- iterate through whspace & chars mix looking for comma
if (numite>=numlength) then
break ; -- exit the inner loop, NOT found, give up
end--if
numite = numite + 1 ;
numchar = mw.ustring.codepoint (strarg,numite,numite) ;
if (numchar>32) and (numchar~=44) then
boouch = true ; -- found a valid char (empty field is an error)
end--if
if (numchar==44) then
if (boouch==true) then
boofnd = true ;
end--if
break ; -- exit the inner loop, found a comma, this is good or bad
end--if
end--while
if (boofnd==false) then
break ; -- exit the outer loop, NOT found or empty field, give up
end--if
numiter = numiter + 1 ;
end--while
if ((numiter>boofnd=numlowl) and (numiter<=numuppl)true) then
boofnd = false ;
strret = "1" ; -- output string (report success)
while (true) do -- iterate through chars skipping whitespace
if (numite>=numlength) then
break ; -- exit the loop, NOT found, give up
end--if
numite = numite + 1 ;
numchar = mw.ustring.codepoint (strarg,numite,numite) ;
if (numchar>32) then
if (numchar==44) then
break ; -- exit the loop, found a comma, give up according to the rules
end--if
boofnd = true ;
break ; -- exit the loop, found valid char, start copying now
end--if
end--while
end--if
if (boofnd==true) then
while (true) do -- iterate through chars copying the found string
if (numchar==32) then
boospc=true ;
else
if (boospc==true) then
strret = strret .. " " ;
boospc = false ;
end--if
strret = strret .. mw.ustring.char (numchar) ;
end--if
if (numite>=numlength) then
break ; -- exit the loop, done
end--if
numite = numite + 1 ;
numchar = mw.ustring.codepoint (strarg,numite,numite) ;
if (numchar==44) then
break ; -- exit the loop, done
end--if
end--while
end--if
end--if
if (boofnd==false) then
strret = "eraro" ;
end--if
return strret
end--function
return chkparametrojnpiksubstrind