19 #include <sys/types.h>
20 #include <netinet/in.h>
21 #include <arpa/inet.h>
24 #include <bsd/string.h>
25 #include <sys/socket.h>
52 static __inline__
char *
55 if (!str || !*str || !set || (strlen(set) != 2))
59 while ((*str == set[0]) || isspace(*str))
63 char *p = &str[strlen(str) - 1];
65 while ((p >= str) && (isspace(*p) || (*p == set[1])))
82 static __inline__
char *
85 if (strlen(str) >= 2) {
88 else if (str[0] ==
'\'')
103 static __inline__
char *
110 while (isspace(*str))
115 char *p = &str[strlen(str) - 1];
118 while ((p >= str) && isspace(*p))
141 static __inline__
int
142 cne_strtok(
char *str,
const char *delim,
char *entries[],
int maxtokens)
147 if (!str || !delim || !strlen(delim) || !entries || !maxtokens)
153 entries[i] =
strtrim(strtok_r(str, delim, &saved));
155 }
while (entries[i] && (++i < maxtokens));
175 static __inline__
int
176 cne_strqtok(
char *str,
const char *delim,
char *argv[],
int maxtokens)
178 char *p, *start_of_word, *s;
180 enum { INIT, WORD, STRING_QUOTE, STRING_TICK, STRING_BRACKET } state = WORD;
182 if (!str || !delim || !argv || maxtokens == 0)
189 for (p = s; (argc < maxtokens) && (*p !=
'\0'); p++) {
190 int c = (
unsigned char)*p;
200 state = STRING_QUOTE;
201 start_of_word = p + 1;
202 }
else if (c ==
'\'') {
204 start_of_word = p + 1;
205 }
else if (c ==
'{') {
206 state = STRING_BRACKET;
207 start_of_word = p + 1;
208 }
else if (!strchr(delim, c)) {
217 argv[argc++] = start_of_word;
225 argv[argc++] = start_of_word;
233 argv[argc++] = start_of_word;
239 if (strchr(delim, c)) {
241 argv[argc++] = start_of_word;
243 start_of_word = p + 1;
252 if ((state != INIT) && (argc < maxtokens))
253 argv[argc++] = start_of_word;
255 if ((argc == 0) && (p != str))
271 static __inline__
char *
277 for (
int i = 0; i <= (int)(strlen(str)); i++)
278 str[i] = tolower(str[i]);
292 static __inline__
char *
298 for (
int i = 0; i <= (int)(strlen(str)); i++)
299 str[i] = toupper(str[i]);
316 static __inline__
int
321 if (!list || !str || !delim)
324 if ((list[0] ==
'%') && (list[1] ==
'|'))
330 size_t n = strlen(list) + 2;
332 buf = (
char *)alloca(n);
334 snprintf(buf, n,
"%s", list);
339 for (
int i = 0; i < nb; i++)
340 if (!strcmp(argv[i], str))
351 static __inline__
char *
356 return (newstr == NULL) ? NULL : strdup(newstr);
369 static __inline__
int
372 return (s == NULL || *s ==
'\0') ? 0 :
cne_strcnt(s + 1, c) + (*s == c);
387 static __inline__
int
392 else if (mask == 0xFF000000)
394 else if (mask == 0xFFFF0000)
396 else if (mask == 0xFFFFFF00)
398 else if (mask == 0xFFFFFFFF)
402 for (i = 0; i < 32; i++)
403 if ((mask & (1 << (31 - i))) == 0)
static __inline__ int cne_strtok(char *str, const char *delim, char *entries[], int maxtokens)
static __inline__ int mask_size(uint32_t mask)
static __inline__ int cne_strcnt(char *s, char c)
static __inline__ char * strtrim(char *str)
static __inline__ int cne_stropt(const char *list, char *str, const char *delim)
static __inline__ char * cne_strtolower(char *str)
static __inline__ char * cne_strdupf(char *str, char *newstr)
static __inline__ char * cne_strtoupper(char *str)
static __inline__ char * strtrimset(char *str, const char *set)
static __inline__ char * strtrim_quotes(char *str)
static __inline__ int cne_strqtok(char *str, const char *delim, char *argv[], int maxtokens)