aboutsummaryrefslogtreecommitdiff
path: root/libbb/compare_string_array.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2015-03-14 20:33:00 +0000
committerRon Yorston <rmy@pobox.com>2015-03-14 20:33:00 +0000
commita4f58436b78fe59e57620c6e0301f213ee25f273 (patch)
tree8355f724926e605280af2d6f2b1ccc6b1bd02dee /libbb/compare_string_array.c
parentba0c36cfcf84efbac6f89e27238e04bb57e9cd45 (diff)
parent49acc1a7618a28d34381cbb7661d7c981fcb238f (diff)
downloadbusybox-w32-a4f58436b78fe59e57620c6e0301f213ee25f273.tar.gz
busybox-w32-a4f58436b78fe59e57620c6e0301f213ee25f273.tar.bz2
busybox-w32-a4f58436b78fe59e57620c6e0301f213ee25f273.zip
Merge branch 'busybox' into merge
Conflicts: coreutils/od_bloaty.c libbb/lineedit.c
Diffstat (limited to 'libbb/compare_string_array.c')
-rw-r--r--libbb/compare_string_array.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/libbb/compare_string_array.c b/libbb/compare_string_array.c
index 4b10cc138..e24815a03 100644
--- a/libbb/compare_string_array.c
+++ b/libbb/compare_string_array.c
@@ -5,6 +5,24 @@
5 5
6#include "libbb.h" 6#include "libbb.h"
7 7
8char* FAST_FUNC is_prefixed_with(const char *string, const char *key)
9{
10#if 0 /* Two passes over key - probably slower */
11 int len = strlen(key);
12 if (strncmp(string, key, len) == 0)
13 return string + len;
14 return NULL;
15#else /* Open-coded */
16 while (*key != '\0') {
17 if (*key != *string)
18 return NULL;
19 key++;
20 string++;
21 }
22 return (char*)string;
23#endif
24}
25
8/* returns the array index of the string */ 26/* returns the array index of the string */
9/* (index of first match is returned, or -1) */ 27/* (index of first match is returned, or -1) */
10int FAST_FUNC index_in_str_array(const char *const string_array[], const char *key) 28int FAST_FUNC index_in_str_array(const char *const string_array[], const char *key)
@@ -39,10 +57,9 @@ int FAST_FUNC index_in_strings(const char *strings, const char *key)
39int FAST_FUNC index_in_substr_array(const char *const string_array[], const char *key) 57int FAST_FUNC index_in_substr_array(const char *const string_array[], const char *key)
40{ 58{
41 int i; 59 int i;
42 int len = strlen(key); 60 if (key[0]) {
43 if (len) {
44 for (i = 0; string_array[i] != 0; i++) { 61 for (i = 0; string_array[i] != 0; i++) {
45 if (strncmp(string_array[i], key, len) == 0) { 62 if (is_prefixed_with(string_array[i], key)) {
46 return i; 63 return i;
47 } 64 }
48 } 65 }