polyseed: use Qt for Unicode normalization

Boost is unreliable for this purpose
This commit is contained in:
tobtoht 2023-06-10 22:37:29 +02:00
parent 1d515d8e93
commit 744c892ba0
No known key found for this signature in database
GPG key ID: E45B10DD027D2472

View 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';