utils.utf8valid

Checks if a UTF-8 string is valid

Prototype

n, column = utils.utf8valid (s)

Description

This checks if a UTF-8 string is valid.

This returns the length of the string (in Unicode characters) if the supplied string is valid UTF-8.

Otherwise it returns nil, and the column of the character in error (1-relative).

eg.

print (utils.utf8valid (utils.fromhex ("F5838894FCB5898588B4"))) --> 2
print (utils.utf8valid (utils.fromhex ("f0f0f0"))) --> nil 1

Lua functions

Topics