Module:string/encode entities: Difference between revisions

From Linguifex
Jump to navigation Jump to search
m 1 revision imported
No edit summary
 
Line 1: Line 1:
-- TO BE REPLACED BY encode_entities in [[Module:string utilities]]. This function decodes on input by default to prevent double-encoding, which the new function does not, so implementations need to take this into account when being converted.
-- TO BE REPLACED BY encode_entities in [[Module:string utilities]]. This function decodes on input by default to prevent double-encoding, which the new function does not, so implementations need to take this into account when being converted.


local debug_track_module = "Module:debug/track"
local string_decode_entities_module = "Module:string/decodeEntities"
local string_decode_entities_module = "Module:string/decodeEntities"
local string_utilities_module = "Module:string utilities"
local string_utilities_module = "Module:string utilities"
Line 15: Line 14:
encode_entities = require(string_utilities_module).encode_entities
encode_entities = require(string_utilities_module).encode_entities
return encode_entities(...)
return encode_entities(...)
end
local function track(...)
track = require(debug_track_module)
return track(...)
end
end


Line 25: Line 19:
if not raw then
if not raw then
local decoded = decode_entities(str)
local decoded = decode_entities(str)
if decoded ~= str then
track("string/encode entities/decoded first")
end
str = decoded
str = decoded
end
end
return encode_entities(str, charset, nil, true)
return encode_entities(str, charset, nil, true)
end
end

Latest revision as of 10:57, 9 May 2026



-- TO BE REPLACED BY encode_entities in [[Module:string utilities]]. This function decodes on input by default to prevent double-encoding, which the new function does not, so implementations need to take this into account when being converted.

local string_decode_entities_module = "Module:string/decodeEntities"
local string_utilities_module = "Module:string utilities"

local require = require

local function decode_entities(...)
	decode_entities = require(string_decode_entities_module)
	return decode_entities(...)
end

local function encode_entities(...)
	encode_entities = require(string_utilities_module).encode_entities
	return encode_entities(...)
end

return function(str, charset, raw)
	if not raw then
		local decoded = decode_entities(str)
		str = decoded
	end
	return encode_entities(str, charset, nil, true)
end