Skip to content

Commit

Permalink
fix encode bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
starwing committed May 31, 2015
1 parent 5511745 commit 40b30bd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ in your codes :-(

LuaRocks Installation
---------------------
`luarocks install utf8`
`luarocks install luautf8`

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.
Expand Down
4 changes: 2 additions & 2 deletions lutf8lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ static size_t utf8_encode(char *s, unsigned ch) {
{
char buff[UTF8_MAX];
unsigned mfb = 0x3F; /* maximum that fits in first byte */
int n = 0;
int n = 1;
do { /* add continuation bytes */
buff[UTF8_MAX - (++n)] = 0x80 | (ch&0x3F);
buff[UTF8_MAX - (n++)] = 0x80 | (ch&0x3F);
ch >>= 6; /* remove added bits */
mfb >>= 1; /* now there is one less bit available in first byte */
} while (ch > mfb); /* still needs continuation byte? */
Expand Down
23 changes: 23 additions & 0 deletions rockspecs/luautf8-0.1.1-1.rockspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package = "luautf8"
version = "0.1.1-1"
source = {
url = "https://github.com/starwing/luautf8/archive/0.1.1.tar.gz",
dir = "luautf8-0.1.1"
}
description = {
summary = "A UTF-8 support module for Lua",
detailed = [[
This module adds UTF-8 support to Lua. It's compatible with Lua "string" module.
]],
homepage = "http://github.com/starwing/luautf8",
license = "MIT"
}
dependencies = {
"lua >= 5.1"
}
build = {
type = "builtin",
modules = {
["lua-utf8"] = "lutf8lib.c"
}
}

0 comments on commit 40b30bd

Please sign in to comment.