| iMatix home page | << | < | > | >> |
SFL Version 2.11 |
#include "sflstr.h" char * strprefix ( const char *string, const char *delims)
Looks for one of the delimiter characters in the string; if found, returns a string that contains the text up to that delimiter. If not found, returns NULL. The returned string can be zero or more characters long followed by a null byte. It is allocated using the mem_alloc() function; you should free it using mem_free() when finished.
{ const char *nextch; char *token; int token_size; ASSERT (string); ASSERT (delims); for (nextch = string; *nextch; nextch++) { if (strchr (delims, *string)) /* Is next character a delimiter */ { token_size = (int) (nextch - string); token = mem_alloc (token_size + 1); if (token == NULL) return (NULL); /* Not enough memory - fail */ memcpy (token, string, token_size); token [token_size] = 0; return (token); } } return (NULL); }
| << | < | > | >> | Copyright © 1996-2000 iMatix Corporation |