使用RapidXml解析日语汉字时出错

时间:2012-04-23 15:56:08

标签: c++ xml unicode xml-parsing rapidxml

当我尝试解析包含特定汉字的xml文件时出现问题:

退

调试后,我发现问题出在RapidXml的这个函数中:

struct text_pure_no_ws_pred
{
    static unsigned char test(Ch ch)
    {
        return internal::lookup_tables<0>::lookup_text_pure_no_ws[static_cast<unsigned char>(ch)];
    }
};


const unsigned char lookup_tables<Dummy>::lookup_text_pure_no_ws[256] = 
    {
      // 0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
         0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 0
         1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 1
         1,  1,  1,  1,  1,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 2
         1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  1,  1,  1,  // 3
         1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 4
         1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 5
         1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 6
         1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 7
         1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 8
         1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // 9
         1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // A
         1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // B
         1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // C
         1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // D
         1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  // E
         1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1   // F
    };

其中ch是汉字退。此函数返回false。为什么?对于所有其他字符,它返回true。 你有什么想法吗?

2 个答案:

答案 0 :(得分:1)

看起来Ch包含Unicode值。 static_cast<unsigned char>(0x9000)为0。

您需要一个包含超过256个值的表。

答案 1 :(得分:1)

RapidXML不支持仅使用UTF-8的完整Unicode。

http://rapidxml.sourceforge.net/manual.html#namespacerapidxml_1character_types_and_encodings

请参阅:Rapidxml and UTF8

您拥有的唯一选项是:将汉字转换为UTF-8并希望它有效。转换为非Unicode代码页,并希望它适用于RapidXML。

相关问题