aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2018-12-09 14:46:14 +0000
committerRon Yorston <rmy@pobox.com>2018-12-09 14:47:42 +0000
commit6691b2e8d230e1c85d1a31a752f9f5b6933edbb0 (patch)
treef9e1c83e5adf9c48c758a18f68ec172983e03c86 /libbb
parent4a5a8422feab7d38f60d2576e32916f9cf711d29 (diff)
downloadbusybox-w32-6691b2e8d230e1c85d1a31a752f9f5b6933edbb0.tar.gz
busybox-w32-6691b2e8d230e1c85d1a31a752f9f5b6933edbb0.tar.bz2
busybox-w32-6691b2e8d230e1c85d1a31a752f9f5b6933edbb0.zip
win32: add a case-insensitive version of is_suffixed_with()
Diffstat (limited to 'libbb')
-rw-r--r--libbb/compare_string_array.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/libbb/compare_string_array.c b/libbb/compare_string_array.c
index 7ccdaef8a..856739c41 100644
--- a/libbb/compare_string_array.c
+++ b/libbb/compare_string_array.c
@@ -45,6 +45,7 @@ char* FAST_FUNC is_prefixed_with_case(const char *string, const char *key)
45 * beginning of prefix key in string. If key is an empty string return pointer 45 * beginning of prefix key in string. If key is an empty string return pointer
46 * to the end of string. 46 * to the end of string.
47 */ 47 */
48#if !ENABLE_PLATFORM_MINGW32
48char* FAST_FUNC is_suffixed_with(const char *string, const char *key) 49char* FAST_FUNC is_suffixed_with(const char *string, const char *key)
49{ 50{
50 size_t key_len = strlen(key); 51 size_t key_len = strlen(key);
@@ -59,6 +60,33 @@ char* FAST_FUNC is_suffixed_with(const char *string, const char *key)
59 60
60 return NULL; 61 return NULL;
61} 62}
63#else
64static char* FAST_FUNC is_suffixed(const char *string, const char *key,
65 int (*fn)(const char *, const char*))
66{
67 size_t key_len = strlen(key);
68 ssize_t len_diff = strlen(string) - key_len;
69
70 if (len_diff >= 0) {
71 string += len_diff;
72 if (fn(string, key) == 0) {
73 return (char*)string;
74 }
75 }
76
77 return NULL;
78}
79
80char* FAST_FUNC is_suffixed_with(const char *string, const char *key)
81{
82 return is_suffixed(string, key, strcmp);
83}
84
85char* FAST_FUNC is_suffixed_with_case(const char *string, const char *key)
86{
87 return is_suffixed(string, key, strcasecmp);
88}
89#endif
62 90
63/* returns the array index of the string */ 91/* returns the array index of the string */
64/* (index of first match is returned, or -1) */ 92/* (index of first match is returned, or -1) */