Functions | Variables

parsing.cpp File Reference

#include "parsing.h"
#include "common/wave_ex.h"
Include dependency graph for parsing.cpp:

Go to the source code of this file.

Functions

bool getUTF8CharacterFromStream (std::istream &stream, utf8_char_t &c)
 get the next (UTF-8) character from the stream returns false on eof (end of stream)
const char * getUTF8CharacterFromString (const char *input, utf8_char_t &c)
 get the next (UTF-8) character from the given string returns a pointer to the next character in the string
int getUTF8ByteCount (char a)
 given an initial byte of a (potentially) multi-byte UTF-8 character, return how many bytes total in the character returns -1 on error.
std::string getNextLineFromStream (std::istream &stream, eParseBehavior behavior)
 Reads to the next newline or end of stream, and stashes all characters (except the final newline) in the output string.
const char * getNextTokenFromString (const char *input, std::string &token, eParseBehavior behavior)
 finds the next whitespace-delimited token, and puts it in the given token (std::string).
const char * getNextTokenFromString (const char *input, char *buffer, int buffer_size, eParseBehavior behavior, int &chars) throw ()
 finds the next whitespace-delimited token, and puts it in the given buffer.
const char * expectFromString (const char *input, const char *expect, eParseBehavior parse)
 expects the given token to be next in the string.
bool isBogus (char a) throw ()
 true if the given character is bogus ('\r', etc)
char * stripComments (char *line) throw ()
char * stripBogus (char *line) throw ()
char * lowercase (char *wext) throw ()
void getDictionaryFromString (const char *cursor, const char *info, dictionary_t &dict)
const char * getValue (const dictionary_t &data, const char *key)
const char * getRequiredValue (const dictionary_t &data, const char *key)
const char * getOptionalValue (const dictionary_t &data, const char *key, const char *default_value) throw ()
const char * getFloatFromString (const char *input, float &x) throw ()
 helper method to extract a float (assuming it is the next token) This routine is UTF-8 compliant
int readFloatsFromString (const char *input, int nFloats, float *output) throw ()
 helper method to read up to N floats.
bool getBooleanFromString (const char *input) throw ()
 tries to determine if the given string is a true or false value.
const char * getNextWord (const char *line, std::string &word)
 retrieves the next word from the specified line of text, and returns a pointer to the first character in the line after the word.

Variables

static const byte_t s_maskHigh = 0x80
static const byte_t s_maskTwoHigh = 0xC0

Function Documentation

bool getUTF8CharacterFromStream ( std::istream &  stream,
utf8_char_t c 
)

get the next (UTF-8) character from the stream returns false on eof (end of stream)

Definition at line 131 of file parsing.cpp.

const char* getUTF8CharacterFromString ( const char *  input,
utf8_char_t c 
)

get the next (UTF-8) character from the given string returns a pointer to the next character in the string

Definition at line 178 of file parsing.cpp.

int getUTF8ByteCount ( char  a  ) 

given an initial byte of a (potentially) multi-byte UTF-8 character, return how many bytes total in the character returns -1 on error.

Definition at line 222 of file parsing.cpp.

std::string getNextLineFromStream ( std::istream &  stream,
eParseBehavior  behavior 
)

Reads to the next newline or end of stream, and stashes all characters (except the final newline) in the output string.

Caller can ask to have comments and/or bogus characters stripped out. returns a std::string containing the line. throws on errors This routine is UTF-8 compliant.

Definition at line 254 of file parsing.cpp.

const char* getNextTokenFromString ( const char *  input,
std::string &  token,
eParseBehavior   
)

finds the next whitespace-delimited token, and puts it in the given token (std::string).

returns a pointer to the character (whitespace or end of string) right after the token. This routine is UTF-8 compliant.

Definition at line 308 of file parsing.cpp.

const char* getNextTokenFromString ( const char *  input,
char *  buffer,
int  buffer_size,
eParseBehavior  ,
int &  chars 
) throw ()

finds the next whitespace-delimited token, and puts it in the given buffer.

returns a pointer to the character right after the token the chars parameter returns how many characters are in the buffer. the buffer is null-terminated if the buffer wasn't big enough for the token, the token will be truncated. The buffer will be null-terminated (the routine saves enough room for the final null). chars will contain the number of characters parsed from the string, even if not all of them were copied into the buffer. So you can detect truncation if chars >= buffer_size. This routine is UTF-8 compliant

Definition at line 364 of file parsing.cpp.

const char* expectFromString ( const char *  input,
const char *  expect,
eParseBehavior   
)

expects the given token to be next in the string.

Throws if the next token is something else. Returns a pointer to the character immediately following the expected token.

Definition at line 407 of file parsing.cpp.

bool isBogus ( char  a  )  throw ()

true if the given character is bogus ('\r', etc)

Definition at line 442 of file parsing.cpp.

char* stripComments ( char *  line  )  throw ()

Definition at line 454 of file parsing.cpp.

char* stripBogus ( char *  line  )  throw ()

Definition at line 481 of file parsing.cpp.

char* lowercase ( char *  wext  )  throw ()

Definition at line 504 of file parsing.cpp.

void getDictionaryFromString ( const char *  cursor,
const char *  info,
dictionary_t dict 
)

Definition at line 524 of file parsing.cpp.

const char* getValue ( const dictionary_t data,
const char *  key 
)

Definition at line 561 of file parsing.cpp.

const char* getRequiredValue ( const dictionary_t data,
const char *  key 
)

Definition at line 576 of file parsing.cpp.

const char* getOptionalValue ( const dictionary_t data,
const char *  key,
const char *  default_value 
) throw ()

Definition at line 600 of file parsing.cpp.

const char* getFloatFromString ( const char *  input,
float &  x 
) throw ()

helper method to extract a float (assuming it is the next token) This routine is UTF-8 compliant

Definition at line 619 of file parsing.cpp.

int readFloatsFromString ( const char *  input,
int  nFloats,
float *  output 
) throw ()

helper method to read up to N floats.

Returns the number read. Assumes that that caller doesn't need the string returned! The caller must provide a pre-allocated array of floats for output.

Definition at line 648 of file parsing.cpp.

bool getBooleanFromString ( const char *  input  )  throw ()

tries to determine if the given string is a true or false value.

This is NOT localized. This is for machine-parsed input only, such as config files. A string is considered false if it is the word "false" (any case), the single letter "F", the character "0", or empty. Any other value is considered true. Note that expressions that evaluate to zero but are not a single digit, such as "-0" or "+0", are considered true.

Definition at line 675 of file parsing.cpp.

const char* getNextWord ( const char *  text,
std::string &  word 
)

retrieves the next word from the specified line of text, and returns a pointer to the first character in the line after the word.

Leading whitespace will be ignored when parsing. The word returned will either be empty, a newline, or a set of non-space characters. If the returned word is empty, then NULL is also the return value (word can only be empty at end-of-line). Note that you can have non-empty words returned with a NULL return value.

Definition at line 701 of file parsing.cpp.


Variable Documentation

const byte_t s_maskHigh = 0x80 [static]

Definition at line 41 of file parsing.cpp.

const byte_t s_maskTwoHigh = 0xC0 [static]

Definition at line 42 of file parsing.cpp.