summaryrefslogtreecommitdiff
path: root/louloulibs/utils
diff options
context:
space:
mode:
Diffstat (limited to 'louloulibs/utils')
-rw-r--r--louloulibs/utils/encoding.cpp9
1 files changed, 4 insertions, 5 deletions
diff --git a/louloulibs/utils/encoding.cpp b/louloulibs/utils/encoding.cpp
index 4b20797..712028e 100644
--- a/louloulibs/utils/encoding.cpp
+++ b/louloulibs/utils/encoding.cpp
@@ -75,13 +75,12 @@ namespace utils
std::string remove_invalid_xml_chars(const std::string& original)
{
// The given string MUST be a valid utf-8 string
- unsigned char* res = new unsigned char[original.size()];
- const auto sg = utils::make_scope_guard([&res](auto&&) { delete[] res;});
+ std::vector<char> res(original.size(), '\0');
// pointer where we write valid chars
- unsigned char* r = res;
+ char* r = res.data();
- const unsigned char* str = reinterpret_cast<const unsigned char*>(original.c_str());
+ const char* str = original.c_str();
std::bitset<20> codepoint;
while (*str)
@@ -140,7 +139,7 @@ namespace utils
else
throw std::runtime_error("Invalid UTF-8 passed to remove_invalid_xml_chars");
}
- return {reinterpret_cast<char*>(res), static_cast<size_t>(r-res)};
+ return {res.data(), static_cast<size_t>(r - res.data())};
}
std::string convert_to_utf8(const std::string& str, const char* charset)