diff options
author | louiz’ <louiz@louiz.org> | 2016-10-27 01:37:55 +0200 |
---|---|---|
committer | louiz’ <louiz@louiz.org> | 2016-10-27 01:37:55 +0200 |
commit | ac61450184112ccb22971cff6cfa6117b4ddfbb6 (patch) | |
tree | 1f8dabe9c000d0132609fd813373d79cf657a198 /louloulibs/utils | |
parent | 6d65e9527e90dda7b76168be23690dfead73c847 (diff) | |
download | biboumi-ac61450184112ccb22971cff6cfa6117b4ddfbb6.tar.gz biboumi-ac61450184112ccb22971cff6cfa6117b4ddfbb6.tar.bz2 biboumi-ac61450184112ccb22971cff6cfa6117b4ddfbb6.tar.xz biboumi-ac61450184112ccb22971cff6cfa6117b4ddfbb6.zip |
Refactor remove_invalid_xml_chars to use correct types directly
Diffstat (limited to 'louloulibs/utils')
-rw-r--r-- | louloulibs/utils/encoding.cpp | 9 |
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) |