lua-users home
lua-l archive

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


This is all predicted on being in a single-byte locale of course.  "." only matches a byte, not a character.

When Modula-3 came out, we thought it was a little daring and progressive to define the language as ISO Latin-1 rather than ASCII....

-- 
Jay
Sent from a Treo, excuse infelicities

-----Original Message-----
From: "Luiz Henrique de Figueiredo" <lhf@tecgraf.puc-rio.br>
To: "Lua list" <lua@bazar2.conectiva.com.br>
Sent: 4/15/07 5:34 PM
Subject: Re: removing diacritical marks from strings

> Does anybody happen to have a mapping (or an algorithm) that will
> remove diacritical marks from strings?  I'd like to convert Jérôme to
> Jerome and that sort of thing.

Try something like this (untested):

local t={
	['A'] = "ÀÁÂÃÄÅ",
	['E'] = "èéêë",
	...
}

local T={}
for i=0,255 do
	local c=string.char(i)
	T[c]=c
end
for k,v in pairs(t) do
	for i=1,#v do
		T[v:sub(i,i)]=k
	end
end

now use string.gsub(source,"(.)",T)
--lhf