这段代码真的能实现遍历字符串时的回退么?

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的要求吧?



...全文
132 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
aptom 2010-01-31
  • 打赏
  • 举报
回复
自己顶一下
24K純帥 2010-01-31
  • 打赏
  • 举报
回复
貌似这两句话都没看过,顶下。。
myj870517 2010-01-31
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 aptom 的回复:]
引用 6 楼 snowmansh 的回复:
建立断点,跟踪一下。

大侠,我不会啊。。。。
[/Quote]调试一定要学会,这要找视频看,讲是讲不清的
aptom 2010-01-31
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 snowmansh 的回复:]
建立断点,跟踪一下。
[/Quote]
大侠,我不会啊。。。。
snowmansh 2010-01-31
  • 打赏
  • 举报
回复
建立断点,跟踪一下。
aptom 2010-01-31
  • 打赏
  • 举报
回复
test了,觉得不行
不过人家是大名鼎鼎的core java啊。。。
snowmansh 2010-01-31
  • 打赏
  • 举报
回复
做个test不就可以了嘛!
myj870517 2010-01-31
  • 打赏
  • 举报
回复
他自己写的方法吧?abcd遇到c的时候回到b?这个意思?
aptom 2010-01-31
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 myj870517 的回复:]
看不懂...
[/Quote]
泪奔。。。。

那就简单点吧
下边这段代码可以实现遍历一个字符串时,后退的操作么?
i--;
int cp = sentence.codePointAt(i);
if (Character.isSupplementaryCodePoint(cp)) i--;
myj870517 2010-01-31
  • 打赏
  • 举报
回复
看不懂...

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧