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:
require('strict')
local p = {}
local p = {}


local function _getBoolean( boolean_str )
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 = _getBoolean(frame.args['subset_only'] or false)
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 )
-- U+2009 THIN SPACE: workaround for bug: HTML entity   is decoded incorrect. Entity   gets decoded properly
local ret = nil;
s = mw.ustring.gsub( s, ' ', ' ' )
-- U+03B5 ε GREEK SMALL LETTER EPSILON: workaround for bug (phab:T328840): HTML entity ε is decoded incorrect for gsub(). Entity ε gets decoded properly
s = mw.ustring.gsub( s, 'ε', 'ε' )


local ret = mw.text.decode( s, not subset_only )
    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 = frame.args['charset']
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 charset and charset ~= '' then
if charset ~= (nil or '') then
ret = mw.text.encode( s, charset )
ret = mw.text.encode( s, charset )
else
else

Please note that all contributions to Timeline of History may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see Timeline of History:Copyrights for details). Do not submit copyrighted work without permission!

To edit this page, please answer the question that appears below (more info):

Cancel Editing help (opens in new window)

Template used on this page: