1 /* vi: set sw=4 ts=4: */
3 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
8 char* FAST_FUNC is_prefixed_with(const char *string, const char *key)
10 #if 0 /* Two passes over key - probably slower */
11 int len = strlen(key);
12 if (strncmp(string, key, len) == 0)
15 #else /* Open-coded */
16 while (*key != '\0') {
26 /* returns the array index of the string */
27 /* (index of first match is returned, or -1) */
28 int FAST_FUNC index_in_str_array(const char *const string_array[], const char *key)
32 for (i = 0; string_array[i] != 0; i++) {
33 if (strcmp(string_array[i], key) == 0) {
40 int FAST_FUNC index_in_strings(const char *strings, const char *key)
45 if (strcmp(strings, key) == 0) {
48 strings += strlen(strings) + 1; /* skip NUL */
54 /* returns the array index of the string, even if it matches only a beginning */
55 /* (index of first match is returned, or -1) */
57 int FAST_FUNC index_in_substr_array(const char *const string_array[], const char *key)
61 for (i = 0; string_array[i] != 0; i++) {
62 if (is_prefixed_with(string_array[i], key)) {
71 int FAST_FUNC index_in_substrings(const char *strings, const char *key)
74 const int len = strlen(key);
79 if (strncmp(strings, key, len) == 0) {
80 if (strings[len] == '\0')
81 return idx; /* exact match */
83 return -1; /* ambiguous match */
86 strings += strlen(strings) + 1; /* skip NUL */
93 const char* FAST_FUNC nth_string(const char *strings, int n)
97 strings += strlen(strings) + 1;
102 #ifdef UNUSED_SO_FAR /* only brctl.c needs it yet */
103 /* Returns 0 for no, 1 for yes or a negative value on error. */
104 smallint FAST_FUNC yesno(const char *str)
106 static const char no_yes[] ALIGN1 =
108 "1\0" "on\0" "yes\0";
109 int ret = index_in_substrings(no_yes, str);