Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

sobj_text.c File Reference


Detailed Description

Text serialization and de-serialization.

#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <assert.h>
#include <math.h>
#include "sobject_p.h"

Include dependency graph for sobj_text.c:

Include dependency graph

Functions

size_t sobj_text_encode_base64 (unsigned char *, const unsigned char *, size_t)
 Encode a block of data as Base64.
size_t sobj_text_decode_base64 (unsigned char *, const unsigned char *, size_t)
 Decode a Base64 encoded block of data.
const char * sobj_text_skip (const char *, const char *)
 Skip whitespace and comments.
size_t sobj_text_string_vref (const char **, char, char *)
 Parse a variable reference.
ptrdiff_t sobj_text_string (const char **, char, bool, char *)
 Convert a text serialization of a string to an extended UNICODE string.
bool sobj_check_unquoted_string (const char *)
 Check if the specified string is an unqouted string.
sobjsobj_text_keyword (const char *, const char *)
 Check if the specified string is a keyword.
enum sobj_type sobj_text_number (const char **, sobj_int64_t *, sobj_float64_t *)
 Parse a text serialization of a numeric value.
sobjsobj_text_unpack_array (struct sobj_env *, const char *, const char **, size_t)
 Unpack a text serialization of array contents.
sobjsobj_text_unpack_expr (struct sobj_env *, const char *, const char **, size_t)
 Unpack a text serialization of an expression object.
size_t sobj_text_unpack_binary_data (const char **, bool, char *)
 Unpack the data part of a text serialization of a binary object.
sobjsobj_text_unpack_binary (struct sobj_env *, const char *, const char **, size_t)
 Unpack a text serialization of a binary object.
sobjsobj_text_unpack_vref (const char *, const char **, size_t)
 Unpack a text serialization of a variable reference object.
int sobj_text_skip_scan (struct sobj_scan_input *)
 Skip whitespace and comments using a get function.
int sobj_text_string_scan (struct sobj_scan_input *, char)
 Scan for the end of a string.
int sobj_text_vref_scan (struct sobj_scan_input *)
 Scan over a text serialization of a variable reference.
int sobj_text_vref_scan_pmatch (struct sobj_scan_input *, char)
 Scan for a matching paren in vref.
int sobj_text_binary_scan (struct sobj_scan_input *)
 Scan over a text serialization of a binary object.
sobjsobj_text_unpack (struct sobj_env *env, enum sobj_text_context context, const char **ptr, size_t offset)
 Unpack a text serialization of a simple object.
int sobj_getc_scan (struct sobj_scan_input *input)
 Get the next character from the get function.
int sobj_text_unpack_scan (struct sobj_scan_input *input)
 Scan for the end of a text serialization.
void sobj_text_pack_string (const char *, bool, struct sobj_buffer *)
 Pack a string value.
void sobj_text_pack_binary (struct sobj *, bool, bool, struct sobj_buffer *, struct sobj_env *)
 Pack a binary object.
void sobj_text_pack_array (struct sobj *, bool, bool, struct sobj_buffer *, struct sobj_env *)
 Pack an array object.
void sobj_text_pack_expr (struct sobj *, bool, struct sobj_buffer *, struct sobj_env *)
 Pack an expression object.
void sobj_text_pack_simple (struct sobj *, bool, bool, struct sobj_buffer *, struct sobj_env *)
 Simple text serialization function without pretty printing.
void sobj_text_pack_binary_pretty (struct sobj *, int, struct sobj_buffer *)
 Pack a binary object, pretty printing.
void sobj_text_pack_array_pretty (struct sobj *, bool, int, struct sobj_buffer *)
 Pack an array object, pretty printing.
void sobj_text_pack_pretty (struct sobj *, int, bool, struct sobj_buffer *)
 Pretty printing text serialization function.
void sobj_text_pack_vref (struct sobj *sobj, bool sep, struct sobj_buffer *buffer)
 Pack a vref object.
void sobj_text_pack (struct sobj *sobj, enum sobj_serialization_mode mode, struct sobj_buffer *buffer, struct sobj_env *env)
 Create a text serialization of a simple object.
size_t sobj_text_pack_srep_string (const char *, char *, ptrdiff_t)
 Pack a string representation of a simple object string value.
size_t sobj_text_pack_srep_array (struct sobj_array *, char *, ptrdiff_t)
 Pack a string representation of an array object.
size_t sobj_text_pack_srep (struct sobj *sobj, char *buffer, ptrdiff_t buffer_length)
 Pack a string representation of a simple object.

Function Documentation

bool sobj_check_unquoted_string const char *  s  )  [static]
 

Check if the specified string is an unqouted string.

This function is a helper for the text serialization parser. It checks if the specified string starts with an unqouted string.

An unquoted string is a sequence of ASCII alphanumerics, underscores, and hyphens. An unquoted string may not start with a digit and must contain at least one character that is not a hyphen. If an unquoted string starts with a hyphen, its second character may not be a digit.

Parameters:
s The string to be checked.
Returns:
The function returns true if the specified string starts with a valid unquoted string anf false if the string does not start with an unquoted string.

int sobj_getc_scan struct sobj_scan_input input  ) 
 

Get the next character from the get function.

Parameters:
input The input source.
Returns:
The next character or -1 on EOF or error.

int sobj_text_binary_scan struct sobj_scan_input input  )  [static]
 

Scan over a text serialization of a binary object.

The input source should be positioned after the initial '%' character.

Parameters:
input The input source.
Returns:
The first character following the binary object, or -1 on EOF or error.

size_t sobj_text_decode_base64 unsigned char *  dst,
const unsigned char *  src,
size_t  src_length
[static]
 

Decode a Base64 encoded block of data.

Unrecognized characters and whitespace are ignored.

Parameters:
dst The destination buffer receiving the decoded block. This may be a null-pointer.
src The source buffer holding the Base64 encoded block.
src_length The length of the source buffer (in bytes).
Returns:
The number of bytes in the decoded block.

size_t sobj_text_encode_base64 unsigned char *  dst,
const unsigned char *  src,
size_t  src_length
[static]
 

Encode a block of data as Base64.

Parameters:
dst The destination buffer receiving the Base64 encoded block. A terminating null-byte is written to the destination buffer. This may be null-pointer.
src The source buffer.
src_length The length of the source buffer (in bytes).
Returns:
The number of bytes required for the Base64 encoding (not counting the terminating null-character).

struct sobj * sobj_text_keyword const char *  s,
const char *  cn
[static]
 

Check if the specified string is a keyword.

Parameters:
s A string parsed in general context. This is a null-terminated string containing only the string value.
cn The class name of the object.
Returns:
If the specified string is a keyword, a simple object instance representing the keyword constant is returned. If the string is not recognized as a keyword, a null-pointer is returned.

enum sobj_type sobj_text_number const char **  ptr,
sobj_int64_t *  int_value,
sobj_float64_t *  float_value
[static]
 

Parse a text serialization of a numeric value.

The function parses an integer or floating point value.

Parameters:
ptr Pointer to the caller's variable holding the position pointer. *ptr should point to the first character of the numeric value. If a numeric value is recognized, *ptr is advanced to the first character following the number. If no numeric value is recognized, *ptr is kept unchanged.
int_value If an integer value is recognized, the value is assigned to *int_value.
float_value If a floating point value is recognized, the value is assigned to *float_value.
Return values:
SOBJ_TYPE_INT An integer value was recognized.
SOBJ_TYPE_FLOAT A floating point value was recognized.
SOBJ_TYPE_NIL No number was recognized. *ptr is kept unchanged.

void sobj_text_pack struct sobj sobj,
enum sobj_serialization_mode  mode,
struct sobj_buffer buffer,
struct sobj_env env
 

Create a text serialization of a simple object.

Parameters:
sobj The called object. The caller must own a reference to the object, since this function will RETAIN and RELEASE (!) this object.
mode The serialization mode. This must be one of the text serialization modes SOBJ_SER_TEXT, SOBJ_SER_TEXT_COMPACT, SOBJ_SER_TEXT_PRETTY, SOBJ_SER_TEXT_DISPLAY.
buffer Buffer receiving the text serialization.
env The environment object (required for the ClassEnv::pack() aka sobj_env_class::so_pack callback). A null-pointer prevents the callback.

void sobj_text_pack_array struct sobj sobj,
bool  sep,
bool  delim,
struct sobj_buffer buffer,
struct sobj_env env
[static]
 

Pack an array object.

Parameters:
sobj The array object.
sep Flag indicating if extra whitespace separators should be written.
delim Flag indicating if array delimiters should be written.
buffer Buffer receiving the text serialization.
env The environment object (required for the ClassEnv::pack() aka sobj_env_class::so_pack callback). A null-pointer prevents the callback (required for SOBJ_SER_TEXT_DISPLAY).

void sobj_text_pack_array_pretty struct sobj sobj,
bool  delim,
int  indent,
struct sobj_buffer buffer
[static]
 

Pack an array object, pretty printing.

Parameters:
sobj The array object.
delim Flag indicating if array delimiters should be written.
indent The current indent level.
buffer Buffer receiving the text serialization.

void sobj_text_pack_binary struct sobj sobj,
bool  sep,
bool  text_variant,
struct sobj_buffer buffer,
struct sobj_env env
[static]
 

Pack a binary object.

Parameters:
sobj The binary object.
sep Flag indicating if extra whitespace separators should be written.
text_variant Flag indicating if the data should be encoded as text.
buffer Buffer receiving the text serialization.
env The environment object (required for the ClassEnv::pack() aka sobj_env_class::so_pack callback). A null-pointer prevents the callback (required for SOBJ_SER_TEXT_DISPLAY).

void sobj_text_pack_binary_pretty struct sobj sobj,
int  indent,
struct sobj_buffer buffer
[static]
 

Pack a binary object, pretty printing.

Parameters:
sobj The binary object.
indent The current indent level.
buffer Buffer receiving the text serialization.

void sobj_text_pack_expr struct sobj sobj,
bool  sep,
struct sobj_buffer buffer,
struct sobj_env env
[static]
 

Pack an expression object.

Parameters:
sobj The expression object.
sep Flag indicating if extra whitespace separators should be written.
buffer Buffer receiving the text serialization. This may be a null-pointer.
env The environment object (required for the ClassEnv::pack() aka sobj_env_class::so_pack callback). A null-pointer prevents the callback (required for SOBJ_SER_TEXT_DISPLAY).

void sobj_text_pack_pretty struct sobj sobj,
int  indent,
bool  selection,
struct sobj_buffer buffer
[static]
 

Pretty printing text serialization function.

Parameters:
sobj The called object.
indent The current indent level.
selection Flag indicating if the object is serialized in selection context.
buffer Buffer receiving the text serialization. This may be a null-pointer.

void sobj_text_pack_simple struct sobj sobj,
bool  sep,
bool  selection,
struct sobj_buffer buffer,
struct sobj_env env
[static]
 

Simple text serialization function without pretty printing.

Parameters:
sobj The called object. The caller must own a reference to the object, since this function will RETAIN and RELEASE (!) this object.
sep Flag indicating if extra whitespace separators should be written.
selection Flag indicating if the object is serialized in selection context.
buffer Buffer receiving the text serialization.
env The environment object (required for the ClassEnv::pack() aka sobj_env_class::so_pack callback). A null-pointer prevents the callback (required for SOBJ_SER_TEXT_DISPLAY).

size_t sobj_text_pack_srep struct sobj sobj,
char *  buffer,
ptrdiff_t  buffer_length
 

Pack a string representation of a simple object.

Parameters:
sobj The simple object instance.
buffer Buffer receiving the string representation. This may be a null-pointer.
buffer_length The length of the output buffer (in bytes).
Returns:
The number of bytes required for the string representation (not counting the terminating null-byte).

size_t sobj_text_pack_srep_array struct sobj_array array,
char *  buffer,
ptrdiff_t  buffer_length
[static]
 

Pack a string representation of an array object.

Parameters:
array The array object.
buffer Buffer receiving the string representation. This may be a null-pointer.
buffer_length The length of the output buffer (in bytes).
Returns:
The number of bytes required for the string representation (not counting the terminating null-byte).

size_t sobj_text_pack_srep_string const char *  string,
char *  buffer,
ptrdiff_t  buffer_length
[static]
 

Pack a string representation of a simple object string value.

Parameters:
string The string value.
buffer Buffer receiving the string representation. This may be a null-pointer.
buffer_length The length of the output buffer (in bytes).
Returns:
The number of bytes required for the string representation (not counting the terminating null-byte).

void sobj_text_pack_string const char *  string,
bool  selection,
struct sobj_buffer buffer
[static]
 

Pack a string value.

Parameters:
string The string value.
selection Flag indicating if the string is packed in selection context.
buffer Buffer receiving the text serialization. This may be a null-pointer.

void sobj_text_pack_vref struct sobj sobj,
bool  sep,
struct sobj_buffer buffer
[static]
 

Pack a vref object.

Parameters:
sobj The vref object.
sep Flag indicating if extra whitespace separators should be written.
buffer Buffer receiving the text serialization.

const char * sobj_text_skip const char *  p,
const char *  extra
[static]
 

Skip whitespace and comments.

Parameters:
p Pointer into a text serialization.
extra Pointer to a string of extra whitespace characters. Characters in the extra string are treated like whitespace. This may be a null-pointer.
Returns:
Pointer to the first non-whitespace, non-comment character encountered. In case of an unterminated comment, a pointer to the end of the serialization is returned (terminating null-byte).

int sobj_text_skip_scan struct sobj_scan_input input  )  [static]
 

Skip whitespace and comments using a get function.

Parameters:
input The scan input.
Returns:
The next non-whitespace, non-comment character or -1 on EOF or error.

ptrdiff_t sobj_text_string const char **  ptr,
char  quote,
bool  vref,
char *  buffer
[static]
 

Convert a text serialization of a string to an extended UNICODE string.

The function reads a text serialization of a string and converts it to an extended UNICODE string. An extended UNICODE string is a sequence of (UTF-8 encoded) UNICODE characters. The ASCII character ESC is used as an escape character for variable references.

Parameters:
ptr Pointer to the first character of the string contents. For a quoted string this is the character following the opening quote. On success, *ptr is advanced to the first character following the string. If the string is quoted, *ptr will point to the closing quote.
quote The quoting character delimiting the string. The end of the string is recognized if an unqouted quoting character is found. If the string is not quoted, quote should be 0.
vref Flag indicating if variable references should be parsed. If this flag is clear, variable references are not recognized and not checked.
buffer The buffer receiving the extended UNICODE string (including a terminating null-character). If this is a null-pointer, no conversion is done.
Returns:
The function returns the number of bytes required to hold the extended UNICODE string, not including the terminating null-character. If a quoting character is specified and the string is not terminated, the special value -1 is returned.
Note:
Invalid variable references are processed literally (without indicating an error).

int sobj_text_string_scan struct sobj_scan_input input,
char  quote
[static]
 

Scan for the end of a string.

The input source should be positioned at the first character following the initial quote.

Parameters:
input The input source.
quote The end quoting character.
Returns:
The first character following the string, or -1 on EOF or error.

size_t sobj_text_string_vref const char **  ptr,
char  quote,
char *  buffer
[static]
 

Parse a variable reference.

Parameters:
ptr The caller's buffer pointer. On success *ptr is advanced to the character following the variable reference.
quote The quoting character delimiting the string. The end of the string is recognized if an unqouted quoting character is found. If the string is not quoted, quote should be 0.
buffer Buffer receiving the the variable reference string. A terminating null-character is written to the buffer. This parameter may be a null-pointer.
Returns:
The length of the reference string (in bytes), not counting the terminating null-byte.

struct sobj* sobj_text_unpack struct sobj_env env,
enum sobj_text_context  context,
const char **  ptr,
size_t  offset
 

Unpack a text serialization of a simple object.

The function unpacks a full text serialization of a simple object.

Parameters:
env The environment. This may be a null-pointer.
context The text serialization context.
ptr Pointer into the text serialization. The text serialization is exprected to be null-terminated.
offset The offset of *ptr relative to the text serialization.
Returns:
The function returns an sobj with a refcount of 0. If no simple object serialization is recognized, a null-pointer is returned.
Note:
In string context (SOBJ_CTX_STRING), the function will always return an instance of a simple object.

struct sobj * sobj_text_unpack_array struct sobj_env env,
const char *  cn,
const char **  ptr,
size_t  offset
[static]
 

Unpack a text serialization of array contents.

The function unpacks the interior of an array object. This function is used for parsing a serialization in array context. Everything up to the first unrecognized character is converted (when parsing an array, this will be the closing bracket).

Parameters:
env The environment. This may be a null-pointer.
cn The class name of the array object.
ptr Pointer into the text serialization. The text serialization is exprected to be null-terminated.
offset The offset of *ptr relative to the text serialization.
Returns:
The function returns an sobj with a refcount of 0.

struct sobj * sobj_text_unpack_binary struct sobj_env env,
const char *  cn,
const char **  ptr,
size_t  offset
[static]
 

Unpack a text serialization of a binary object.

Parameters:
env The environment. This may be a null-pointer.
cn The class name of the object.
ptr Pointer into the text serialization. The text serialization is exprected to be null-terminated.
offset The offset of *ptr relative to the text serialization.
Returns:
The function returns an sobj with a refcount of 0.

size_t sobj_text_unpack_binary_data const char **  ptr,
bool  text_variant,
char *  buffer
[static]
 

Unpack the data part of a text serialization of a binary object.

Parameters:
ptr Pointer into text serialization. The text serialization is exprected to be null-terminated.
text_variant Flag indicating if the data part is encoded as text.
buffer Buffer receiving the decoded data. This may be a null-pointer.
Returns:
The function returns the number of data bytes.

struct sobj * sobj_text_unpack_expr struct sobj_env env,
const char *  cn,
const char **  ptr,
size_t  offset
[static]
 

Unpack a text serialization of an expression object.

Parameters:
env The environment. This may be a null-pointer.
cn The class name of the object.
ptr Pointer into the text serialization. The text serialization is exprected to be null-terminated.
offset The offset of *ptr relative to the text serialization.
Returns:
The function returns an sobj with a refcount of 0.

int sobj_text_unpack_scan struct sobj_scan_input input  ) 
 

Scan for the end of a text serialization.

Parameters:
input The scan input.
Return values:
0 Success.
-1 The get function returned -1 (indicating EOF or error).

struct sobj * sobj_text_unpack_vref const char *  cn,
const char **  ptr,
size_t  offset
[static]
 

Unpack a text serialization of a variable reference object.

Parameters:
cn The class name of the object.
ptr Pointer into the text serialization. The text serialization is exprected to be null-terminated.
offset The offset of *ptr relative to the text serialization.
Returns:
The function returns an sobj with a refcount of 0.

int sobj_text_vref_scan struct sobj_scan_input input  )  [static]
 

Scan over a text serialization of a variable reference.

The input source should be positioned after the initial '$' character.

Parameters:
input The input source.
Returns:
The first character following the variable reference, or -1 on EOF or error.

int sobj_text_vref_scan_pmatch struct sobj_scan_input input,
char  match
[static]
 

Scan for a matching paren in vref.

Parameters:
input The input source.
match The matching paren.
Returns:
The first character following the matching paren, or -1 on EOF or error.


Generated on Sat Jul 23 16:05:41 2005 for sobject by  doxygen 1.3.9.1