xchange v0.9
Structured data exchange for C/C++
|
Macros | |
#define | NULLDEV "/dev/null" |
null device on system | |
#define | XJSON_INDENT " " |
Indentation for nested elements. | |
Functions | |
char * | xjsonEscapeString (const char *src, int maxLength) |
int | xjsonGetIndent () |
XStructure * | xjsonParseAt (char **src, int *lineNumber) |
XStructure * | xjsonParseFile (FILE *file, size_t length, int *lineNumber) |
XStructure * | xjsonParseFilename (const char *fileName, int *lineNumber) |
void | xjsonSetErrorStream (FILE *fp) |
void | xjsonSetIndent (int nchars) |
char * | xjsonToString (const XStructure *s) |
char * | xjsonUnescapeString (const char *json) |
A set of functions for parsing and creating JSON description of data.
char * xjsonEscapeString | ( | const char * | src, |
int | maxLength | ||
) |
Converts a native string to its JSON representation.
src | Pointer to the native (unescaped) string, which may contain special characters. |
maxLength | The number of characters in the input string if not terminated, or <=0 if always teminated arbitrary length string. |
References x_error(), X_SUCCESS, and x_trace_null().
int xjsonGetIndent | ( | ) |
Returns the number of spaces per indentation when emitting JSON formatted output.
XStructure * xjsonParseAt | ( | char ** | pos, |
int * | lineNumber | ||
) |
Parses a JSON object from the given parse position, returning the structured data and updating the parse position. Parse errors are reported to stderr or the alternate stream set by xSetErrorStream().
[in,out] | pos | Pointer to current parse position, which will be updated to point to after the last character consumed by the JSON parser. |
[out] | lineNumber | Optional pointer that holds a line number of the parse position, or NULL if not required. Line numbers may be useful to report where the parser run into an error if the parsing failed. Line numbers start at 1, and are counted from the initial parse position. |
References x_error().
XStructure * xjsonParseFile | ( | FILE * | fp, |
size_t | length, | ||
int * | lineNumber | ||
) |
Parses a JSON object from the current position in a file, returning the described structured data. Parse errors are reported to stderr or the alternate stream set by xSetErrorStream().
[in] | fp | File pointer, opened with read permission ("r"). |
[in] | length | [bytes] The number of bytes to parse / available, or 0 to read to the end of the file. (In the latter case the file must support fseek with SEEK_END to automatically determine the length, or else this function will return NULL). |
[out] | lineNumber | Optional pointer that holds a line number of the parse position, or NULL if not required. Line numbers may be useful to report where the parser run into an error if the parsing failed. Line numbers start at 1, and are counted from the initial parse position. |
References x_error().
XStructure * xjsonParseFilename | ( | const char * | fileName, |
int * | lineNumber | ||
) |
Parses a JSON object from the beginning of a file, returning the described structured data. Parse errors are reported to stderr or the alternate stream set by xSetErrorStream().
[in] | fileName | File name/path to parse. |
[out] | lineNumber | Optional pointer that holds a line number of the parse position, or NULL if not required. Line numbers may be useful to report where the parser run into an error if the parsing failed. Line numbers start at 1, and are counted from the initial parse position. |
References x_error(), xIsVerbose(), and xjsonParseFile().
void xjsonSetErrorStream | ( | FILE * | fp | ) |
void xjsonSetIndent | ( | int | nchars | ) |
Sets the number of spaces per indentation when emitting JSON formatted output.
nchars | (bytes) the new number of white space character of indentation to use. Negative values map to 0. |
char * xjsonToString | ( | const XStructure * | s | ) |
Converts structured data into its JSON representation. Conversion errors are reported to stderr or the altenate stream set by xSetErrorStream().
s | Pointer to structured data |
References FALSE, x_error(), X_NULL, and xErrorDescription().
char * xjsonUnescapeString | ( | const char * | str | ) |
Converts a an escaped string in JSON representation to a native string
str | The JSON representation of the string, in which special characters appear in escaped form (without the surrounding double quotes). |
References x_error().