繁体   English   中英

带有 boost::locale::normalize 的 bad_cast 错误

[英]bad_cast error with boost::locale::normalize

我正在尝试使用 boost 将包含 txt 文件内容的字符串转换为 unicode 字符串 C++ 并在此之后对其进行规范化。 不幸的是,我得到了 bad_cast 错误。 任何人都可以帮忙吗? 代码:

convert_to_wstring(void *buffer, int length) {
    boost::locale::generator g;
    g.locale_cache_enabled(true);
    std::locale loc = g(boost::locale::util::get_system_locale());
    std::string buffer_char = static_cast<char *>(buffer);
    std::wstring result = boost::locale::conv::to_utf<wchar_t>(buffer_char, loc);
    result = boost::locale::normalize(result);
    result = boost::locale::fold_case(result);
    return result;
}

我正在研究它。 问题是在某些语言环境中规范化字符串之前应该生成它,所以固定代码如下所示:

convert_to_wstring(void *buffer, int length) {
    boost::locale::generator gen;
    gen.locale_cache_enabled(true);
    std::locale loc = gen(boost::locale::util::get_system_locale());
    std::string buffer_char = static_cast<char *>(buffer);
    std::wstring result = boost::locale::conv::to_utf<wchar_t>(buffer_char, loc);
    std::locale locale = gen("UTF-8");
    std::locale::global(locale);
    result = boost::locale::normalize(result);
    result = boost::locale::fold_case(result);
    return result;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM