]> Nutra Git (v1) - gamesguru/feather.git/commitdiff
polyseed: use Qt for Unicode normalization
authortobtoht <tob@featherwallet.org>
Sat, 10 Jun 2023 20:37:29 +0000 (22:37 +0200)
committertobtoht <tob@featherwallet.org>
Sat, 10 Jun 2023 20:58:24 +0000 (22:58 +0200)
Boost is unreliable for this purpose

src/polyseed/polyseed.cpp

index e5f206e53d370e581ea3f2624617b5592df9d77d..9074687528b64d4d25bdbdbee750ae1767d2eae7 100644 (file)
@@ -9,17 +9,18 @@
 #include <sodium/randombytes.h>
 #include <boost/locale.hpp>
 
-#include <cstdint>
-#include <cstring>
-#include <algorithm>
 #include <array>
 
+#include <QString>
+
 namespace polyseed {
 
     static std::locale locale;
 
     static size_t utf8_nfc(const char* str, polyseed_str norm) {
-        auto s = boost::locale::normalize(str, boost::locale::norm_type::norm_nfc, locale);
+        auto Qstr = QString(str);
+        auto Qs = Qstr.normalized(QString::NormalizationForm_C);
+        auto s = Qs.toStdString();
         size_t size = std::min(s.size(), (size_t)POLYSEED_STR_SIZE - 1);
         s.copy(norm, size);
         norm[size] = '\0';
@@ -28,7 +29,9 @@ namespace polyseed {
     }
 
     static size_t utf8_nfkd(const char* str, polyseed_str norm) {
-        auto s = boost::locale::normalize(str, boost::locale::norm_type::norm_nfkd, locale);
+        auto Qstr = QString(str);
+        auto Qs = Qstr.normalized(QString::NormalizationForm_KD);
+        auto s = Qs.toStdString();
         size_t size = std::min(s.size(), (size_t)POLYSEED_STR_SIZE - 1);
         s.copy(norm, size);
         norm[size] = '\0';