lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Thu, Dec 29, 2005 at 04:10:26PM -0800, Chris Marrin wrote:
>     "This is a summation character: \226\136\145"
> 
> and a console that understood UTF8 would show a summation characer. But 
> to do this I had to:
> 
> - Use to the Character Map utility to find the character
> - Copy that character into OpenOffice, which understands Unicode
> - Save the file as UTF8
> - Open the file as binary in MsDev
> - Hand convert the character sequence to UTF8
> - Use Calculator to convert the result into decimal
> 
> It would be nice if Lua could do this for me :-)
what should Lua do for you?
Use to the Character Map utility?
Copy that character into OpenOffice?
Or write the one line Lua script to print the decimal
numbers corresponding to the UTF-8 representation
of a given Unicode point?
No problem, Lua does it for you.
The attached utftab prints 64 chars a line with their
base Lua string encoding; just add 0-63 to the last \128.
Run it in a UTF-8 xterm.
Use ncurses (or some extremely antisocial hacks from slnspider)
to add mouse support to print the code for any character.

However, your list pretty much makes the point that the problem
is not whether to write some u+xxx or two or three decimal codes.
You want to use either an Unicode capable editor
or some utility to look up codes
-- as long as everybody agrees to use UTF-8 anyway, that is.
It does make a big difference though where friends of the wide char
want their wchar_t based version of Lua. Anybody?
#!/opt/selene/bin/lua
local sprintf = string.format

-- bytes a,b
-- skip invalid a=192,193
a=194
io.write(sprintf("    \\%3d\\128 ",a))
for b=128,159 do io.write(" ") end -- skip c1 controls
for b=160,191 do io.write(sprintf("%c%c",a,b)) end
io.write("\n")

for a=195,223 do -- regular
	io.write(sprintf("    \\%3d\\128 ",a))
	for b=128,191 do io.write(sprintf("%c%c",a,b)) end
	io.write("\n")
end

-- bytes a,b,c
a=224 -- skip invalid b=128,159 for a=224
for b=160,191 do
	io.write(sprintf("\\%3d\\%3d\\128 ",a,b))
	for c=128,191 do io.write(sprintf("%c%c%c",a,b,c)) end
	io.write("\n")
end

for a=225,239 do -- regular a,b,c
	for b=128,191 do
		io.write(sprintf("\\%3d\\%3d\\128 ",a,b))
		for c=128,191 do io.write(sprintf("%c%c%c",a,b,c)) end
		io.write("\n")
	end
end