aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2009-02-21 18:25:30 +0000
committerTed Kremenek <kremenek@apple.com>2009-02-21 18:25:30 +0000
commit07bf7efa0ac1f7ca8ca57a675dd8c6e2c52df73a (patch)
tree75500105a7e8e7f72795a39d583e40d16c57c6a8 /include
parentb5bd026a756d8650f2a94607c9b1dc34cf1c024a (diff)
downloadexternal_llvm-07bf7efa0ac1f7ca8ca57a675dd8c6e2c52df73a.zip
external_llvm-07bf7efa0ac1f7ca8ca57a675dd8c6e2c52df73a.tar.gz
external_llvm-07bf7efa0ac1f7ca8ca57a675dd8c6e2c52df73a.tar.bz2
Add version of StringsEqualNoCase that takes two null-terminated C-strings and compares up to 'len' characters. I tend to screw up string comparison functions, so anyone who is interested please review this\!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@65236 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/llvm/ADT/StringExtras.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/include/llvm/ADT/StringExtras.h b/include/llvm/ADT/StringExtras.h
index 75b54f5..e40e409 100644
--- a/include/llvm/ADT/StringExtras.h
+++ b/include/llvm/ADT/StringExtras.h
@@ -159,6 +159,25 @@ static inline bool StringsEqualNoCase(const std::string &LHS,
}
return RHS[LHS.size()] == 0; // Not too long?
}
+
+/// StringsEqualNoCase - Return true if the two null-terminated C strings are
+/// equal, ignoring
+
+static inline bool StringsEqualNoCase(const char *LHS, const char *RHS,
+ unsigned len) {
+
+ for (unsigned i = 0; i < len; ++i) {
+ if (tolower(LHS[i]) != tolower(RHS[i]))
+ return false;
+
+ // If RHS[i] == 0 then LHS[i] == 0 or otherwise we would have returned
+ // at the previous branch as tolower('\0') == '\0'.
+ if (RHS[i] == 0)
+ return true;
+ }
+
+ return true;
+}
/// CStrInCStrNoCase - Portable version of strcasestr. Locates the first
/// occurance of c-string 's2' in string 's1', ignoring case. Returns