Jump to content

Module:DecodeEncode

Permanently protected module
From Wikipedia, the free encyclopedia

require('strict')localp={}localfunction_getBoolean(boolean_str)-- from: module:String; adapted-- requires an explicit truelocalboolean_valueiftype(boolean_str)=='string'thenboolean_str=boolean_str:lower()ifboolean_str=='true'orboolean_str=='yes'orboolean_str=='1'thenboolean_value=trueelseboolean_value=falseendelseiftype(boolean_str)=='boolean'thenboolean_value=boolean_strelseboolean_value=falseendreturnboolean_valueendfunctionp.decode(frame)locals=frame.args['s']or''localsubset_only=_getBoolean(frame.args['subset_only']orfalse)returnp._decode(s,subset_only)endfunctionp._decode(s,subset_only)-- U+2009 THIN SPACE: workaround for bug: HTML entity &thinsp; is decoded incorrect. Entity &ThinSpace; gets decoded properlys=mw.ustring.gsub(s,'&thinsp;','&ThinSpace;')-- U+03B5 ε GREEK SMALL LETTER EPSILON: workaround for bug (phab:T328840): HTML entity &epsilon; is decoded incorrect for gsub(). Entity &epsi; gets decoded properlys=mw.ustring.gsub(s,'&epsilon;','&epsi;')localret=mw.text.decode(s,notsubset_only)returnretendfunctionp.encode(frame)locals=frame.args['s']or''localcharset=frame.args['charset']returnp._encode(s,charset)endfunctionp._encode(s,charset)-- example: charset = '_&©−°\\\"\'\=' -- do escape with backslash not %;localretifcharsetandcharset~=''thenret=mw.text.encode(s,charset)else-- use default: chartset = '<>&"\' ' (outer quotes = lua required; space = NBSP)ret=mw.text.encode(s)endreturnretendreturnp
close