Modulo:mchkparametrojn: Malsamoj inter versioj
Enhavo forigita Enhavo aldonita
forviŝas cimojn |
fixing bugs |
||
Linio 1:
--[[
MODULE "
"eo.wiktionary.org/wiki/Modulo:
Benefit:
Utilo: elprenas subsignocxenon el perkome apartigita signocxeno, tio
helpas elpreni signocxenon el dudimensia tabelo
Used by templates / Uzata far sxablonoj:
- eltblkemele
- eltbllingvokodoinfo
- eltblmonato
- eltblnumeralo
- eltbltagodesemajno
Incoming: -
- index of the substring (ZERO-based, must be integer 0...63,
Returned: - found substring if success or string "eraro" if something
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.
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
function
local
local strret = "
local
local
local
local
local
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
if (
end--if
if (numlength==2) then
end--if
if (
numsin = 255 ; -- 255 is invalid, note that ZERO would be valid
else
if (numlength==2) then
numsin = numsin * 10 + numsim ; -- 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 ((
while (true) do -- iterate through
if (numsin==0) then -- nothing to skip anymore
boofnd = true ;
break ; -- exit the outer loop, nothing to skip anymore
end--if
numsin = numsin - 1 ;
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
end--while
if (
boofnd = false ;
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
|