Apache Xerces: ConvertUTF16toUCS4的源代码是:
ConversionResult ConvertUTF16toUCS4(
UTF16 **sourceStart, UTF16 *sourceEnd,
UCS4 **targetStart, const UCS4 *targetEnd)
{
ConversionResult result = ok;
register UTF16 *source = *sourceStart;
register UCS4 *target = *targetStart;
while (source < sourceEnd)
{
register UCS4 ch;
ch = *source++;
if (ch >= kSurrogateHighStart && ch <= kSurrogateHighEnd && source < sourceEnd)
{
register UCS4 ch2 = *source;
if (ch2 >= kSurrogateLowStart && ch2 <= kSurrogateLowEnd)
{
ch = ((ch - kSurrogateHighStart) << halfShift) + (ch2 - kSurrogateLowStart) + halfBase;
++source;
};
};
if (target >= targetEnd)
{
result = targetExhausted;
break;
};
*target++ = ch;
};
*sourceStart = source;
*targetStart = target;
return result;
};
我正在尝试将 UTF16 编码的代理对转换为 UCS4 编码的数据。我正在使用 WindowsOS 和一个小端机器。
如果您仔细观察,您会发现,在转换之后,他们将 target 分配给*targetStart
. 那么它不会指向目标的最后一个元素而不是目标的第一个元素吗?当我从代码中删除该语句*targetStart = target;
时,它按预期工作。这是 API 中的错误还是我遗漏了什么?