Wouldn't this be nice?
Neal Gafter
neal at gafter.com
Wed Nov 11 10:29:05 PST 2009
I wrote this back in
2004<http://www.denverjug.org/meetings/files/200408_Tiger.pdf>
:
*Iterable<Integer> codePoints(final String s) {
*
*return new Iterable<Integer>() {
*
*public Iterator<Integer> iterator() {
*
*return new Iterator<Integer>() {
*
*int nextIndex = 0;
public boolean hasNext() {
*
*return nextIndex < s.length();
*
*}
public Integer next() {
*
*int result = s.codePointAt(nextIndex);
nextIndex += Character.charCount(result);
return result;
*
*}
public void remove()
*
*{ throw new UnsupportedOperationException(); }
*
*};
*
*}
*
*};
*
*}
*
Doing this for CharSequence is only a bit more complicated.
If this is likely to be used frequently, direct compiler-generated would
certainly be better. Do we have a feel for how often this feature would be
used?
-Neal
On Wed, Nov 11, 2009 at 10:14 AM, Joshua Bloch <jjb at google.com> wrote:
> Eammon,
>
> That's a great idea! In fact, it's a compelling reason to support the
> feature.
>
> Josh
>
> On Wed, Nov 11, 2009 at 10:05 AM, Eamonn McManus <Eamonn.McManus at sun.com
> >wrote:
>
> > What I'm really sorry that I didn't put into the original statement is:
> >
> > for (char c : myString)
> >
> > which would also work on other CharSequences. Oh well, maybe someday
> >
> > That would certainly be awfully nice, especially if it also worked for
> > code points in general, as in
> >
> > for (int c : myString)
> >
> > Getting the right behaviour using the codePointCount and codePointAt and
> > charCount methods of Character is really tedious, but necessary if you
> want
> > your code to be fully international. There are ways to abstract it away a
> > bit in the current language, but they're kind of clunky.
> >
> > Éamonn
> >
> > Joshua Bloch wrote:
> >
> > Paulo,
> >
> > I have a hard time intuiting the semantics by just looking a the
> statement.
> > What I'm really sorry that I didn't put into the original statement is:
> >
> > for (char c : myString)
> >
> > which would also work on other CharSequences. Oh well, maybe someday.
> >
> > Josh
> >
> > On Wed, Nov 11, 2009 at 8:38 AM, Paulo Levi <i30817 at gmail.com> <
> i30817 at gmail.com> wrote:
> >
> >
> >
> > Probably you figured out i wanted:
> > for(int i : infos.length - 1)
> >
> > sigh.
> >
> >
> >
> >
> >
>
>
More information about the coin-dev
mailing list