summaryrefslogtreecommitdiff
path: root/include/stdalgo.h
diff options
context:
space:
mode:
authorAttila Molnar <attilamolnar@hush.com>2016-08-22 16:46:44 +0200
committerAttila Molnar <attilamolnar@hush.com>2016-08-22 16:46:44 +0200
commit90ea1b01b78a94486b8142808c06aacff543ca64 (patch)
tree50d3582ff28f56a3816307cc6e10fc4f775d2e2a /include/stdalgo.h
parent0562561425f133874685789269c8ab1aa053c95f (diff)
Add stdalgo::string::equalsci and use it instead of irc::string for case-insensitive comparison
Diffstat (limited to 'include/stdalgo.h')
-rw-r--r--include/stdalgo.h32
1 files changed, 32 insertions, 0 deletions
diff --git a/include/stdalgo.h b/include/stdalgo.h
index 3e00a4cdc..12ec76275 100644
--- a/include/stdalgo.h
+++ b/include/stdalgo.h
@@ -64,6 +64,38 @@ namespace stdalgo
}
}
+ namespace string
+ {
+ /** Get underlying C string of the string passed as parameter. Useful in template functions.
+ * @param str C string
+ * @return Same as input
+ */
+ inline const char* tocstr(const char* str)
+ {
+ return str;
+ }
+
+ /** Get underlying C string of the string passed as parameter. Useful in template functions.
+ * @param str std::string object
+ * @return str.c_str()
+ */
+ inline const char* tocstr(const std::string& str)
+ {
+ return str.c_str();
+ }
+
+ /** Check if two strings are equal case insensitively.
+ * @param str1 First string to compare.
+ * @param str2 Second string to compare.
+ * @return True if the strings are equal case-insensitively, false otherwise.
+ */
+ template <typename S1, typename S2>
+ inline bool equalsci(const S1& str1, const S2& str2)
+ {
+ return (!strcasecmp(tocstr(str1), tocstr(str2)));
+ }
+ }
+
/**
* Deleter that uses operator delete to delete the item
*/