lua-users home
lua-l archive

Re: Issues: Character 160 - Non-breaking space + Additional Issue with UTF-8

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


On 10 July 2018 at 15:00, Dirk Laurie <dirk.laurie@gmail.com> wrote:
> utf8.find ("Hélène",'n') --> 5 5
> utf8.sub ("Hélène",5) --> 'ne'
> utf8.gsub ("Hélène","[éè]","e") --> 'Helene' 2
> utf8.reverse ("Hélène") --> 'enèléH'
fully untested:
function utf8.find(s, ...)
 local a, b = s:find(...)
 return utf8.len(s, 1, a), utf8.len(s, 1, b)
end
function utf8.sub(s, a, b)
 return s:sub(utf8.offset(s, a), utf8.offset(s, b))
end
function utf8.reverse(s)
 local l, t = utf8.len(s), {}
 for p, c in utf8.codes(s) do
 t[l] = c
 l = l -1
 end
 return utf8.char(table.unpack(t))
end
-- 
Javier

AltStyle によって変換されたページ (->オリジナル) /