aboutsummaryrefslogtreecommitdiff
path: root/src/common/Utilities
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/Utilities')
-rw-r--r--src/common/Utilities/Util.cpp16
-rw-r--r--src/common/Utilities/Util.h14
2 files changed, 22 insertions, 8 deletions
diff --git a/src/common/Utilities/Util.cpp b/src/common/Utilities/Util.cpp
index c374bff9cf1..fc2a9519a3f 100644
--- a/src/common/Utilities/Util.cpp
+++ b/src/common/Utilities/Util.cpp
@@ -818,10 +818,10 @@ std::string Trinity::Impl::ByteArrayToHexStr(uint8 const* bytes, size_t arrayLen
}
std::string result;
- result.reserve(arrayLen * 2);
- auto inserter = std::back_inserter(result);
+ result.resize(arrayLen * 2);
+ auto inserter = result.data();
for (int32 i = init; i != end; i += op)
- Trinity::StringFormatTo(inserter, "{:02X}", bytes[i]);
+ inserter = Trinity::StringFormatTo(inserter, "{:02X}", bytes[i]);
return result;
}
@@ -862,6 +862,16 @@ bool StringCompareLessI(std::string_view a, std::string_view b)
return std::ranges::lexicographical_compare(a, b, {}, charToLower, charToLower);
}
+void StringReplaceAll(std::string* str, std::string_view text, std::string_view replacement)
+{
+ std::size_t pos = str->find(text, 0);
+ while (pos != std::string::npos)
+ {
+ str->replace(pos, text.length(), replacement);
+ pos = str->find(text, pos + replacement.length());
+ }
+}
+
std::string Trinity::Impl::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 8e78797caef..a16e6ba0e89 100644
--- a/src/common/Utilities/Util.h
+++ b/src/common/Utilities/Util.h
@@ -464,11 +464,6 @@ TC_COMMON_API bool StringEqualI(std::string_view str1, std::string_view str2);
inline bool StringStartsWith(std::string_view haystack, std::string_view needle) { return (haystack.substr(0, needle.length()) == needle); }
inline bool StringStartsWithI(std::string_view haystack, std::string_view needle) { return StringEqualI(haystack.substr(0, needle.length()), needle); }
TC_COMMON_API bool StringContainsStringI(std::string_view haystack, std::string_view needle);
-template <typename T>
-inline bool ValueContainsStringI(std::pair<T, std::string_view> const& haystack, std::string_view needle)
-{
- return StringContainsStringI(haystack.second, needle);
-}
TC_COMMON_API bool StringCompareLessI(std::string_view a, std::string_view b);
struct StringCompareLessI_T
@@ -476,6 +471,15 @@ struct StringCompareLessI_T
bool operator()(std::string_view a, std::string_view b) const { return StringCompareLessI(a, b); }
};
+TC_COMMON_API void StringReplaceAll(std::string* str, std::string_view text, std::string_view replacement);
+
+[[nodiscard]] inline std::string StringReplaceAll(std::string_view str, std::string_view text, std::string_view replacement)
+{
+ std::string result(str);
+ StringReplaceAll(&result, text, replacement);
+ return result;
+}
+
// simple class for not-modifyable list
template <typename T>
class HookList final