localchar=string.charlocalconcat=table.concatlocaltonumber=tonumberlocalfunctionerr(cp)error("Codepoint "..cp.." is out of range: codepoints must be between 0x0 and 0x10FFFF.",2)endlocalfunctionutf8_char(cp)cp=tonumber(cp)ifcp<0thenerr("-0x"..("%X"):format(-cp+1))elseifcp<0x80thenreturnchar(cp)elseifcp<0x800thenreturnchar(0xC0+cp/0x40,0x80+cp%0x40)elseifcp<0x10000thenifcp>=0xD800andcp<0xE000thenreturn"?"-- mw.ustring.char returns "?" for surrogates.endreturnchar(0xE0+cp/0x1000,0x80+cp/0x40%0x40,0x80+cp%0x40)elseifcp<0x110000thenreturnchar(0xF0+cp/0x40000,0x80+cp/0x1000%0x40,0x80+cp/0x40%0x40,0x80+cp%0x40)enderr("0x"..("%X"):format(cp))endreturnfunction(cp,...)if...==nilthenreturnutf8_char(cp)endlocalret={cp,...}fori=1,#retdoret[i]=utf8_char(ret[i])endreturnconcat(ret)end