Module:string/encode entities

Wiktionary වෙතින්

local codepoint
local decode_entities
local find = string.find
local format = string.format
local gsub = string.gsub
local match = string.match
local pattern_escape

local function encode_entity(ch)
	codepoint = codepoint or require("Module:string/codepoint")
	return "&#x" .. format("%X", codepoint(ch)) .. ";"
end

return function(text, charset, raw)
	if not raw then
		decode_entities = decode_entities or require("Module:string/decode entities")
		text = decode_entities(text)
	end
	if charset == "" then
		return text
	elseif not charset then
		charset = "\"&'<>\194\160"
	elseif not match(charset, "[\128-\244]") then
		pattern_escape = pattern_escape or require("Module:string/pattern escape")
		return (gsub(text, "[" .. pattern_escape(charset) .. "]", encode_entity))
	end
	return (gsub(text, "[%z\1-\127\194-\244][\128-\191]*", function(ch)
		return find(charset, ch, 1, true) and encode_entity(ch) or nil
	end))
end
"https://si.wiktionary.org/w/index.php?title=Module:string/encode_entities&oldid=164309" වෙතින් සම්ප්‍රවේශනය කෙරිණි