rename: src/Formats -> src/Rosetta, @formats -> @rosetta requires, build/luajit/rosetta + rosetta._compat, build/roblox/Rosetta, ROSETTA_* env/globals, writer vendor strings

This commit is contained in:
4DBug committed 2026-11-01 01:19:16 -05:00
1 parent 2956576d7f
commit 22ddcd78fa
941 files changed
+3364 -3364

No files matched your search

+36
View File
@@ -0,0 +1,36 @@
--!strict
-- core/Sniff: helpers for the formats' sniff functions (which return 0..1 from the first bytes, never consuming and
-- never throwing): magic comparison and the start of a text file without its UTF-8 byte order mark.
--
-- function Qoi.sniff(r) return Sniff.magic(r, "qoif") end -- 1 or 0
-- function Gz.sniff(r) return Sniff.magic(r, "\31\139\8", 0, 0.9) end -- a custom score
-- local head = Sniff.text(r, 64) -- the first 64 bytes, BOM dropped
-- local head = Sniff.text(r, 512, true) -- ... and leading whitespace too
-- local text = Sniff.dropBom(whole) -- decoders: the BOM off a whole file
local Sniff = {}
type Peeker = { peek: (any, number, number?) -> string }
-- magic(r, s, at?, score?) -> score (default 1) when the bytes at offset at (default 0) are s, else 0
function Sniff.magic(r: Peeker, s: string, at: number?, score: number?): number
return if r:peek(#s, at) == s then score or 1 else 0
end
-- dropBom(s) -> s without a leading UTF-8 byte order mark (for decoders reading a whole text file)
function Sniff.dropBom(s: string): string
return if string.sub(s, 1, 3) == "\239\187\191" then string.sub(s, 4) else s
end
-- text(r, n, trim?) -> up to n bytes from the start without a UTF-8 BOM (and leading whitespace when trim)
function Sniff.text(r: Peeker, n: number, trim: boolean?): string
local s = r:peek(n)
if string.sub(s, 1, 3) == "\239\187\191" then
s = string.sub(s, 4)
end
if trim then
s = string.match(s, "^%s*(.*)$") :: string
end
return s
end
return Sniff