diff options
| author | ailurux <ailuruxx@gmail.com> | 2023-11-09 16:31:20 +1100 |
|---|---|---|
| committer | ailurux <ailuruxx@gmail.com> | 2023-11-09 16:31:20 +1100 |
| commit | d42de6b12292ead077e79d1edb72b52a39767909 (patch) | |
| tree | 8efe501d4e8539605cb19f930a159fd5e8393f49 /src/locale/collation.cpp | |
| parent | c1db38ba42607a3b70f5e624365f39f0e782bd24 (diff) | |
| download | tangara-fw-d42de6b12292ead077e79d1edb72b52a39767909.tar.gz | |
Fixed extra null bytes at the end of collations
Diffstat (limited to 'src/locale/collation.cpp')
| -rw-r--r-- | src/locale/collation.cpp | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/src/locale/collation.cpp b/src/locale/collation.cpp index 31465645..2c7e1d0c 100644 --- a/src/locale/collation.cpp +++ b/src/locale/collation.cpp @@ -86,16 +86,12 @@ GLibCollator::~GLibCollator() { } auto GLibCollator::Transform(const std::string& in) -> std::string { - char dest[256]; - size_t size = glib_strxfrm(dest, in.c_str(), 256, locale_data_.get()); - if (size >= 256) { - char* larger_dest = new char[size + 1]{0}; - glib_strxfrm(larger_dest, in.c_str(), size, locale_data_.get()); - std::string out{larger_dest, size}; - delete[] larger_dest; - return out; - } - return {dest, size}; + size_t size = glib_strxfrm(NULL, in.c_str(), 0, locale_data_.get()); + char* dest = new char[size + 1]{0}; + glib_strxfrm(dest, in.c_str(), size, locale_data_.get()); + std::string out{dest, strnlen(dest, size)}; + delete[] dest; + return out; } } // namespace locale |
