ws-cleanup: shared helpers instead of copies (CRCs, codec arguments, utf8char, keyLess / isArray)
A sweep for duplicated function bodies, CRC tables and base64 across src/Formats: - core/Crc32.msb / MSB_TABLE: the MSB-first 0x04C11DB7 CRC-32 that containers/Ogg (Page + Mux), containers/MpegTs and codecs/Bzip2 each built (test vectors CRC-32/MPEG-2 and /BZIP2 in tests/core/bytes). - audio/flac/Encode uses audio/flac/Frame's CRC-8 / CRC-16 tables (Frame.crc8 added) instead of its own copy. - core/Bytes.toBuffer / Bytes.span: the (buffer | string, offset, length) argument checking codecs/Deflate, codecs/Lzma and codecs/Brotli each carried. - codecs/Text.utf8char: one copy instead of four (codecs/Json, codecs/Xml, data/yaml, data/toml). - Types.keyLess / Types.isArray (small additions to Types, backward compatible): data/msgpack, data/cbor and data/yaml/Emit had identical copies. - playlist/pls: dead copies of m3u's attributes / extinf removed. Left on purpose: per-codec bit readers / writers in hot loops (STYLE.md: inner loops keep their own bit buffers), same-folder helpers (Alac signExtend, Vorbis ilog), Zip's DOS-date civil() (a different epoch helper).
This commit is contained in:
1 parent
7169f2cc2c
commit
f784b4eb9b
22 files changed
+152
-311
No files matched your search
@@ -3,6 +3,7 @@
|
||||
-- their key order; arrays are arrays; datetimes are Types.Date values. Checks the 1.0 validity rules: UTF-8, control
|
||||
-- characters, table / key redefinition (explicit, implicit, dotted, inline and array-of-tables), number grammar and
|
||||
-- 64-bit range, escapes, datetimes. Never throws: failures return nil, message, offset (0-based).
|
||||
local Text = require("@formats/codecs/Text")
|
||||
local Types = require("@formats/Types")
|
||||
|
||||
local Decode = {}
|
||||
@@ -13,16 +14,7 @@ export type Options = {
|
||||
bigInts: ("number" | "string")?, -- integers beyond +-2^53: "string" keeps their digits (default "number")
|
||||
}
|
||||
|
||||
local function utf8char(c: number): string
|
||||
if c < 0x80 then
|
||||
return char(c)
|
||||
elseif c < 0x800 then
|
||||
return char(0xC0 + c // 64, 0x80 + c % 64)
|
||||
elseif c < 0x10000 then
|
||||
return char(0xE0 + c // 4096, 0x80 + (c // 64) % 64, 0x80 + c % 64)
|
||||
end
|
||||
return char(0xF0 + c // 262144, 0x80 + (c // 4096) % 64, 0x80 + (c // 64) % 64, 0x80 + c % 64)
|
||||
end
|
||||
local utf8char = Text.utf8char
|
||||
|
||||
local ESC: { [number]: string } = { [98] = "\b", [116] = "\t", [110] = "\n", [102] = "\f", [114] = "\r", [34] = '"', [92] = "\\" }
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ local Toml = {
|
||||
category = "data",
|
||||
extensions = { "toml" },
|
||||
mime = { "application/toml" },
|
||||
deps = { "core/Err", "core/Bytes", "Types", "codecs/Json" },
|
||||
deps = { "core/Err", "core/Bytes", "Types", "codecs/Json", "codecs/Text" },
|
||||
caps = { decode = true, encode = true, ordered = true, dates = true },
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user