block: don't put spaces around :
[ironout.git] / strutils.c
blob4ea3d7a21f6bf9fb03c2a266174eca24ac69ac01
1 #include <ctype.h>
2 #include <string.h>
5 /* returns the start of the next token */
6 char *readtoken(char *to, char *from, char *delims)
8 for (; *from != '\0' && !strchr(delims, *from);)
9 *to++ = *from++;
10 *to = '\0';
11 for (; *from != '\0' && strchr(delims, *from);)
12 from++;
13 return from;
16 /* returns the start of the next word */
17 char *readword(char *to, char *from)
19 for (; *from != '\0' && isalnum(*from);)
20 *to++ = *from++;
21 *to = '\0';
22 for (; *from != '\0' && !isalnum(*from);)
23 from++;
24 return from;
27 char *nthtoken(char *to, char *from, char* delims, int n)
29 int i = 0;
30 for (i = 0; i < n; i++)
31 from = readtoken(to, from, delims);
32 return from;
35 int startswith(char *heystack, char *needle)
37 while (*needle != '\0' && *needle == *heystack++)
38 needle++;
39 return !*needle;
42 int endswith(char *heystack, char *needle)
44 char *p = heystack + strlen(heystack);
45 char *q = needle + strlen(needle);
46 while (q != needle && p != heystack && *--p == *--q)
48 return *p == *q && q == needle;