lua-users home
lua-l archive

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


2017-02-09 14:05 GMT+02:00 云风 Cloud Wu <cloudwu@gmail.com>:

> But there is another problem.
>
> local s = "\xE4\xBA"
> assert(utf8.len(s, 1, 2) == utf8.len(s .. "\x91",1,2)) -- failed

Why is this a problem? It should fail. s is not a valid UTF8 codepoint
("\xE4" promises three bytes, but there are only two). When you
supply the extra byte, there is one valid codepoint. starting between
charaters 1 and 2.

> utf8.len(s, 1, 2)
nil    1
> utf8.len(s .. "\x91",1,2)
1