Editing Module:DecodeEncode
Jump to navigation
Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
function _getBoolean( boolean_str ) | |||
-- from: module:String; adapted | -- from: module:String; adapted | ||
-- requires an explicit true | -- requires an explicit true | ||
Line 23: | Line 22: | ||
function p.decode( frame ) | function p.decode( frame ) | ||
local s = frame.args['s'] or '' | 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 ) | return p._decode( s, subset_only ) | ||
Line 30: | Line 32: | ||
function p._decode( s, subset_only ) | 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 | return ret | ||
Line 41: | Line 42: | ||
function p.encode( frame ) | function p.encode( frame ) | ||
local s = frame.args['s'] or '' | local s | ||
local charset | |||
s = frame.args['s'] or '' | |||
charset = frame.args['charset'] | |||
return p._encode( s, charset ) | return p._encode( s, charset ) | ||
Line 51: | Line 55: | ||
local ret | local ret | ||
if | if charset ~= (nil or '') then | ||
ret = mw.text.encode( s, charset ) | ret = mw.text.encode( s, charset ) | ||
else | else |