在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):starwing/luautf8开源软件地址(OpenSource Url):https://github.com/starwing/luautf8开源编程语言(OpenSource Language):C 81.1%开源软件介绍(OpenSource Introduction):UTF-8 module for Lua 5.xThis module adds UTF-8 support to Lua. It use data extracted from Unicode Character Database, and tested on Lua 5.2.3, Lua 5.3.0 and LuaJIT. parseucd.lua is a pure Lua script generate unidata.h, to support convert characters and check characters' category. It mainly used to compatible with Lua's own string module, it passed all string and pattern matching test in lua test suite2. It also add some useful routines against UTF-8 features, some like:
Note that to avoid conflict with the Lua5.3's buitin library 'utf8', this library produce a file like lua-utf8.dll or lua-utf8.so. so use it like this: local utf8 = require 'lua-utf8' in your codes :-( LuaRocks Installation
It's now full-compatible with Lua5.3's utf8 library, so replace this file (and headers) with lua5.3 source's lutf8lib.c is also okay. UsageMany routines are same as Lua's string module:
The document of these functions can be find in Lua manual3. Some routines in string module needn't support Unicode:
They are NOT in utf8 module. Some routines are the compatible for Lua 5.3's basic UTF-8 support library:
See Lua5.3's manual to get usage. Some routines are new, with some Unicode-spec functions: utf8.escape(str) -> utf8 stringescape a str to UTF-8 format string. It support several escape format:
Examples:local u = utf8.escape
print(u"%123%u123%{123}%u{123}%xABC%x{ABC}")
print(u"%%123%?%d%%u") utf8.charpos(s[[, charpos], index]) -> charpos, code pointconvert UTF-8 position to byte offset.
if only utf8.next(s[, charpos[, index]]) -> charpos, code pointiterate though the UTF-8 string s. If only s is given, it can used as a iterator: for pos, code in utf8.next, "utf8-string" do
-- ...
end if only utf8.insert(s[, idx], substring) -> new_stringinsert a substring to s. If idx is given, insert substring before char at this index, otherwise substring will concat to s. idx can be negative. utf8.remove(s[, start[, stop]]) -> new_stringdelete a substring in s. If neither start nor stop is given, delete the last UTF-8 char in s, otherwise delete char from start to end of s. if stop is given, delete char from start to stop (include start and stop). start and stop can be negative. utf8.width(s[, ambi_is_double[, default_width]]) -> widthcalculate the width of UTF-8 string s. if ambi_is_double is given, the ambiguous width character's width is 2, otherwise it's 1. fullwidth/doublewidth character's width is 2, and other character's width is 1. if default_width is given, it will be the width of unprintable character, used display a non-character mark for these characters. if s is a code point, return the width of this code point. utf8.widthindex(s, location[, ambi_is_double[, default_width]]) -> idx, offset, widthreturn the character index at given location in string s. this is a reverse operation of utf8.width(). this function return a index of location, and a offset in in UTF-8 encoding. e.g. if cursor is at the second column (middle) of the wide char, offset will be 2. the width of character at idx is returned, also. utf8.title(s) -> new_stringutf8.fold(s) -> new_stringconvert UTF-8 string s to title-case, or folded case used to compare by ignore case. if s is a number, it's treat as a code point and return a convert code point (number). utf8.lower/utf8.upper has the same extension. utf8.ncasecmp(a, b) -> [-1,0,1]compare a and b without case, -1 means a < b, 0 means a == b and 1 means a > b. Improvement needed
LicenseIt use same license with Lua: http://www.lua.org/license.html |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论