Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lua string.upper not working with accented characters?

Tags:

lua

I'm trying to convert some French text to upper case in lua, it is not converting the accented characters. Any idea why?

test script:

print('échelle')
print(string.upper('échelle'))
print('ÉCHELLE')
print(string.lower('ÉCHELLE'))

output:

échelle
éCHELLE
ÉCHELLE
Échelle

like image 669
dirtbag Avatar asked Jul 20 '12 02:07

dirtbag


People also ask

What is %w Lua?

Valid in Lua, where %w is (almost) the equivalent of \w in other languages. ^[%w-.]+$ means match a string that is entirely composed of alphanumeric characters (letters and digits), dashes or dots.

What does string Sub Do in Lua?

Another important function of the Lua's string library is the string. sub() function. The string. sub() function is used to extract a piece of the string.


1 Answers

It might be a bit overkill, but you can do this with slnunicode (which is available in LuaRocks).

require "unicode"
print(unicode.utf8.upper("échelle"))
-- ÉCHELLE

You may need to use unicode.ascii.upper or unicode.latin1.upper depending on the encoding of your source files.

like image 107
furq Avatar answered Jan 03 '23 11:01

furq