diff options
-rw-r--r-- | lualibs-table.lua | 21 | ||||
-rw-r--r-- | lualibs-unicode.lua | 22 | ||||
-rw-r--r-- | lualibs-util-prs.lua | 4 |
3 files changed, 38 insertions, 9 deletions
diff --git a/lualibs-table.lua b/lualibs-table.lua index 11cb66b..c6bbc62 100644 --- a/lualibs-table.lua +++ b/lualibs-table.lua @@ -1054,3 +1054,24 @@ function table.sorted(t,...) sort(t,...) return t -- still sorts in-place end + +-- + +function table.values(t,s) -- optional sort flag + if t then + local values, keys, v = { }, { }, 0 + for key, value in next, t do + if not keys[value] then + v = v + 1 + values[v] = value + keys[k] = key + end + end + if s then + sort(values) + end + return values + else + return { } + end +end diff --git a/lualibs-unicode.lua b/lualibs-unicode.lua index 7ada394..902f6a0 100644 --- a/lualibs-unicode.lua +++ b/lualibs-unicode.lua @@ -935,19 +935,27 @@ 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) +function utf.utf8_to_utf16_be(str,nobom) + if nobom then + return lpegmatch(b_remap,str) + else + return char(254,255) .. lpegmatch(b_remap,str) + end end -function utf.utf8_to_utf16_le(str) - return char(255,254) .. lpegmatch(l_remap,str) +function utf.utf8_to_utf16_le(str,nobom) + if nobom then + return lpegmatch(l_remap,str) + else + return char(255,254) .. lpegmatch(l_remap,str) + end end -function utf.utf8_to_utf16(str,littleendian) +function utf.utf8_to_utf16(str,littleendian,nobom) if littleendian then - return utf.utf8_to_utf16_le(str) + return utf.utf8_to_utf16_le(str,nobom) else - return utf.utf8_to_utf16_be(str) + return utf.utf8_to_utf16_be(str,nobom) end end diff --git a/lualibs-util-prs.lua b/lualibs-util-prs.lua index 29a57e0..9518b7f 100644 --- a/lualibs-util-prs.lua +++ b/lualibs-util-prs.lua @@ -483,8 +483,8 @@ function parsers.rfc4180splitter(specification) * Cs((dquotechar + (1 - quotechar))^0) * quotechar local non_escaped = C((1 - quotechar - newline - separator)^1) - local field = escaped + non_escaped - local record = Ct((field * separator^-1)^1) + local field = escaped + non_escaped + Cc("") + local record = Ct(field * (separator * field)^1) local headerline = record * Cp() local wholeblob = Ct((newline^-1 * record)^0) return function(data,getheader) |