module watt.json.util

Useful functions when dealing with JSON.

The watt.json.sax parser doesn't process any of the output it gives. Use these functions to get data from what it gives you.

Code Map

//! Useful functions when dealing with JSON.
module watt.json.util;


//! Base Exception for the whole json package.
class JSONException : Exception
{
public:
	this(msg: string, location: string) { }
}

//! Exception thrown when an error occurs during parsing.
class ParseException : JSONException
{
public:
	this(msg: string, location: string) { }
}

fn canBeInteger(data: const(char)[], signed: bool) bool { }
//! Parse a u64 from a JSON number string.
fn parseUlong(data: const(char)[], l: u64) bool { }
//! Parse an i64 from a JSON number string. Returns true if a double was
//! parsed.
fn parseLong(data: const(char)[], l: i64) bool { }
//! Parse a double from a JSON number string.
fn parseDouble(data: const(char)[], d: f64) bool { }
//! Parse a double from a JSON number string, using a pre allocated
//! buffer, resizing it if needed.
fn parseDouble(data: const(char)[], d: f64, buffer: char[]) bool { }
fn parseBool(data: const(char)[]) bool { }
//! Unescape a JSON string and return it.
fn unescapeString(str: const(char)[]) const(char)[] { }
//! Unescape a JSON string and return it.
fn unescapeString(str: const(u8)[]) const(char)[] { }
//! Unescape a JSON string and return it, using a pre allocated buffer and
//! resizing it if needed.
fn unescapeString(str: const(char)[], buffer: char[]) const(char)[] { }
//! Escape a JSON string and return it.
fn escapeString(str: const(char)[]) const(char)[] { }
//! Escape a JSON string and return it, using a pre allocated buffer and
//! resizing it if needed.
fn escapeString(str: const(char)[], buffer: char[]) const(char)[] { }
class JSONException : Exception

Base Exception for the whole json package.

class ParseException : JSONException

Exception thrown when an error occurs during parsing.

fn canBeInteger(data: const(char)[], signed: bool) bool

Parameters

data
signed

If false, '-' will make this function return false.

Return

true if data contains a non-digit character.

fn parseUlong(data: const(char)[], l: u64) bool

Parse a u64 from a JSON number string.

Return

true if a double was parsed.

fn parseLong(data: const(char)[], l: i64) bool

Parse an i64 from a JSON number string. Returns true if a double was parsed.

fn parseDouble(data: const(char)[], d: f64) bool

Parse a double from a JSON number string.

Returns true if a double was parsed, false otherwise.

fn parseDouble(data: const(char)[], d: f64, buffer: char[]) bool

Parse a double from a JSON number string, using a pre allocated buffer, resizing it if needed.

Return

true if a double was parsed.

fn parseBool(data: const(char)[]) bool

Return

the boolean value of a string.

fn unescapeString(str: const(char)[]) const(char)[]

Unescape a JSON string and return it.

fn unescapeString(str: const(char)[], buffer: char[]) const(char)[]

Unescape a JSON string and return it, using a pre allocated buffer and resizing it if needed.

fn escapeString(str: const(char)[]) const(char)[]

Escape a JSON string and return it.

fn escapeString(str: const(char)[], buffer: char[]) const(char)[]

Escape a JSON string and return it, using a pre allocated buffer and resizing it if needed.