News for hackers. Stuff that matters.
Re:I Can’t Write My Name in Unicode by elFarto on Wednesday March 18, 2015 @05:05AM (#9224317)
Actually, that's not correct, and it's the exact same mistake I made when using that API. codePointAt returns the codepoint at index i, where i is measured in 16-bit chars, which means you could index into the middle of a surrogate pair.

The correct version is:

  for (int i = 0; i < string.length(); i = string.offsetByCodePoints(i, 1))
  {
     int codepoint = string.codePointAt(i);
  }
Java 8 seems to have acquired a codePoints() method on the CharSequence interface which seems to do the same thing.

But this just adds to the fact, proper Unicode string processing is a pain :).

Re:I Can’t Write My Name in Unicode by jdmichal on Wednesday March 18, 2015 @10:15AM (#9225582)
I think you missed the part where `i` is not incremented in the for statement, but inside the loop using `Character.charCount`, which returns the number of `char` necessary to represent the code point. If there's something wrong with this, my unit tests have never brought it up, and I am always sure to test with multi-`char` codepoints.
Re:I Can’t Write My Name in Unicode by elFarto on Wednesday March 18, 2015 @10:59AM (#9225944)
Your right, I did miss it, I apologize. That'll teach me to read code so early in the morning.