diff options
author | Philipp Gesang <phg42.2a@gmail.com> | 2013-09-03 04:28:56 -0700 |
---|---|---|
committer | Philipp Gesang <phg42.2a@gmail.com> | 2013-09-03 04:28:56 -0700 |
commit | 08311ca818df220f8e59fc0ff5835d18913daa89 (patch) | |
tree | 0274fb1094de1786db3a814346c95fab097259fb | |
parent | 3aacbae713dd9a3468578f56a75b74bb378a7de2 (diff) | |
parent | 5a4a4188ea6b7796cd4795c84866e8b0db553949 (diff) | |
download | lualibs-08311ca818df220f8e59fc0ff5835d18913daa89.tar.gz |
Merge pull request #17 from phi-gamma/master
sync with Context as of 2013-09-03
-rw-r--r-- | lualibs-dir.lua | 36 | ||||
-rw-r--r-- | lualibs-lpeg.lua | 10 | ||||
-rw-r--r-- | lualibs-unicode.lua | 12 |
3 files changed, 44 insertions, 14 deletions
diff --git a/lualibs-dir.lua b/lualibs-dir.lua index e47de60..40081cc 100644 --- a/lualibs-dir.lua +++ b/lualibs-dir.lua @@ -26,6 +26,8 @@ local isfile = lfs.isfile local currentdir = lfs.currentdir local chdir = lfs.chdir +local onwindows = os.type == "windows" or find(os.getenv("PATH"),";") + -- in case we load outside luatex if not isdir then @@ -136,11 +138,33 @@ end dir.collectpattern = collectpattern -local pattern = Ct { - [1] = (C(P(".") + P("/")^1) + C(R("az","AZ") * P(":") * P("/")^0) + Cc("./")) * V(2) * V(3), - [2] = C(((1-S("*?/"))^0 * P("/"))^0), - [3] = C(P(1)^0) -} +local separator + +if onwindows then -- we could sanitize here + +-- pattern = Ct { +-- [1] = (C(P(".") + S("/\\")^1) + C(R("az","AZ") * P(":") * S("/\\")^0) + Cc("./")) * V(2) * V(3), +-- [2] = C(((1-S("*?/\\"))^0 * S("/\\"))^0), +-- [3] = C(P(1)^0) +-- } + + local slash = S("/\\") / "/" + + pattern = Ct { + [1] = (Cs(P(".") + slash^1) + Cs(R("az","AZ") * P(":") * slash^0) + Cc("./")) * V(2) * V(3), + [2] = Cs(((1-S("*?/\\"))^0 * slash)^0), + [3] = Cs(P(1)^0) + } + +else -- assume unix + + pattern = Ct { + [1] = (C(P(".") + P("/")^1) + Cc("./")) * V(2) * V(3), + [2] = C(((1-S("*?/"))^0 * P("/"))^0), + [3] = C(P(1)^0) + } + +end local filter = Cs ( ( P("**") / ".*" + @@ -257,8 +281,6 @@ end local make_indeed = true -- false -local onwindows = os.type == "windows" or find(os.getenv("PATH"),";") - if onwindows then function dir.mkdirs(...) diff --git a/lualibs-lpeg.lua b/lualibs-lpeg.lua index b33df96..78b503b 100644 --- a/lualibs-lpeg.lua +++ b/lualibs-lpeg.lua @@ -109,11 +109,11 @@ local space = P(" ") local period = P(".") local comma = P(",") -local utfbom_32_be = P('\000\000\254\255') -local utfbom_32_le = P('\255\254\000\000') -local utfbom_16_be = P('\255\254') -local utfbom_16_le = P('\254\255') -local utfbom_8 = P('\239\187\191') +local utfbom_32_be = P('\000\000\254\255') -- 00 00 FE FF +local utfbom_32_le = P('\255\254\000\000') -- FF FE 00 00 +local utfbom_16_be = P('\254\255') -- FE FF +local utfbom_16_le = P('\255\254') -- FF FE +local utfbom_8 = P('\239\187\191') -- EF BB BF local utfbom = utfbom_32_be + utfbom_32_le + utfbom_16_be + utfbom_16_le + utfbom_8 diff --git a/lualibs-unicode.lua b/lualibs-unicode.lua index 813ffd5..cf0c93d 100644 --- a/lualibs-unicode.lua +++ b/lualibs-unicode.lua @@ -777,11 +777,19 @@ end local _, l_remap = utf.remapper(little) local _, b_remap = utf.remapper(big) +function utf.utf8_to_utf16_be(str) + return char(254,255) .. lpegmatch(b_remap,str) +end + +function utf.utf8_to_utf16_le(str) + return char(255,254) .. lpegmatch(l_remap,str) +end + function utf.utf8_to_utf16(str,littleendian) if littleendian then - return char(255,254) .. lpegmatch(l_remap,str) + return utf.utf8_to_utf16_le(str) else - return char(254,255) .. lpegmatch(b_remap,str) + return utf.utf8_to_utf16_be(str) end end |