From ccf23ffa0b0bcd92a42b338ba47ccf569866ffa0 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Sat, 5 Aug 2023 12:00:39 +0100 Subject: Move stdalgo::string::{equalsci,tocstr} to utility/string. Co-authored-by: Attila Molnar Co-authored-year: 2016 --- include/utility/string.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'include/utility/string.h') 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 + inline bool equalsci(const S1& str1, const S2& str2) + { + return (!strcasecmp(tocstr(str1), tocstr(str2))); + } } -- cgit v1.3.1-10-gc9f91