SphinxBase
5prealpha
|
Miscellaneous useful string functions. More...
Go to the source code of this file.
Enumerations | |
enum | string_edge_e { STRING_START, STRING_END, STRING_BOTH } |
Which end of a string to operate on for string_trim(). More... | |
Functions | |
SPHINXBASE_EXPORT char * | string_join (const char *base,...) |
Concatenate a NULL-terminated argument list of strings, returning a newly allocated string. | |
SPHINXBASE_EXPORT char * | string_trim (char *string, enum string_edge_e which) |
Remove whitespace from a string, modifying it in-place. More... | |
SPHINXBASE_EXPORT double | atof_c (char const *str) |
Locale independent version of atof(). More... | |
SPHINXBASE_EXPORT int32 | str2words (char *line, char **wptr, int32 n_wptr) |
Convert a line to an array of "words", based on whitespace separators. More... | |
SPHINXBASE_EXPORT int32 | nextword (char *line, const char *delim, char **word, char *delimfound) |
Yet another attempt at a clean "next-word-in-string" function. More... | |
Miscellaneous useful string functions.
Definition in file strfuncs.h.
enum string_edge_e |
Which end of a string to operate on for string_trim().
Enumerator | |
---|---|
STRING_START | Beginning of string. |
STRING_END | End of string. |
STRING_BOTH | Both ends of string. |
Definition at line 70 of file strfuncs.h.
SPHINXBASE_EXPORT double atof_c | ( | char const * | str | ) |
Locale independent version of atof().
This function behaves like atof() in the "C" locale. Switching locale in a threaded program is extremely uncool, therefore we need this since we pass floats as strings in 1000 different places.
Definition at line 55 of file strfuncs.c.
SPHINXBASE_EXPORT int32 nextword | ( | char * | line, |
const char * | delim, | ||
char ** | word, | ||
char * | delimfound | ||
) |
Yet another attempt at a clean "next-word-in-string" function.
See arguments below.
while ((n = nextword(line, delim, &word, &delimfound)) >= 0) { ... do something with word .. word[n] = delimfound; line = word + n; }
line | Input: String being searched for next word. Will be modified by this function (NUL characters inserted) |
delim | Input: A word, if found, must be delimited at either end by a character from this string (or at the end by the NULL char) |
word | Output: *word = ptr within line to beginning of first word, if found. Delimiter at the end of word replaced with the NULL char. |
delimfound | Output: *delimfound = original delimiter found at the end of the word. (This way, the caller can restore the delimiter, preserving the original string.) |
Definition at line 166 of file strfuncs.c.
SPHINXBASE_EXPORT int32 str2words | ( | char * | line, |
char ** | wptr, | ||
int32 | n_wptr | ||
) |
Convert a line to an array of "words", based on whitespace separators.
A word is a string with no whitespace chars in it. Note that the string line is modified as a result: NULL chars are placed after every word in the line. Return value: No. of words found; -1 if no. of words in line exceeds n_wptr.
line | In/Out: line to be parsed. This string will be modified! (NUL characters inserted at word boundaries) |
wptr | In/Out: Array of pointers to words found in line. The array must be allocated by the caller. It may be NULL in which case the number of words will be counted. This allows you to allcate it to the proper size, e.g.: |
n = str2words(line, NULL, 0); wptr = ckd_calloc(n, sizeof(*wptr)); str2words(line, wptr, n);
n_wptr | In: Size of wptr array, ignored if wptr == NULL |
Definition at line 123 of file strfuncs.c.
SPHINXBASE_EXPORT char* string_trim | ( | char * | string, |
enum string_edge_e | which | ||
) |
Remove whitespace from a string, modifying it in-place.
string | string to trim, contents will be modified. |
which | one of STRING_START, STRING_END, or STRING_BOTH. |
Definition at line 97 of file strfuncs.c.
References STRING_BOTH, STRING_END, and STRING_START.
Referenced by lineiter_next().