lua-users home
lua-l archive

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



On 11-Oct-05, at 5:10 PM, Walter Cruz wrote:

Hi. Does anybody have a utf82latin2 function in lua to share? :P

 []'s
 - Walter

Here's one (for Lua5.1) which isn't very good :)

 function utf8tolatin1(s)
  return (s:gsub("([\192-\255])([\128-\191]*)", function(head, tail)
    if head == "\194" and #tail == 1 then
      return tail
    elseif head == "\195" and #tail == 1 then
      return string.char(tail:byte()+64)
    else return "?"
    end
  end))
end


It does too little error checking, and it doesn't combine diacritics (i.e. n + combining ~ does not become ñ). So it's only virtue is that it fits in a short email message.