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.
SPHINXBASE_EXPORT double | atof_c (char const *str)
| Locale independent version of atof().
SPHINXBASE_EXPORT int32 | str2words (char *line, char **wptr, int32 n_wptr)
| Convert a line to an array of "words", based on whitespace separators.
SPHINXBASE_EXPORT int32 | nextword (char *line, const char *delim, char **word, char *delimfound)
| Yet another attempt at a clean "next-word-in-string" function.

## Detailed Description

Miscellaneous useful string functions.

Definition in file strfuncs.h.

## Enumeration Type Documentation

## string_edge_e

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.

## Function Documentation

## atof_c()

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.

References atof_c().

Referenced by atof_c(), and logmath_read().

## nextword()

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

  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.

References nextword().

Referenced by nextword().

## str2words()

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

  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);

Parameters

  n_wptr | In: Size of wptr array, ignored if wptr == NULL

Definition at line 123 of file strfuncs.c.

References str2words().

Referenced by str2words().

## string_join()

SPHINXBASE_EXPORT char * string_join | ( | const char * | base,
|  |  | ... )

Concatenate a NULL-terminated argument list of strings, returning a newly allocated string.

Definition at line 70 of file strfuncs.c.

References ckd_calloc, and string_join().

Referenced by fopen_comp(), jsgf_get_rule(), ngram_model_set_read(), and string_join().

## string_trim()

SPHINXBASE_EXPORT char * string_trim | ( | char * | string,
|  | enum string_edge_e | which )

Remove whitespace from a string, modifying it in-place.

Parameters

  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, STRING_START, and string_trim().

Referenced by lineiter_next(), lineiter_start_clean(), and string_trim().