Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 5063163
Votes 1
Synopsis Please add a method int[] String.toCodePointArray()
Category java:classes_lang
Reported Against tiger-beta2
Release Fixed
State 3-Accepted, request for enhancement
Priority: 4-Low
Related Bugs 5003547
Submit Date 15-JUN-2004
Description


A DESCRIPTION OF THE REQUEST :
With Unicode 4 and supplementary characters, it has become painful to process Strings as char sequences. It would be easier to handle them as int sequences. The low-hanging fruit would be to supply a method

int[] toCodePointArray()

in the String class (and, if you feel generous, a constructor String(int[]) in addition to the existing String(int[], int, int))



JUSTIFICATION :
Consider a typical string processing task--removing characters that match a particular criterion. It is painful to handle the surrogate characters.

In addition, it would be delightful to be able to iterate over the code points with the generalized for loop:

for (int cp : str.toCodePointArray()) { ... }



EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Right now, I use a helper method such as this one:

 private static int[] getCodePointArray(String str)
   {
      int[] codePoints = new int[str.codePointCount(0, str.length())];
      for (int i = 0, j = 0; i < str.length(); i++, j++)
      {
         int cp = str.codePointAt(i);
         if (Character.isSupplementaryCodePoint(cp)) i++;
         codePoints[j] = cp;
      }
      return codePoints;
   }
ACTUAL -
Ugh, don't get me going
(Incident Review ID: 276989) 
======================================================================
Posted Date : 2005-07-26 18:48:05.0
Work Around
N/A
Evaluation
Contribution forum : https://jdk-collaboration.dev.java.net/servlets/ProjectForumMessageView?forumID=1463&messageID=18210
Posted Date : 2007-01-18 20:16:09.0
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang