我想将QString转换XMLCh const *
为 Xerces-C++ 使用的。
前者可以const ushort *
在(我认为)O(1) 时间内以主机字节顺序“转换”为 NUL 终止。后者也是一个 UTF-16 字符串,但我不确定是哪个字节顺序。
有没有人解决过这个问题?我不想做很多字符串复制。
也许:
const XMLCh* QtoX(const QString& s) { return (s.utf16()); }
QString XtoQ(const XMLCh* x) { return QString::fromUtf16(x); }
从这里?我对此没有个人经验。
QString->XMLCh* QString::toWCharArray(XMLCh* buffer)
XMLCh->QString QString::fromWCharArray(x)
为 XMLCh 分配内存:
XMLCh* QString2X(QString _w, MemoryManager *mm =
XMLPlatformUtils::fgMemoryManager) {
XMLCh b[256];
_w.toWCharArray(b);
XMLCh* _x = (XMLCh*) mm->allocate((XMLString::stringLen(b)+1)*sizeof(XMLCh));
XMLString::copyString(_x, b);
return _x;
}