diff options
author | Patrick Simianer <simianer@cl.uni-heidelberg.de> | 2012-08-01 17:32:37 +0200 |
---|---|---|
committer | Patrick Simianer <simianer@cl.uni-heidelberg.de> | 2012-08-01 17:32:37 +0200 |
commit | eb3ea4fd5dff1c94b237af792c9f7bf421d79d96 (patch) | |
tree | 2acd7674f36e6dc6e815c5856519fdea1a2d6bf8 /sa-extract/strutil.c | |
parent | e816274e337a066df1b1e86ef00136a021a17caf (diff) | |
parent | 193d137056c3c4f73d66f8db84691d63307de894 (diff) |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'sa-extract/strutil.c')
-rw-r--r-- | sa-extract/strutil.c | 63 |
1 files changed, 0 insertions, 63 deletions
diff --git a/sa-extract/strutil.c b/sa-extract/strutil.c deleted file mode 100644 index 456de87a..00000000 --- a/sa-extract/strutil.c +++ /dev/null @@ -1,63 +0,0 @@ -#include <string.h> -#include <stdlib.h> - -/* Like strsep(3) except that the delimiter is a string, not a set of characters. -*/ -char *strstrsep(char **stringp, const char *delim) { - char *match, *save; - save = *stringp; - if (*stringp == NULL) - return NULL; - match = strstr(*stringp, delim); - if (match == NULL) { - *stringp = NULL; - return save; - } - *match = '\0'; - *stringp = match + strlen(delim); - return save; -} - -static char **words = NULL; -static int max_words; -char **split(char *s, const char *delim, int *pn) { - int i; - char *tok, *rest; - - if (words == NULL) { - max_words = 10; - words = malloc(max_words*sizeof(char *)); - } - i = 0; - rest = s; - while ((tok = (delim ? strstrsep(&rest, delim) : strsep(&rest, " \t\n"))) != NULL) { - if (!delim && !*tok) // empty token - continue; - while (i+1 >= max_words) { - max_words *= 2; - words = realloc(words, max_words*sizeof(char *)); - } - words[i] = tok; - i++; - } - words[i] = NULL; - if (pn != NULL) - *pn = i; - return words; -} - -inline int isspace(char c) { - return (c == ' ' || c == '\t' || c == '\n'); -} - -char *strip(char *s) { - int n; - while (isspace(*s) && *s != '\0') - s++; - n = strlen(s); - while (n > 0 && isspace(s[n-1])) { - s[n-1] = '\0'; - n--; - } - return s; -} |