မေႃႇၵျူး:DecodeEncode
ၽိုၼ်ၵႅမ်မိုဝ်းမေႃႇၵျူး[သၢင်ႈ]
တွၼ်ႈတႃႇ Scribunto module ဢၼ်ၼႆႉ ၸဝ်ႈၵဝ်ႇ ၸၢင်ႈ သၢင်ႈ ၼႃႈလိၵ်ႈ ၼႆႉလႆႈယူႇၶႃႈ။ ၽူႈၸိူဝ်းမႄးထတ်းၶဝ် ၸၢင်ႈၸၢမ်းတူၺ်းလႆႈ ၸိူဝ်းပဵၼ်ၼႃႈလိၵ်ႈ sandbox (သၢင်ႈ | ငဝ်းမိူၼ်) လႄႈ testcases (သၢင်ႈ) ႁင်း မေႃႇၵျူးဢၼ်ၼႆႉ လႆႈယူႇၶႃႈ။ သႂ်ႇပိူင်ထၢၼ်ႈ ၵႃႈတီႈ ၼႃႈလိၵ်ႈၽႄ /doc လႄႈ။ ၼႃႈလိၵ်ႈၽႄ ႁင်း မေႃႇၵျူး ဢၼ်ၼႆႉ။. |
local p = {}
function _getBoolean( boolean_str )
-- from: module:String; adapted
-- requires an explicit true
local boolean_value
if type( boolean_str ) == 'string' then
boolean_str = boolean_str:lower()
if boolean_str == 'true' or boolean_str == 'yes' or boolean_str == '1' then
boolean_value = true
else
boolean_value = false
end
elseif type( boolean_str ) == 'boolean' then
boolean_value = boolean_str
else
boolean_value = false
end
return boolean_value
end
function p.decode( frame )
local s
local subset_only
s = frame.args['s'] or ''
subset_only = _getBoolean(frame.args['subset_only'] or false)
return p._decode( s, subset_only )
end
function p._decode( s, subset_only )
local ret = nil;
s = mw.ustring.gsub( s, ' ', ' ' ) -- Workaround for bug:   gets properly decoded in decode, but   doesn't.
ret = mw.text.decode( s, not subset_only )
return ret
end
function p.encode( frame )
local s
local charset
s = frame.args['s'] or ''
charset = frame.args['charset']
return p._encode( s, charset )
end
function p._encode( s, charset )
-- example: charset = '_&©−°\\\"\'\=' -- do escape with backslash not %;
local ret
if charset ~= (nil or '') then
ret = mw.text.encode( s, charset )
else
-- use default: chartset = '<>&"\' ' (outer quotes = lua required; space = NBSP)
ret = mw.text.encode( s )
end
return ret
end
return p