Module:User:kc kennylau/sandbox

p={}

function p.show(frame) local text = {} local a = {"003","004","005","006","007","008","009","020","021","022","023","024","025","026","027","028","029","02A","02C"} local res = "" for _,b in ipairs(a) do		local c = mw.loadData("Module:zh/data/ltc-pron/"..b)		for k,v in pairs(c) do			for _,d in ipairs(v) do				if mw.ustring.match(d,"[並定澄從邪崇俟禪常船群羣匣]%S+ 上") then res = res .. k				end end end end table.insert(text,res) return table.concat(text,'\n\n') end

function p.test_lowercase(fs) for _,f in ipairs(fs) do		local t1 = f("ABC[g]DEÉF") local t2 = f("A[E]BC[g]D[h]EF[p]") local t3 = f("A[E]BC[g]DEF[p]å^[!]") mw.log(t1,t2,t3) mw.log("abgdeéf","Ebghep","Ebgdepå!") end local s = ("ABCDE[e]"):rep(100) p.test(fs,s) end

function p.lowercase0(text) return (text .. "A[a]") :gsub("([^%[]*)[%z\1-Z\\^-\127\194-\244][\128-\191]*%[([^%]]+)%]",			function(a,b) return mw.ustring.lower(a)..b end) :sub(1,-2) end

function p.lowercase1(text) local replacements = {} local i = 1 local new_text = mw.ustring.gsub(text, "%[([^%[%]])%]",		function(position, new)			replacements[position-i] = new			i = i + 3			return ""		end) return mw.ustring.gsub(new_text, "(.)",		function(position, char)			return replacements[position] or mw.ustring.lower(char)		end) end

function p.lowercase2(text) local replacements = {} local offset = 0 local new_text = text:gsub("%[([%z\1-Z\\^-\127\194-\244][\128-\191]*)%]",       function(position, new)            replacements[position-offset] = new            offset = offset + #new + 2            return ""        end) return (new_text:gsub("([%z\1-\127\194-\244][\128-\191]*)", function(char, position) return replacements[position] or mw.ustring.lower(char) -- char:lower end)) end

function p.lowercase3(text) return text:gsub("([^%[%]]*)([%z\1-Z\\^-\127\194-\244][\128-\191]*)([%[%]]?)",		function(rest,char,instr)			if instr == "[" then return mw.ustring.lower(rest) end			if instr == "]" then return char end			return mw.ustring.lower(rest .. char)		end) end

function p.lowercase4(text) return text :gsub("^(.+%])(.*)$",			function(a,b) return a..mw.ustring.lower(b) end) :gsub("(.-)[%z\1-Z\\^-\127\194-\244][\128-\191]*%[([^%]]+)%]",			function(a,b) return mw.ustring.lower(a)..b end) end

function p.test(fs, x)	local t = os.time while os.time < t+1 do end t = t + 2 for i,f in ipairs(fs) do		local j = 0 while os.time < t do f(x) j = j + 1 end mw.log(j) t = t + 1 end end

function p.link1(t) t = mw.text.split(t, ' ', true) for i=1,#t do t[i] =  .. t[i] ..  end return table.concat(t, ' ') end

function p.link2(t) t = mw.ustring.gsub(t, '%s+', '%0') return t end

return p