summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2022-11-17 04:15:38 -0500
committerWilliam Wilgus <wilgus.william@gmail.com>2022-11-17 04:15:38 -0500
commit00f915d92ea6cce33110484814dc17ae47509969 (patch)
treee61a99063d10230329220d1d2aa6a0e722c3a453
parent972810f6cfd9715de1b182978c4d26e67dcf72cf (diff)
downloadrockbox-00f915d92e.tar.gz
rockbox-00f915d92e.zip
strnatcmp.c use a fn pointer to call strcmp/strcasecmp
Change-Id: I2bfaeec4cf2af4bed8f0781bcfa24b0b104fb22a
-rw-r--r--firmware/common/strnatcmp.c16
1 files changed, 6 insertions, 10 deletions
diff --git a/firmware/common/strnatcmp.c b/firmware/common/strnatcmp.c
index 0084ff3582..d77f7e995e 100644
--- a/firmware/common/strnatcmp.c
+++ b/firmware/common/strnatcmp.c
@@ -122,7 +122,8 @@ compare_left(char const *a, char const *b)
return 0;
}
-static int strnatcmp0(char const *a, char const *b, int fold_case)
+static int strnatcmp0(char const *a, char const *b,
+ int (*cmp_fn)(const char*, const char*))
{
int ai, bi;
int ca, cb;
@@ -150,13 +151,10 @@ static int strnatcmp0(char const *a, char const *b, int fold_case)
if (!ca && !cb) {
/* The strings compare the same. Call str[case]cmp() to ensure
consistent results. */
- if(fold_case)
- return strcasecmp(a,b);
- else
- return strcmp(a,b);
+ return cmp_fn(a,b);
}
- if (fold_case) {
+ if (cmp_fn == &strcasecmp) {
ca = nat_unify_case(ca);
cb = nat_unify_case(cb);
}
@@ -170,14 +168,12 @@ static int strnatcmp0(char const *a, char const *b, int fold_case)
}
}
-
-
int strnatcmp(const char *a, const char *b) {
- return strnatcmp0(a, b, 0);
+ return strnatcmp0(a, b, strcmp);
}
/* Compare, recognizing numeric string and ignoring case. */
int strnatcasecmp(const char *a, const char *b) {
- return strnatcmp0(a, b, 1);
+ return strnatcmp0(a, b, &strcasecmp);
}