It is currently April 19th, 2024, 7:07 am

Unicode character codes

Get help with creating, editing & fixing problems with skins
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Unicode character codes

Post by jsmorley »

Here is a pattern that does a better job of dealing with hex...

Code: Select all

function Unicode(inString)

	if inString == '' then return end
	newString = string.gsub(inString, '\\u(%x+)', '\[\\x%1\]')
	return newString

end	
Turns out that %x represents any hex digit, a-f, A-F, 0-9. Use that and remove the added space at the end, and then I think we are 99% there.

The only thing that would still fool it is a something like some text\u29and some more text, where 29 ) and 29a ʚ are both valid hex numbers and valid Unicode characters. This Lua will choose the later... I doubt you would ever see that, as the standard for using escapes to encode Unicode in HTML is that it must be followed by a space if the next character is one of a-f, A-F, 0-9.