Add std/json quirks

This commit is contained in:
Nigel Tao committed 2020-03-12 16:47:26 +11:00
1 parent d6fdfb133f
commit a3827275c0
5 files changed
+279 -12

No files matched your search

+17 -4
View File
@@ -14,6 +14,13 @@ For example, in an animated GIF image, the first frame might not fill out the
entire image, and different implementations choose a different default color
for the outside pixels: opaque black, transparent black, or something else.
Other file formats have unofficial extensions. For example, a strict reading of
the [JSON specification](https://json.org/) rejects an initial `"\x1E"` ASCII
Record Separator, `"// comments"` or commas after the final array element or
object key-value pair (e.g. `"[1,2,3,]"`), but
[some](https://www.ietf.org/rfc/rfc7464.txt) [extensions](https://json5.org) to
the format allow these and other changes.
Wuffs, out of the box, makes particular choices (typically mimicking the de
facto canonical implementation), but enabling various quirks results in
different choices. In particular, quirks are useful in regression testing that
@@ -28,12 +35,18 @@ convention](/doc/note/base38-and-fourcc.md). Decoders and encoders can have a
`set_quirk_enabled!(quirk base.u32, enabled base.bool)` method whose first
argument is this `uint32_t` value.
For example, the base38 encoding of `"gif "` is `0xF8586`, so that the
GIF-specific quirks have a `uint32_t` value of `((0xF8586 << 10) | n)`, for
some small integer `n`. The generated `C` language file defines human-readable
names for those constant values.
For example, the base38 encoding of `"gif "` and `"json"` is `0x0F8586` and
`0x124265` respectively, so that the GIF-specific quirks have a `uint32_t`
value of `((0x0F8586 << 10) | g)`, and the JSON-specific quirks have a
`uint32_t` value of `((0x124265 << 10) | j)`, for some small integers `g` and
`j`. The high bits are a namespace. The overall quirk values are different even
if `g` and `j` re-use the same 10-bit integer.
The generated `C` language file defines human-readable names for those constant
values, such as `WUFFS_JSON__QUIRK_ALLOW_LEADING_UNICODE_BYTE_ORDER_MARK`.
## Listing
- [GIF image decoder quirks](/std/gif/decode_quirks.wuffs)
- [JSON decoder quirks](/std/json/decode_quirks.wuffs)