Version 7.0
Copyright © 2021 Lowell D. Thomas
APG
… an ABNF Parser Generator
Data Structures | Functions
builder.c File Reference

The JSON builder object. More...

#include "json.h"
#include "jsonp.h"
#include "./json-grammar.h"
Include dependency graph for builder.c:

Go to the source code of this file.

Data Structures

struct  counts
 Internal workings only. Don't worry about it. More...
 
struct  nexts
 Internal workings only. Don't worry about it. More...
 
struct  bvalue
 A builder value. Internal workings only. Don't worry about it. More...
 
struct  build
 The builder object context. More...
 

Functions

void * vpJsonBuildCtor (void *vpJsonCtx)
 The builder object constructor. More...
 
void vJsonBuildDtor (void *vpBuildCtx)
 The builder object destructor. More...
 
void vJsonBuildClear (void *vpBuildCtx)
 Clears all memory associated with this builder object. More...
 
aint uiJsonBuildMakeStringU (void *vpBuildCtx, const uint32_t *uipData, aint uiLength)
 Make a string value from UTF-32 code points. More...
 
aint uiJsonBuildMakeStringA (void *vpBuildCtx, const char *cpString)
 Make a string value from a null-terminated ASCII string. More...
 
aint uiJsonBuildMakeNumberF (void *vpBuildCtx, double dNumber)
 Make a JSON floating point number value. More...
 
aint uiJsonBuildMakeNumberS (void *vpBuildCtx, int64_t iNumber)
 Make a JSON signed integer number value. More...
 
aint uiJsonBuildMakeNumberU (void *vpBuildCtx, uint64_t uiNumber)
 Make a JSON unsigned integer number value. More...
 
aint uiJsonBuildMakeTrue (void *vpBuildCtx)
 Make a JSON true value. More...
 
aint uiJsonBuildMakeFalse (void *vpBuildCtx)
 Make a JSON false value. More...
 
aint uiJsonBuildMakeNull (void *vpBuildCtx)
 Make a JSON null value. More...
 
aint uiJsonBuildMakeObject (void *vpBuildCtx)
 Make a JSON object value. More...
 
aint uiJsonBuildMakeArray (void *vpBuildCtx)
 Makea JSON array value. More...
 
aint uiJsonBuildAddToObject (void *vpBuildCtx, aint uiObject, aint uiKey, aint uiAdd)
 Add a child value to a parent object value. More...
 
aint uiJsonBuildAddToArray (void *vpBuildCtx, aint uiArray, aint uiAdd)
 Add a child value to a parent array value. More...
 
void * vpJsonBuild (void *vpBuildCtx, aint uiRoot)
 Build the JSON object. More...
 

Detailed Description

The JSON builder object.

A suite of functions for building a tree of JSON values.

Definition in file builder.c.

Function Documentation

◆ uiJsonBuildAddToArray()

aint uiJsonBuildAddToArray ( void *  vpBuildCtx,
aint  uiArray,
aint  uiAdd 
)

Add a child value to a parent array value.

Parameters
vpBuildCtxA context pointer returned from a previous call to vpJsonBuildCtor(). Silently exits the application with exit code BAD_CONTEXT if pointer is invalid.
uiArrayThe parent array value to add a child value to. The return index from uiJsonBuildMakeArray().
uiAddThe index of the value to add as a child of uiParent.
Returns
Returns an index reference to the created value. Exception thrown on fatal error.

Definition at line 550 of file builder.c.

◆ uiJsonBuildAddToObject()

aint uiJsonBuildAddToObject ( void *  vpBuildCtx,
aint  uiObject,
aint  uiKey,
aint  uiAdd 
)

Add a child value to a parent object value.

Parameters
vpBuildCtxA context pointer returned from a previous call to vpJsonBuildCtor(). Silently exits the application with exit code BAD_CONTEXT if pointer is invalid.
uiObjectThe parent object value to add a child value to. The return index from uiJsonBuildMakeObject().
uiKeyMust the index of a string object defining the object's member key.
e.g. uiKey = uiJsonBuilderStringA(vpBuildCtx, "my key");
uiAddThe index of the value to add as a child of uiParent.
Returns
Returns an index reference to the created value. Exception thrown on fatal error.

Definition at line 479 of file builder.c.

◆ uiJsonBuildMakeArray()

aint uiJsonBuildMakeArray ( void *  vpBuildCtx)

Makea JSON array value.

Parameters
vpBuildCtxA context pointer returned from a previous call to vpJsonBuildCtof(); Silently exits the application with exit code BAD_CONTEXT if pointer is invalid.
Returns
Returns an index reference to the created value.

Definition at line 459 of file builder.c.

◆ uiJsonBuildMakeFalse()

aint uiJsonBuildMakeFalse ( void *  vpBuildCtx)

Make a JSON false value.

Parameters
vpBuildCtxA context pointer returned from a previous call to vpJsonBuildCtof(); Silently exits the application with exit code BAD_CONTEXT if pointer is invalid.
Returns
Returns an index reference to the created value.

Definition at line 417 of file builder.c.

◆ uiJsonBuildMakeNull()

aint uiJsonBuildMakeNull ( void *  vpBuildCtx)

Make a JSON null value.

Parameters
vpBuildCtxA context pointer returned from a previous call to vpJsonBuildCtof(); Silently exits the application with exit code BAD_CONTEXT if pointer is invalid.
Returns
Returns an index reference to the created value.

Definition at line 431 of file builder.c.

◆ uiJsonBuildMakeNumberF()

aint uiJsonBuildMakeNumberF ( void *  vpBuildCtx,
double  dNumber 
)

Make a JSON floating point number value.

Parameters
vpBuildCtxA context pointer returned from a previous call to vpJsonBuildCtor(). Silently exits the application with exit code BAD_CONTEXT if pointer is invalid.
dNumberThe floating point number to make a JSON value from.
Returns
Returns an index reference to the created value.

Definition at line 336 of file builder.c.

◆ uiJsonBuildMakeNumberS()

aint uiJsonBuildMakeNumberS ( void *  vpBuildCtx,
int64_t  iNumber 
)

Make a JSON signed integer number value.

Parameters
vpBuildCtxA context pointer returned from a previous call to vpJsonBuildCtor(). Silently exits the application with exit code BAD_CONTEXT if pointer is invalid.
iNumberThe signed integer to make a JSON value from. If iNumber >= 0, an unsigned integer value will be created.
Returns
Returns an index reference to the created value.

Definition at line 358 of file builder.c.

◆ uiJsonBuildMakeNumberU()

aint uiJsonBuildMakeNumberU ( void *  vpBuildCtx,
uint64_t  uiNumber 
)

Make a JSON unsigned integer number value.

Parameters
vpBuildCtxA context pointer returned from a previous call to vpJsonBuildCtor(). Silently exits the application with exit code BAD_CONTEXT if pointer is invalid.
uiNumberThe unsigned integer to make a JSON value from.
Returns
Returns an index reference to the created value.

Definition at line 383 of file builder.c.

◆ uiJsonBuildMakeObject()

aint uiJsonBuildMakeObject ( void *  vpBuildCtx)

Make a JSON object value.

Parameters
vpBuildCtxA context pointer returned from a previous call to vpJsonBuildCtor(). Silently exits the application with exit code BAD_CONTEXT if pointer is invalid.
Returns
Returns an index reference to the created value.

Definition at line 445 of file builder.c.

◆ uiJsonBuildMakeStringA()

aint uiJsonBuildMakeStringA ( void *  vpBuildCtx,
const char *  cpString 
)

Make a string value from a null-terminated ASCII string.

Note that the input is raw UTF-32, 32-bit code points.

Note that the input must be a valid RFC8259-compliant string. Be especially careful since the input argument is a C-language string which must result in a RFC8259-compliant string. In particular, this means the the reverse solidus, "\", must always be escaped. For example:

  • intended JSON string: "I want a line feed, \n, a quote, \", and the Unicode code point \u00FF." - C-language string input: "I want a line feed, \n, a quote, \", and the Unicode code point \\u00FF."

Also note that this means the characters 0x00-0x1F must be escaped, e.g. \u0000 or \u00FF, and that characters 0x80-0xFF must be either escaped or UTF-8 encoded. Example, the character value 0xFF can be input with either of these C-language strings.

  • "\\u00FF" or
  • "\xC3\xBF"
Parameters
vpBuildCtxA context pointer returned from a previous call to vpJsonBuildCtor(). Silently exits the application with exit code BAD_CONTEXT if pointer is invalid.
cpStringPointer to the string to make into a value. String may be empty but not NULL.
Returns
Returns an index reference to the created value. Exception thrown on fatal error.

Definition at line 283 of file builder.c.

◆ uiJsonBuildMakeStringU()

aint uiJsonBuildMakeStringU ( void *  vpBuildCtx,
const uint32_t *  uipData,
aint  uiLength 
)

Make a string value from UTF-32 code points.

Note that the input is raw UTF-32, 32-bit code points.

Parameters
vpBuildCtxA context pointer returned from a previous call to vpJsonBuildCtor(). Silently exits the application with exit code BAD_CONTEXT if pointer is invalid.
uipDataPointer to the array of Unicode UTF-32 code points. May be NULL for empty array (uiLength ignored.)
uiLengthThe number of code points in the array. May be zero.
Returns
Returns an index reference to the created value. Exception thrown on fatal error.

Definition at line 223 of file builder.c.

◆ uiJsonBuildMakeTrue()

aint uiJsonBuildMakeTrue ( void *  vpBuildCtx)

Make a JSON true value.

Parameters
vpBuildCtxA context pointer returned from a previous call to vpJsonBuildCtor(). Silently exits the application with exit code BAD_CONTEXT if pointer is invalid.
Returns
Returns an index reference to the created value.

Definition at line 403 of file builder.c.

◆ vJsonBuildClear()

void vJsonBuildClear ( void *  vpBuildCtx)

Clears all memory associated with this builder object.

Reset this object for building a new value tree.

Parameters
vpBuildCtxA context pointer returned from a previous call to vpJsonBuildCtor(). Silently exits the application with exit code BAD_CONTEXT if pointer is invalid.

Definition at line 184 of file builder.c.

◆ vJsonBuildDtor()

void vJsonBuildDtor ( void *  vpBuildCtx)

The builder object destructor.

Frees all memory allocations associated with this object. Note however, that vJsonDtor(), the parent object destructor, will free all memory associated with this builder object,

Parameters
vpBuildCtxA context pointer returned from a previous call to vpJsonBuildCtor(). Silently exits the application with exit code BAD_CONTEXT if pointer is invalid.

Definition at line 154 of file builder.c.

◆ vpJsonBuild()

void* vpJsonBuild ( void *  vpBuildCtx,
aint  uiRoot 
)

Build the JSON object.

Build a tree of values, from the collection of values "added" with uiJsonBuilderAdd() calls.

Parameters
vpBuildCtxA context pointer returned from a previous call to vpJsonBuildCtor(). Silently exits the application with exit code BAD_CONTEXT if pointer is invalid.
uiRootIndex of the value to use as the tree root. Must be a return value from one of the uiJsonBuildMake...() functions.
Returns
Pointer to an iterator over the built tree of values.

Definition at line 603 of file builder.c.

◆ vpJsonBuildCtor()

void* vpJsonBuildCtor ( void *  vpJsonCtx)

The builder object constructor.

Parameters
vpJsonCtx- Pointer to a valid JSON object previously created with vpJsonCtor(). Silently exits the application with exit code BAD_CONTEXT if pointer is invalid.
Returns
Pointer to the buider object context. If NULL, a memory allocation error has occurred.

Definition at line 124 of file builder.c.

APG Version 7.0 is licensed under the 2-Clause BSD License,
an Open Source Initiative Approved License.