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.

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.

On success *ok is set true; on malformed input *ok is set false and the result is JSON null. 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) does full bounds/structure checking and rejects malformed input; parse<false>(...) strips every such check from the binary via if constexpr (see the Parser docs) and does not write *ok — for trusted, known-well-formed input only, as feeding it malformed input is undefined behavior.

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.

Complexity

O(nodes)

Allocation

none of its own (grows out only if its capacity is exceeded)

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.

Complexity

O(n) in the input length

Allocation

only the owned std::string fields / vector growth in out — 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#