* str_icmp,
* str_nicmp - compare two strings ignoring case
*
+ * str_delim - locate the first occurrence of a delimiter
+ *
* str_istr - locate a substring ignoring case
*
* mem_mem,
}
+/*
+ * str_delim - locate the first occurrence of a delimiter
+ *
+ * The str_delim() function finds the first occurrence in the string s
+ * of one of the characters in the string delim.
+ *
+ * The function returns a pointer to the first occurrence of one of the
+ * specified delimiters, or a pointer to the terminating null character
+ * at the end of s, if no such occurrence was found.
+ */
+static inline char *str_delim(const char *s, const char *delim) {
+ while (!strchr(delim, *s))
+ ++s;
+ return (char *)s;
+}
+
+
/*
* str_istr - locate a substring ignoring case
*
for (int i = 0; i < (int)sizeof(s_); ++i) { \
if (s_[i] == 0) \
fprintf(stderr, "\\0"); \
- else if (s_[i] < ' ' || s_[i] > 127) \
- fprintf(stderr, "\\x%02"PRIX8, (uint8_t)(s_[i])); \
+ else if (!isprint(s_[i])) \
+ fprintf(stderr, "\\x%02"PRIx8, (uint8_t)(s_[i])); \
else \
fputc(s_[i], stderr); \
} \
T(str_nicmp("まほaSdf", "まほasdF", 1) == 0);
T(str_nicmp("asdf", "asdF", 1) == 0);
+ H("str_delim");
+ char s1[] = "abc:def,\r\n\tghi";
+ D(s1);
+ T(str_delim(s1, "") - s1 == (int)strlen(s1));
+ T(str_delim(s1, "*") - s1 == (int)strlen(s1));
+ T(str_delim(s1, "i") - s1 == (int)strlen(s1)-1);
+ T(str_delim(s1, ":") - s1 == 3);
+ T(str_delim(s1, "-_:") - s1 == 3);
+ T(str_delim(s1, "e,") - s1 == 5);
+ T(str_delim(s1, ",#'") - s1 == 7);
+ T(str_delim(s1, "\n\r") - s1 == 8);
+
H("str_istr");
char h1[] = "asdfま\0ほyxc";
char h2[] = "";