VOOZH about

URL: https://minecraft.wiki/w/Module:Text

⇱ Module:Text – Minecraft Wiki


Module:Text

From Minecraft Wiki
Jump to navigation Jump to search
Documentation[view] [edit] [history] [purge]Jump to code ↴

This is an exact copy of the built-in mw.text.gsplit, mw.text.split, and mw.text.trim functions, just using the significantly faster string library instead of the ustring library. As such, this won't work properly if you're trying to split a string by unicode characters, or trim unicode characters from a string. Unicode characters being in the string should be fine though.

[view] [edit] [history] [purge]The above documentation is transcluded from Module:Text/doc.
-- Source: https://phabricator.wikimedia.org/diffusion/ELUA/browse/master/includes/Engines/LuaCommon/lualib/mw.text.lua
localp={}
functionp.gsplit(text,pattern,plain)
locals,l=1,text:len()
returnfunction()
ifsthen
locale,n=text:find(pattern,s,plain)
localret
ifnotethen
ret=text:sub(s)
s=nil
elseifn<ethen
-- Empty separator!
ret=text:sub(s,e)
ife<lthen
s=e+1
else
s=nil
end
else
ret=e>sandtext:sub(s,e-1)or''
s=n+1
end
returnret
end
end,nil,nil
end
functionp.split(text,pattern,plain)
localret={}
forminp.gsplit(text,pattern,plain)do
ret[#ret+1]=m
end
returnret
end
functionp.trim(s,charset)
ifnotcharsetthen
returnstring.match(s,'^()%s*$')and''orstring.match(s,'^%s*(.*%S)')
else
return(string.gsub(s,'^['..charset..']*(.-)['..charset..']*$','%1'))
end
end
returnp
Retrieved from "https://minecraft.wiki/w/Module:Text?oldid=2929107"

Navigation menu