为什么使用tinyxml2-ex ::文本返回损坏的文本?

发布于 2025-02-12 19:12:30 字数 918 浏览 0 评论 0原文

我正在尝试使用 tinyxml2-ex读取一些库来阅读一些库XML数据。

当我尝试使用它的特定API调用时:

const CString strNameToUse(tinyxml2::text(pAssign).c_str());

结果字符串会失去口音之类的东西。最后,我通过UTF8处理恢复了我的原始方法:

const CString strNameToUse(CA2CT(pAssign->GetText(), CP_UTF8));

这很好。有人知道为什么tinyxml2-ex :: text方法失败了吗?请注意,使用tinyxml2名称空间是允许使用的。


引用库的是std :: String,并且这样做:

// helper function to get element text as a string, blank if none
inline std::string text (const XMLElement * element)
{
    if (!element)
        throw XmlException ("null element"s);

    if (auto value = element -> GetText())
        return std::string (value);
    else
        return ""s;
}

I am trying to use the tinyxml2-ex library to read some XML data.

When I try using it's specific API call:

const CString strNameToUse(tinyxml2::text(pAssign).c_str());

The resulting string loses things like accents. In the end I have reverted to my original approach with the UTF8 handling:

const CString strNameToUse(CA2CT(pAssign->GetText(), CP_UTF8));

This works fine. Does anyone know why the tinyxml2-ex::text approach fails? Note that it is permissible to the use the tinyxml2 namespace.


The referred to library is using std::string and does it like this:

// helper function to get element text as a string, blank if none
inline std::string text (const XMLElement * element)
{
    if (!element)
        throw XmlException ("null element"s);

    if (auto value = element -> GetText())
        return std::string (value);
    else
        return ""s;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

榆西 2025-02-19 19:12:30

图书馆作者解释说(github

这是因为tixml2ex :: text(请参阅tixml2ex.h in Line 465 in

if (auto value = element -> GetText())
    return std::string (value);

将损坏ASCII外部包含字符的任何字符串127。

The library author explained (GitHub discussion:

It's because tixml2ex::text (see line 465 in tixml2ex.h) does this:

if (auto value = element -> GetText())
    return std::string (value);

which will corrupt any string containing characters outside ASCII 127.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文