Skip to content

kikito/utf8_validator.lua

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 

utf8_validator.lua

This Lua function can be used to validate UTF-8 strings.

Usage:

local utf8_validator = require 'utf8_validator'

local is_valid  = utf_validator.validate('This is valid')

-- you can also use the shortcut syntax:
local is_valid2 = utf_validator('This is also valid')

If a string is not valid utf8, then validate will also return the position of the first byte that makes it non-valid:

local is_valid, error_position = utf_validator(a_binary_blob)
if not is_valid then print('non-utf8 sequence detected at position ' .. tostring(error_position))

For valid utf8 strings, error_position is always nil.

Installation

Just copy the utf8_validator.lua file wherever you need it and require it.

License

This library is MIT-licensed.

Specs

This library uses busted for its specs. In order to run them, install busted and then:

cd path/where/the/spec/folder/is
busted

About

Easily validating UTF-8 strings in pure Lua

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages