diff options
Diffstat (limited to 'src/common/Utilities')
| -rw-r--r-- | src/common/Utilities/Util.cpp | 21 | ||||
| -rw-r--r-- | src/common/Utilities/Util.h | 12 |
2 files changed, 26 insertions, 7 deletions
diff --git a/src/common/Utilities/Util.cpp b/src/common/Utilities/Util.cpp index c51cb954c91..e277a3aae95 100644 --- a/src/common/Utilities/Util.cpp +++ b/src/common/Utilities/Util.cpp @@ -29,6 +29,7 @@ #include <cctype> #include <cstdarg> #include <ctime> +#include <boost/core/demangle.hpp> #if TRINITY_COMPILER == TRINITY_COMPILER_GNU #include <sys/socket.h> @@ -646,17 +647,23 @@ void Trinity::Impl::HexStrToByteArray(std::string_view str, uint8* out, size_t o } } -bool StringEqualI(std::string_view str1, std::string_view str2) +bool StringEqualI(std::string_view a, std::string_view b) { - return std::equal(str1.begin(), str1.end(), str2.begin(), str2.end(), - [](char a, char b) - { - return std::tolower(a) == std::tolower(b); - }); + return std::equal(a.begin(), a.end(), b.begin(), b.end(), [](char c1, char c2) { return std::tolower(c1) == std::tolower(c2); }); } bool StringContainsStringI(std::string_view haystack, std::string_view needle) { return haystack.end() != - std::search(haystack.begin(), haystack.end(), needle.begin(), needle.end(), [](char c1, char c2) { return std::toupper(c1) == std::toupper(c2); }); + std::search(haystack.begin(), haystack.end(), needle.begin(), needle.end(), [](char c1, char c2) { return std::tolower(c1) == std::tolower(c2); }); +} + +bool StringCompareLessI(std::string_view a, std::string_view b) +{ + return std::lexicographical_compare(a.begin(), a.end(), b.begin(), b.end(), [](char c1, char c2) { return std::tolower(c1) < std::tolower(c2); }); +} + +std::string GetTypeName(std::type_info const& info) +{ + return boost::core::demangle(info.name()); } diff --git a/src/common/Utilities/Util.h b/src/common/Utilities/Util.h index 170fbbd52d9..cf4c6cff23f 100644 --- a/src/common/Utilities/Util.h +++ b/src/common/Utilities/Util.h @@ -26,6 +26,7 @@ #include <string> #include <string_view> #include <sstream> +#include <typeinfo> #include <utility> #include <vector> @@ -339,6 +340,11 @@ inline bool ValueContainsStringI(std::pair<T, std::string_view> const& haystack, { return StringContainsStringI(haystack.second, needle); } +TC_COMMON_API bool StringCompareLessI(std::string_view a, std::string_view b); + +struct StringCompareLessI_T { + bool operator()(std::string_view a, std::string_view b) const { return StringCompareLessI(a, b); } +}; // simple class for not-modifyable list template <typename T> @@ -544,4 +550,10 @@ Ret* Coalesce(T1* first, T*... rest) return static_cast<Ret*>(first); } +TC_COMMON_API std::string GetTypeName(std::type_info const&); +template <typename T> +std::string GetTypeName() { return GetTypeName(typeid(T)); } +template <typename T> +std::enable_if_t<!std::is_same_v<std::decay_t<T>, std::type_info>, std::string> GetTypeName(T&& v) { return GetTypeName(typeid(v)); } + #endif |
