All pastes #758771 Raw Edit

Someone

public text v1 · immutable
·published 2007-11-02 15:42 UTC
rendered paste body
-- Using http://lua-users.org/lists/lua-l/2005-10/msg00371.html

function checkxml(s)
        local r = {};
        local ucode;
        for utf8seq in s:eachutf8() do
                ucode = utf8seq:toucode();
                if (ucode >= 0x20 and ucode <= 0xD7FF) or (ucode >= 0xE000 and ucode <= 0xFFFD) or (ucode >= 0x10000 and ucode <= 0x10FFFF) or ucode == 0x9 or ucode == 0xA or ucode == 0xD then
                        table.insert(r, utf8seq);
                else
                        table.insert(r, string.format("&#%d;", ucode));
                end
        end
        return table.concat(r);
end