မေႃႇၵျူး:string utilities: လွင်ႈပႅၵ်ႇပိူင်ႈ ၼႂ်းၵႄႈ လွင်ႈၶူၼ်ႉၶႆႈ

Content deleted Content added
Saimawnkham (ဢုပ်ႇဢူဝ်း) ၵေႃႉ ၶိုၼ်ၶိုၼ်း လွင်ႈၶူၼ်ႉၶႆႈ 88282
Tags: Undo Reverted
mNo edit summary
Tags: Manual revert Reverted
ထႅဝ် 102:
-- 4-byte codepoint, F4.
-- Make sure it doesn't decode to over U+10FFFF.
if text:byte(c.byte + 12) > 0x8f then
error("String " .. text .. " is not UTF-8.")
end
ထႅဝ် 507:
function export.lcfirst(text)
return uclcfirst(text, true)
end
 
-- Almost identical to mw.text.nowiki, but with minor changes to be identical to the PHP equivalent: ";" always escapes, and colons in certain protocols only escape after regex \b. Also about 2-3 times as fast.
function export.nowiki(text)
return (text
:gsub("[\"&'<=>%[%]{|};]", {
["\""] = "&#34;", ["&"] = "&#38;", ["'"] = "&#39;",
["<"] = "&#60;", ["="] = "&#61;", [">"] = "&#62;",
["["] = "&#91;", ["]"] = "&#93;", ["{"] = "&#123;",
["|"] = "&#124;", ["}"] = "&#125;", [";"] = "&#59;"
})
:gsub("%f[^%z\r\n][#*: \n\r\t]", {
["#"] = "&#35;", ["*"] = "&#42;", [":"] = "&#58;",
[" "] = "&#32;", ["\n"] = "&#10;", ["\r"] = "&#13;",
["\t"] = "&#9;"
})
:gsub("(%f[^%z\r\n])%-(%-%-%-)", "%1&#45;%2")
:gsub("__", "_&#95;")
:gsub("://", "&#58;//")
:gsub("([IP]?[MRS][BFI][CDN])([\t\n\f\r ])", function(m1, m2)
if m1 == "ISBN" or m1 == "RFC" or m1 == "PMID" then
return m1 .. m2:gsub(".", {
["\t"] = "&#9;", ["\n"] = "&#10;", ["\f"] = "&#12;",
["\r"] = "&#13;", [" "] = "&#32;"
})
end
end)
:gsub("[%w_]+:", {
["bitcoin:"] = "bitcoin&#58;", ["geo:"] = "geo&#58;", ["magnet:"] = "magnet&#58;",
["mailto:"] = "mailto&#58;", ["matrix:"] = "matrix&#58;", ["news:"] = "news&#58;",
["sip:"] = "sip&#58;", ["sips:"] = "sips&#58;", ["sms:"] = "sms&#58;",
["tel:"] = "tel&#58;", ["urn:"] = "urn&#58;", ["xmpp:"] = "xmpp&#58;"
}))
end