Skip to content

Commit d83006c

Browse files
committed
Add JSON5 flags (unimplemented)
1 parent 04b30db commit d83006c

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

src/yyjson.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,57 @@ static const yyjson_read_flag YYJSON_READ_ALLOW_BOM = 1 << 8;
779779

780780

781781

782+
/* -----Unimplemented----- */
783+
784+
/** Allow extended number formats (non-standard):
785+
- Hexadecimal numbers, such as `0x7B`.
786+
- Numbers with leading or trailing decimal point, such as `.123`, `123.`.
787+
- Numbers with a leading plus sign, such as `+123`. */
788+
static const yyjson_read_flag YYJSON_READ_ALLOW_EXT_NUMBER = 1 << 9;
789+
790+
/** Allow extended escape sequences in strings (non-standard):
791+
- Additional escapes: `\a`, `\e`, `\v`, `\'`, `\?`, `\0`-`\9`.
792+
- Hex escapes: `\xNN`, such as `\x7B`.
793+
- Line continuation: backslash followed by line terminator sequences.
794+
- Unknown escape: if backslash is followed by an unsupported character,
795+
the backslash will be removed and the character will be kept as-is.
796+
*/
797+
static const yyjson_read_flag YYJSON_READ_ALLOW_EXT_ESCAPE = 1 << 10;
798+
799+
/** Allow extended whitespace characters (non-standard):
800+
- Vertical tab `\v` and form feed `\f`.
801+
- Line separator `\u2028` and paragraph separator `\u2029`.
802+
- Non-breaking space `\xA0`.
803+
- Byte order mark: `\uFEFF`.
804+
- Other Unicode characters in the Zs (Separator, space) category. */
805+
static const yyjson_read_flag YYJSON_READ_ALLOW_EXT_WHITESPACE = 1 << 11;
806+
807+
/** Allow strings enclosed in single quotes (non-standard),
808+
such as `'abc'`. */
809+
static const yyjson_read_flag YYJSON_READ_ALLOW_SINGLE_QUOTED_STR = 1 << 12;
810+
811+
/** Allow object keys without quotes (non-standard),
812+
such as `{a:1,b:2}`. */
813+
static const yyjson_read_flag YYJSON_READ_ALLOW_UNQUOTED_KEY = 1 << 13;
814+
815+
/** Allow JSON5 format, see: https://json5.org and https://spec.json5.org
816+
817+
This flag supports all JSON5 features with some additional extensions:
818+
- Accepts more escape sequences than JSON5 (e.g. `\a`, `\e`).
819+
- Unquoted keys are and not limited to ECMAScript IdentifierName.
820+
- The `Inf`, `Infinity` and `NaN` literals are case-insensitive. */
821+
static const yyjson_read_flag YYJSON_READ_JSON5 =
822+
YYJSON_READ_ALLOW_COMMENTS |
823+
YYJSON_READ_ALLOW_TRAILING_COMMAS |
824+
YYJSON_READ_ALLOW_INF_AND_NAN |
825+
YYJSON_READ_ALLOW_EXT_NUMBER |
826+
YYJSON_READ_ALLOW_EXT_ESCAPE |
827+
YYJSON_READ_ALLOW_EXT_WHITESPACE |
828+
YYJSON_READ_ALLOW_SINGLE_QUOTED_STR |
829+
YYJSON_READ_ALLOW_UNQUOTED_KEY;
830+
831+
832+
782833
/** Result code for JSON reader. */
783834
typedef uint32_t yyjson_read_code;
784835

0 commit comments

Comments
 (0)