zserge / jsmn

Jsmn is a world fastest JSON parser/tokenizer. This is the official repo replacing the old one at Bitbucket
MIT License
3.72k stars 783 forks source link

Enhancements for feature macros #195

Open dominickpastore opened 4 years ago

dominickpastore commented 4 years ago

This PR does two things:

Details

More granular macros

This PR builds on the changes from PR #194. With PR #194, there are three specific ways in which non-strict mode diverges from RFC 8259:

  1. Primitives may contain any character except whitespace and those with special meaning in JSON ({}[],:").
  2. Strings may contain control characters (\x01 - \x1F) and invalid escape sequences
  3. Primitives may be used as object keys

Some projects using jsmn might want some of these features, but not all. For example, a project might want to enable (1) to improve performance or shrink code size, but leave (3) disabled to help catch bugs.

For this purpose, this PR creates three new macros: JSMN_PERMISSIVE_PRIMITIVES for (1), JSMN_PERMISSIVE_STRINGS for (2), and JSMN_PRIMITIVE_KEYS for (3). These can be defined individually, or defining JSMN_NON_STRICT will cause all to be defined.

Enable strict mode and parent links by default

With this PR, strict RFC 8259 compliance and parent links become the default behavior. New macros JSMN_LOW_MEMORY and JSMN_NON_STRICT disable these behaviors.

JSMN_PARENT_LINKS still exists, but is defined by default unless JSMN_LOW_MEMORY is defined.

JSMN_NON_STRICT replaces JSMN_STRICT. When defined, all non-strict features are enabled.

dominickpastore commented 4 years ago

Apologize for the history rewriting. Rebased onto the latest commits from PR #194.