Simpleson
Classes | Functions
json::parsing Namespace Reference

Namespace used for JSON parsing functions. More...

Classes

struct  parse_results
 Structure for capturing the results of parsing. More...
 

Functions

const char * tlws (const char *start)
 (t)rims (l)eading (w)hite (s)pace More...
 
std::string read_digits (const char *input)
 Reads a set of digits from a string. More...
 
std::string decode_string (const char *input)
 Decodes a string in JSON format. More...
 
std::string encode_string (const char *input)
 Encodes a string in JSON format. More...
 
parse_results parse (const char *input)
 Parses the first value encountered in a JSON string. More...
 
template<typename T >
get_number (const char *input, const char *format)
 Template for reading a numeric value. More...
 
template<typename T >
std::string get_number_string (const T &number, const char *format)
 Converts a number to a string. More...
 
std::vector< std::string > parse_array (const char *input)
 Parses a JSON array. More...
 

Detailed Description

Namespace used for JSON parsing functions.

Function Documentation

◆ decode_string()

std::string json::parsing::decode_string ( const char *  input)

Decodes a string in JSON format.

The quotation mark ("), reverse solidus (\‍), solidus (/), backspace (b), formfeed (f), linefeed (n), carriage return (r), horizontal tab (t), and Unicode character will be unescaped @param input A string, encapsulated in quotations ("), potentially containing escaped control characters

Returns
A string with control characters un-escaped
Note
This function will strip leading and trailing quotations.
See also
encode_string

◆ encode_string()

std::string json::parsing::encode_string ( const char *  input)

Encodes a string in JSON format.

The quotation mark ("), reverse solidus (), solidus (/), backspace (b), formfeed (f), linefeed (n), carriage return (r), horizontal tab (t), and Unicode character will be escaped

Parameters
inputA string potentially containing control characters
Returns
A string that has all control characters escaped with a reverse solidus ()
Note
This function will add leading and trailing quotations.
See also
decode_string

◆ get_number()

template<typename T >
T json::parsing::get_number ( const char *  input,
const char *  format 
)

Template for reading a numeric value.

Template Parameters
TThe C data type the input will be convered to
Parameters
inputThe string to conver to a number
formatThe format to use when converting the string to a number
Returns
The numeric value contained by the input

◆ get_number_string()

template<typename T >
std::string json::parsing::get_number_string ( const T &  number,
const char *  format 
)

Converts a number to a string.

Template Parameters
TheC data type of the number to be converted
Parameters
numberA reference to the number to be converted
formatThe format to be used when converting the number
Returns
A string representation of the input number

◆ parse()

json::parsing::parse_results json::parsing::parse ( const char *  input)

Parses the first value encountered in a JSON string.

Parameters
inputThe string to be parsed
Returns
Details regarding the first value encountered
Exceptions
json::parsing_errorException thrown when the input is not valid JSON

◆ parse_array()

std::vector< std::string > json::parsing::parse_array ( const char *  input)

Parses a JSON array.

Converts a serialized JSON array into a vector of the values in the array

Parameters
inputThe serialized JSON array
Returns
A vector containing each element of the array with each element being serialized JSON

◆ read_digits()

std::string json::parsing::read_digits ( const char *  input)

Reads a set of digits from a string.

This function will take an input string and read the digits at the front of the string until a character other than a digit (0-9) is encountered.

Parameters
inputA string that starts with a set of digits (0-9)
Returns
A string containing the digits

◆ tlws()

const char * json::parsing::tlws ( const char *  start)

(t)rims (l)eading (w)hite (s)pace

Given a string, returns a pointer to the first character that is not white space. Spaces, tabs, and carriage returns are all considered white space.

Parameters
startThe string to examine
Returns
A pointer within the input string that points at the first charactor that is not white space
Note
If the string consists of entirely white space, then the null terminator is returned
Warning
The behavior of this function with string that is not null-terminated is undefined