cheatah
Module

parsers::json

Classes

Functions

fn std::string_view to_view(const Node &value) noexcept source#

Read a Node's characters when it is a string (either backing), else an empty view.

Parameters
value

the node to read.

Returns

the characters when value is a string (either backing), else an empty view.

Complexity

O(1).

Allocation

none

fn Document parse(std::string_view text, bool *ok=nullptr) source#

Parse text into a SELF-CONTAINED Document (owning containers AND owned strings — every string is copied, not a view), so the result is safe to return, cache, or outlive text.

For the zero-copy, source-viewing form (no string copies), reuse a Parser and call Parser::parse.

Validate is a COMPILE-TIME switch: the default (true) checks bounds/structure and rejects malformed input; parse<false>(...) strips every such check from the binary via if constexpr and does not write *ok — trusted, known-well-formed input only; malformed input is undefined behavior.

Parameters
text

the JSON source to parse.

ok

if non-null, set true on success and false on a parse error (written only when Validate is true).

Returns

the self-contained Document (JSON null on error when validating).

Complexity

O(n) in the input length.

Allocation

allocates the owned document tree (arrays, objects, and copied strings)

fn template Document parse< true >(std::string_view, bool *) source#
fn template Document parse< false >(std::string_view, bool *) source#
fn dump · 2 overloads
void dump(const Document &value, std::string &out)source#
std::string dump(const Document &value)source#

Serialize a Document by APPENDING to the caller's buffer — stream into a preallocated/reused std::string rather than allocating a fresh one.

This is the efficient path (push_back/append into one growing buffer); it deliberately avoids std::stringstream, which adds formatting, locale, and virtual-streambuf overhead per write. Reserve out once and reuse it across calls.

Parameters
value

the document to serialize.

out

the buffer the JSON text is appended to.

Complexity

O(output size).

Allocation

allocates the O(depth) frame stack; grows out only past its capacity.

fn bool read(std::string_view text, T &out) source#

Parse text directly into out (a struct with a schema<>, a supported scalar, std::vector, std::array, std::optional, or std::string/std::string_view).

Returns true on success. With Validate=true the input is fully checked (including no trailing junk); with Validate=false every bounds/structure check is compiled out for trusted, well-formed input (malformed input is then undefined behavior, and no success/trailing check is performed — it always returns true).

std::string fields OWN their characters (safe to outlive text); std::string_view fields VIEW text (which must then outlive out) and reject escaped strings.

Parameters
text

the JSON source to parse.

out

the value filled in place.

Returns

true on success; false when Validate is true and text is malformed or has trailing junk.

Complexity

O(n) in the input length.

Allocation

only the owned std::string fields / vector growth in out, plus a temporary key string when a key is escaped — no DOM, no Node tree.

fn Field< Class, Member > field(std::string_view name, Member Class::*ptr) noexcept source#

Build one key->member mapping.

Template parameters
Class

the struct type owning the member.

Member

the member's value type.

Parameters
name

the JSON object key.

ptr

pointer to the target data member.

Returns

the Field mapping.

Complexity

O(1) — constexpr aggregate construction.

Allocation

none.

fn ObjectSchema< Fields... > object(Fields... fs) noexcept source#

Bundle fields into a schema.

Template parameters
Fields

the Field types making up the schema.

Parameters
fs

the field mappings, in declaration order (cosmetic — matching is by name).

Returns

the ObjectSchema.

Complexity

O(1) — constexpr tuple construction.

Allocation

none.

fn String · 3 overloads
String(const char *) -> String< std::string_view >source#
String(std::string_view) -> String< std::string_view >source#
String(std::string) -> String< std::string >source#

Deduction guides — route each argument to the right storage.

A const char* and a std::string_view become VIEWS (never a std::string); an rvalue std::string is OWNED. These user-defined guides are preferred over the implicit one, so String{"lit"} deduces String<std::string_view>, not String<const char*>.

Complexity

O(1) — deduction is compile-time; the chosen constructor moves or views.

Allocation

none.

fn bool decode_escapes(std::string_view raw, std::string &out) source#

Decode the raw (escaped) inner bytes of a JSON string (scan.hpp's detail::decode_escapes).

Complexity

O(|raw|).

Allocation

output growth (reserved once up front).

fn bool match(Cursor &c, std::string_view lit) noexcept source#

Consume an exact literal like "true" if present, else leave the cursor put (detail::match).

Complexity

O(|literal|).

Allocation

none.

fn bool scan_string(Cursor &c, std::string_view &raw, bool &esc) source#

Scan a quoted string to its raw inner bytes + had-escapes flag (detail::scan_string).

Complexity

O(|string|) — SIMD, 32 bytes per step.

Allocation

none — the raw bytes are a view.

fn void skip_ws(Cursor &c) noexcept source#

Advance the cursor past JSON whitespace (detail::skip_ws over the SIMD skip).

Complexity

O(whitespace run).

Allocation

none.

Constants & variables

var std::size_t kMaxParseDepth source#
var no_schema schema source#
var auto schema<::cheatah::requests::Options > source#

JSON schema for Options, synthesized by purrc from the struct's fields — powers parsers.json.read into this type.

var auto schema<::cheatah::requests::Response > source#

JSON schema for Response, synthesized by purrc from the struct's fields — powers parsers.json.read into this type.

Types

type Node Document source#
type Array< std::vector< Node > > OwnedArray source#
type Array< std::span< const Node > > ArrayView source#
type Object< std::vector< Member > > OwnedObject source#
type Object< std::span< const Member > > ObjectView source#