Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   Namespace Members   Compound Members  

PLMParse Namespace Reference

Help functions to parse config files and init strings. More...


Functions

PLMDLL u32 ReadString (char **str, char *dest, u32 len, char sep= ',')
PLMDLL bool ReadBoolean (char **str, bool &val)
PLMDLL bool ReadInt (char **str, int &val)
PLMDLL bool ReadFloat (char **str, float &val)
PLMDLL bool ReadGeometry (char **str, PLMRect &r)
PLMDLL bool ReadColor (char **str, unsigned char color[4])
PLMDLL const char * ReadBoolean (const char *str, bool &val)
PLMDLL const char * ReadInt (const char *str, int &val)
PLMDLL const char * ReadFloat (const char *str, float &val)
PLMDLL const char * ReadColor (const char *str, unsigned char color[4])
PLMDLL bool ReadDate (const char *str, time_t &val)
PLMDLL char * EatSpace (const char *str)
PLMDLL char * SkipEqual (char *ptr)
PLMDLL unsigned char Hexa2Dec (unsigned char c1, unsigned char c2)
PLMDLL void Dec2Hexa (unsigned int val, int n, char *dst)
PLMDLL void Dec2Hexa (u8 *color, int n, char *dst)
PLMDLL void Hexa2Float (const char *src, float *dst)
PLMDLL float RGB2H (float *src)
PLMDLL void H2RGB (float h, float *dst)
PLMDLL void RGB_to_HSV (float r, float g, float b, float &h, float &s, float &v)
PLMDLL void HSV_to_RGB (float h, float s, float v, float &r, float &g, float &b)
PLMDLL void Obfuscate (const char *str, char *dst)
PLMDLL int ForceRange (char *str, char c1, char c2, char repl= '_')
PLMDLL int SystemPath (char *filename)


Detailed Description

Help functions to parse config files and init strings.

Function Documentation

PLMDLL u32 ReadString char **    str,
char *    dest,
u32    len,
char    sep = ','
 

Read a string of text until a separator is found.

Parameters:
str  [in/out] the string to read, it is updated to point on the last character that was read (usually after sep).
dest  an allocated string of at least len bytes, to write the chars read. Leading spaces are ignored, and \sep is replaced by \0. Can be NULL, nothing is written then but str is still updated.
len  the maximum number of characters to write into dest. Ignored if dest is NULL.
sep  the ending character, the copy is stopped as soon as this character is found in str.
Returns:
the number of characters really written (without \0), (or that would have been written if dest is NULL).

PLMDLL bool ReadBoolean char **    str,
bool &    val
 

Try to read a boolean value from a string.

Can be { "true", "false", "yes", "no", "1", "0" } (case independant).

Returns:
  • true if one word from the above list is found, val is then updated, and str then points on the first character after that word (a ',' is also skipped if found at the end)
  • no if none of these words are found, val and str not modified.

PLMDLL bool ReadInt char **    str,
int &    val
 

Try to read an integer (not a float) from a string.

Leading spaces are ignored. On success, str points on the first not-usable character after the integer (if it's ',' it is skipped also) and the value found is written in val. Return false on error, val and str not modified.

PLMDLL bool ReadFloat char **    str,
float &    val
 

Try to read a floating point value from a string.

See ReadInt() for details. Return false on error and do not modify val.

PLMDLL bool ReadGeometry char **    str,
PLMRect   r
 

Try to read 4 integers (position and size) from a string.

Syntax: "xpos, ypos, width, height" True is returned only if the four integers can be read, then str will point after the last integer correctly read (the last ',' is also skipped if any). str is always modified, even if it returns false.

PLMDLL bool ReadColor char **    str,
unsigned char    color[4]
 

Try to read a color definition from a string.

Syntax: "RRGGBB[AA]" Return true on success, and fill in color with red, green, blue and possibly alpha components. A trailing ',' is also skipped. str is then modified to points after what has been read. Return false on error, str and color are not modified.

PLMDLL const char* ReadBoolean const char *    str,
bool &    val
 

Try to read a boolean value from a string and write it in val.

"true", "yes", "1" are considered as true, "false", "no", "0" as false, and case is ignored (yes = YES = YeS). Leading spaces are ignored. Return NULL if none of the previous word is found (val not modified), or the first not-used position in str on success.

PLMDLL const char* ReadInt const char *    str,
int &    val
 

Try to read an integer (not a float) from a string and write it in val.

Leading white spaces are ignored. Return NULL on error, or the first not-used position in str on success.

PLMDLL const char* ReadFloat const char *    str,
float &    val
 

Try to read a floating point value from a string and write it in val.

Leading white spaces are ignored. Return NULL on error, or the first not-used position in str on success.

PLMDLL const char* ReadColor const char *    str,
unsigned char    color[4]
 

Try to read a color definition from a string (HTML syntax) and fill in color with red, green, blue and optionnaly alpha components.

The syntax must be "RRGGBB[AA]". Leading white spaces are ignored. Note that color[3] is not modified if alpha value is missing. Return NULL on error, or the first not-used position in str on success.

PLMDLL bool ReadDate const char *    str,
time_t &    val
 

Try to read a date and time value from a string and write it in val.

The syntax must be : "YYYY/MM/DD [HH:MM[:SS]]" Leading white spaces are ignored, hour part and seconds are optional. Return false on error.

PLMDLL char* EatSpace const char *    str
 

Return a pointer on the first non-space character (space or tab).

PLMDLL char* SkipEqual char *    ptr
 

Try to read the following pattern "<spaces><separator><spaces>" in the given string.

<spaces> is any number of space or tabs and <separator> is '=' or ':'.

Returns:
a pointer on the first character after the pattern on success, or NULL if the <separator> is not found, or if the there is nothing else in the string.

PLMDLL unsigned char Hexa2Dec unsigned char    c1,
unsigned char    c2
 

Convert a hexadecimal value from a string into a decimal value.

Example: 'F' and 'E' ("FE") gives 254.

PLMDLL void Dec2Hexa unsigned int    val,
int    n,
char *    dst
 

Convert a decimal value into a hexadecimal string.

val the value to convert, each group of 4 bits is turned into a character (0-9A-F). n the number of groups/letters = the space in dst (range = 1-8, 0 = none). dst a pre-allocated string to write the n converted characters.

PLMDLL void Dec2Hexa u8 *    color,
int    n,
char *    dst
 

Convert an array of decimal values (bytes) into a hexadecimal string.

color an array of values (usually red/green/blue and optionnaly alpha components) n the number of components (3 for RGB or 4 for RGBA), but can be any value. dst the string where the hexa chars are written, its size must be at least 2*n bytes since each value requires exactly 2 characters.

PLMDLL void Hexa2Float const char *    src,
float *    dst
 

Convert a string "RRGGBB" (color definition) into 3 float values (red, green and blue, stored in dst array).

PLMDLL float RGB2H float *    src
 

Convert a color in RGB format into Hue value of HSV format.

PLMDLL void H2RGB float    h,
float *    dst
 

Convert a the Hue value of a color in HSV format into RGB format (S = V = 1.0f).

PLMDLL void RGB_to_HSV float    r,
float    g,
float    b,
float &    h,
float &    s,
float &    v
 

Convert a color in RGB format (values in [0..1]) into HSV format.

PLMDLL void HSV_to_RGB float    h,
float    s,
float    v,
float &    r,
float &    g,
float &    b
 

Convert a color in HSV format into RGB format (values in [0..1]).

PLMDLL void Obfuscate const char *    str,
char *    dst
 

Copy the string src into pre-allocated string dst, but modify all characters to make them unreadable.

The characters are simply inverted (bitwise NOT), so the operation is reversible. The source string should not contain a character of code 255, since it would be turned into 0 which means end-of-string. A second call to Obfuscate() would restore the initial string.

PLMDLL int ForceRange char *    str,
char    c1,
char    c2,
char    repl = '_'
 

Parse the given string str, and check if all characters are within the range [c1..c2] (inclusive).

Any character outside the range is replaced by the character repl. Details:

  • if c1 < c2 : any char OUTSIDE [c1..c2] (inclusive) is turned into repl.
  • if c1 = c2 : ALL chars but c1 is replaced by repl.
  • if c1 > c2 : any char INSIDE ]c1..c2[ (exclusive) is turned into repl. Return the number of characters modified.

PLMDLL int SystemPath char *    filename
 

Replace all path separators in the string filename by system separators.

I.e. Replace any occurence of '\' or '/' or ':' by the standard separator of the current system ('/' on unix, '\' on win32, ':' on old MacOS).


Generated by Doxygen 1.2.18 on Tue Oct 26 12:07:45 2004.