![]() |
![]() |
![]() |
CTPL Reference Manual | ![]() |
---|---|---|---|---|
Top | Description |
#include <ctpl/readutils.h> #define CTPL_BLANK_CHARS #define CTPL_ESCAPE_CHAR #define CTPL_STRING_DELIMITER_CHAR gchar * ctpl_read_word (MB *mb, const gchar *accept); gsize ctpl_read_skip_chars (MB *mb, const gchar *reject); #define ctpl_read_skip_blank (mb) gchar * ctpl_read_string_literal (MB *mb); gdouble ctpl_read_double (MB *mb, gsize *n_read);
Useful functions to read data from a LibMB buffer.
These functions are somewhat generic and are used by different part of CTPL internally.
#define CTPL_BLANK_CHARS " \t\v\r\n"
Characters treated as blank, commonly used as separator.
#define CTPL_STRING_DELIMITER_CHAR '"'
Character surrounding string literals.
gchar * ctpl_read_word (MB *mb, const gchar *accept);
Reads a word composed of accept
characters.
|
A MB |
|
String of acceptable characters for the word |
Returns : |
A newly allocated string containing the read word or NULL if there
was no word to read (e.g. no characters matching accept was found
before one not matching it).
|
gsize ctpl_read_skip_chars (MB *mb, const gchar *reject);
Skips characters in reject
, making the next call to mb_getc()
on mb
not
getting one of them.
|
A MB |
|
Characters to skip. |
Returns : |
The number of skipped characters. |
#define ctpl_read_skip_blank(mb) (ctpl_read_skip_chars ((mb), CTPL_BLANK_CHARS))
Skips blank characters (those from CTPL_BLANK_CHARS).
See ctpl_read_skip_chars()
.
|
A MB |
Returns : |
The number of skipped characters. |
gchar * ctpl_read_string_literal (MB *mb);
Tries to read a string literal.
A string literal is something like "foo bar"
, with the quotes.
Here, the quotes are CTPL_STRING_DELIMITER_CHAR
. Delimiter character may
appear inside a string literal if escaped with CTPL_ESCAPE_CHAR
.
A plain CTPL_ESCAPE_CHAR
need to be escaped too, otherwise it will simply
escape the next character.
|
A MB |
Returns : |
The read string, or NULL if none read.
|
gdouble ctpl_read_double (MB *mb, gsize *n_read);
Reads a number from mb
as a double, as g_ascii_strtod()
would do.
errno
may be modified by a call to this function (see g_ascii_strtod()
for possible reasons).
Regardless the above warning, you do not need to check errno
to know if
the conversion succeeded cleanly and completely, since this function
already does it and reports an invalid value if errno
reports any
interesting error (i.e. ERANGE
).
|
A MB |
|
Return location for the number of characters that were read to build
the returned value, or NULL . This value is set to 0 if no valid
number were read.
|
Returns : |
The read value as a double, or 0 on error. See n_read to cleanly
detect errors.
|