这段代码真的能实现遍历字符串时的回退么?
aptom 2010-01-31 04:23:53 初学Core Java(java核心技术),看到一下叙述和代码,大意是下边的代码可以实现遍历字符串(按代码点)时的回退操作
======================================
Fortunately, the codePointAt method can tell whether a code unit is the first or second half of a supplementary character, and it returns the right result either way. That is, you can move backwards with the following statements:
i--;
int cp = sentence.codePointAt(i);
if (Character.isSupplementaryCodePoint(cp)) i--;
========================================
我觉得蛮奇怪的啊
按我的理解,codePointAt方法如果碰上一个辅助代码点(supplementary code point)的low-surrogate(应该就是上边写的second half of a supplementary character吧?),会返回这个代码单元的值,而不是代码点的值。
所以上边if后面的条件,如果位置i处是一个low-surrogate,值为false,不会发生i--,这不满足move backwards的要求吧?