SphinxBase  5prealpha
strfuncs.h File Reference

Miscellaneous useful string functions. More...

#include <stdarg.h>
#include <sphinxbase/sphinxbase_export.h>
#include <sphinxbase/prim_type.h>

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...
 

Detailed Description

Miscellaneous useful string functions.

Definition in file strfuncs.h.

Enumeration Type Documentation

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.

Function Documentation

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.

Referenced by logmath_read().

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.

Returns
Length of word returned, or -1 if nothing found. This allows you to scan through a line:
while ((n = nextword(line, delim, &word, &delimfound)) >= 0) {
    ... do something with word ..
    word[n] = delimfound;
    line = word + n;
}
Parameters
lineInput: String being searched for next word. Will be modified by this function (NUL characters inserted)
delimInput: A word, if found, must be delimited at either end by a character from this string (or at the end by the NULL char)
wordOutput: *word = ptr within line to beginning of first word, if found. Delimiter at the end of word replaced with the NULL char.
delimfoundOutput: *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.

Parameters
lineIn/Out: line to be parsed. This string will be modified! (NUL characters inserted at word boundaries)
wptrIn/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);

Parameters
n_wptrIn: 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.

Parameters
stringstring to trim, contents will be modified.
whichone 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(), and lineiter_start_clean().