[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Could Lua itself become UTF8-aware?
- From: "Soni L." <fakedme@...>
- Date: Mon, 1 May 2017 18:54:18 -0300
On 2017-05-01 05:34 PM, Jay Carlson wrote:
On May 1, 2017, at 9:05 AM, Roberto Ierusalimschy <firstname.lastname@example.org> wrote:
I'd like to have Lua better support checking whether something is RFC-legal UTF-8.
What is wrong with 'utf8.len'?
Nothing I see now. Considering that you fixed it three years ago, I am embarrassed; I had written my own and kept it.
The assert-heavy style for is_utf8 is O(n*m). If you know the rules for UTF-8 manipulation in Lua, the number of callpoints, m, can stay small.
Perhaps you might wanna memoize (with "__mode") such calls? (if the
string is unchanged between calls, it's an O(1) instead of O(n) call,
thus you get O(n+m) instead. if it does get changed, interning still
ends up being more expensive.)
I have been saved several times by failed is_utf8 assertions, usually in strings not from my code. OK, my definition of "saved" includes "not producing results outside the domain, possibly causing the next program to crash. maybe." This level of obsession is probably not for everyone.
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.