哪些开源C或c++库可以将任意UTF-32转换为NFC
What open source C or C++ libraries can convert arbitrary UTF-32 to NFC?
哪些开源C或c++库可以将任意UTF-32转换为NFC?
我认为到目前为止可以做到这一点的库:ICU, Qt, GLib(不确定?)。
我不需要任何其他复杂的Unicode支持;从任意但已知正确的UTF-32转换为NFC格式的UTF-32。
我最感兴趣的是一个可以直接做到这一点的库。例如,Qt和ICU(据我所知)都通过与UTF-16之间的中间转换阶段来完成所有工作。
ICU或Boost。现场(包装ICU)将是你最好的一个非常,非常长的路要走。规范化映射将与来自更多软件的映射等效,我认为这是此转换的重点。
这是我在决定使用ICU后最终使用的代码的主要部分。我想我应该把它放在这里,以防它对尝试同样事情的人有所帮助。
std::string normalize(const std::string &unnormalized_utf8) {
// FIXME: until ICU supports doing normalization over a UText
// interface directly on our UTF-8, we'll use the insanely less
// efficient approach of converting to UTF-16, normalizing, and
// converting back to UTF-8.
// Convert to UTF-16 string
auto unnormalized_utf16 = icu::UnicodeString::fromUTF8(unnormalized_utf8);
// Get a pointer to the global NFC normalizer
UErrorCode icu_error = U_ZERO_ERROR;
const auto *normalizer = icu::Normalizer2::getInstance(nullptr, "nfc", UNORM2_COMPOSE, icu_error);
assert(U_SUCCESS(icu_error));
// Normalize our string
icu::UnicodeString normalized_utf16;
normalizer->normalize(unnormalized_utf16, normalized_utf16, icu_error);
assert(U_SUCCESS(icu_error));
// Convert back to UTF-8
std::string normalized_utf8;
normalized_utf16.toUTF8String(normalized_utf8);
return normalized_utf8;
}
相关文章:
- HEX值到wchar_t字符(UTF-8)的转换
- 用常见虚拟函数实现的任意组合来实现派生类的正确方法是什么
- 将应用程序从32位移植到64位时出现问题
- 带有Protobuf序列化的C++Hazelcast:字符串不是UTF-8格式的
- 转换特殊字符(UTF-8)
- C++读取和写入 UTF-32 文件
- 在这种情况下,UTF-16 和 UTF-32 的 BOM 是强制性的
- 在 Linux 中将 UTF-32 宽字符转换为 UTF-16 宽字符以获取补充平面字符
- cpp 预处理器无法识别 UTF-32 字符串
- 如何使Windows 7支持12000(UTF-32)代码页或1200(UTF-16)代码页
- 将 UTF-8 转换为 UTF-32,预先计算每个'chars'数
- std::wstring在Windows上支持UTF-16和UTF-32吗
- 在C++内部使用UTF-8与UTF-16与UTF-32
- Linux控制台的国际UTF-32字符串输出
- 哪些开源C或c++库可以将任意UTF-32转换为NFC
- 读取Unicode UTF-32文件到wstring
- c++是否支持除UTF-8、UTF-16和UTF-32以外的字符编码之间的转换?
- 将UTF-32字符打印到终端
- 如何在Linux上使用std库从utf-16转换为utf-32
- 在使用STL的迭代器上使用UTF-8到UTF-32