aboutsummaryrefslogtreecommitdiff
path: root/common/str.cpp
diff options
context:
space:
mode:
authorMax Horn2011-05-23 18:32:42 +0200
committerMax Horn2011-05-23 19:12:25 +0200
commit8e3aafd30d14bcd586cc06a525e2dc2a8298c7b2 (patch)
tree63038cba9ad4d0dd72a65749ee7ac7410ac76edc /common/str.cpp
parent3931e1dc50ad773aa3f9d95b2810857a3e7ce943 (diff)
downloadscummvm-rg350-8e3aafd30d14bcd586cc06a525e2dc2a8298c7b2.tar.gz
scummvm-rg350-8e3aafd30d14bcd586cc06a525e2dc2a8298c7b2.tar.bz2
scummvm-rg350-8e3aafd30d14bcd586cc06a525e2dc2a8298c7b2.zip
COMMON: Provide our own implementations for scumm_str(n)icmp
This takes up a tiny little bit of extra binary size, but gets rid of some awful #ifdef hackery.
Diffstat (limited to 'common/str.cpp')
-rw-r--r--common/str.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/common/str.cpp b/common/str.cpp
index 08a6cb6822..740e7b6a06 100644
--- a/common/str.cpp
+++ b/common/str.cpp
@@ -833,3 +833,36 @@ size_t strlcat(char *dst, const char *src, size_t size) {
}
} // End of namespace Common
+
+// Portable implementation of stricmp / strcasecmp / strcmpi.
+// TODO: Rename this to Common::strcasecmp
+int scumm_stricmp(const char *s1, const char *s2) {
+ byte l1, l2;
+ do {
+ // Don't use ++ inside tolower, in case the macro uses its
+ // arguments more than once.
+ l1 = (byte)*s1++;
+ l1 = tolower(l1);
+ l2 = (byte)*s2++;
+ l2 = tolower(l2);
+ } while (l1 == l2 && l1 != 0);
+ return l1 - l2;
+}
+
+// Portable implementation of strnicmp / strncasecmp / strncmpi.
+// TODO: Rename this to Common::strncasecmp
+int scumm_strnicmp(const char *s1, const char *s2, uint n) {
+ byte l1, l2;
+ do {
+ if (n-- == 0)
+ return 0; // no difference found so far -> signal equality
+
+ // Don't use ++ inside tolower, in case the macro uses its
+ // arguments more than once.
+ l1 = (byte)*s1++;
+ l1 = tolower(l1);
+ l2 = (byte)*s2++;
+ l2 = tolower(l2);
+ } while (l1 == l2 && l1 != 0);
+ return l1 - l2;
+}