aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Sadie Powell2023-08-05 12:00:39 +0100
committerGravatar Sadie Powell2023-08-11 12:03:09 +0100
commitccf23ffa0b0bcd92a42b338ba47ccf569866ffa0 (patch)
tree29feb5d0e565d7ba2d58a9256850b017fe5535df
parentMove stdalgo::string::join to utility/string and templatise separator. (diff)
Move stdalgo::string::{equalsci,tocstr} to utility/string.
Co-authored-by: Attila Molnar <attilamolnar@hush.com> Co-authored-year: 2016
-rw-r--r--include/stdalgo.h32
-rw-r--r--include/utility/string.h27
2 files changed, 27 insertions, 32 deletions
diff --git a/include/stdalgo.h b/include/stdalgo.h
index 8a32ba553..b7c931f58 100644
--- a/include/stdalgo.h
+++ b/include/stdalgo.h
@@ -65,38 +65,6 @@ 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)));
- }
- }
-
/**
* Deletes all elements in a container using operator delete
* @param cont The container containing the elements to delete
diff --git a/include/utility/string.h b/include/utility/string.h
index a23ed20b8..03d17299c 100644
--- a/include/utility/string.h
+++ b/include/utility/string.h
@@ -56,4 +56,31 @@ namespace insp
sv.remove_suffix(std::distance(end, str.end()));
return sv;
}
+
+ /** Get underlying C string of the string passed as parameter. Useful in template functions.
+ * @param str A `const char*` string.
+ */
+ 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 A `std::string` string.
+ */
+ 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; otherwise, false.
+ */
+ template <typename S1, typename S2>
+ inline bool equalsci(const S1& str1, const S2& str2)
+ {
+ return (!strcasecmp(tocstr(str1), tocstr(str2)));
+ }
}