str.c (725B)
1 /* See LICENSE file for copyright and license details. */ 2 #include <ctype.h> 3 #include <stdio.h> 4 #include <stdlib.h> 5 #include <string.h> 6 7 #include "util.h" 8 9 /* remove tailing or leading white space from s */ 10 char * 11 strtrim(char *s) 12 { 13 char *end; 14 15 /* trim leading space */ 16 while (isspace(*s)) s++; 17 18 if (*s == 0) /* all spaces? */ 19 return s; 20 21 /* trim trailing space */ 22 end = s + strlen(s) - 1; 23 while (end > s && isspace(*end)) end--; 24 25 /* write new null terminator */ 26 *(end+1) = 0; 27 28 return s; 29 } 30 31 /* return if str is in the list */ 32 int 33 strinlist(char *str, char **list, int listc) 34 { 35 if (!str || !list) return 0; 36 int i; 37 for (i = 0; i < listc; i++) 38 if (list[i] && strcmp(str, list[i]) == 0) 39 return 1; 40 return 0; 41 }