jdk/src/java.base/share/classes/java/lang/StringUTF16.java
changeset 42346 c0c6d5d20c35
parent 39157 bba1e4c5c547
child 44642 331e669007f7
equal deleted inserted replaced
42345:cead5ce4ca27 42346:c0c6d5d20c35
   809             byte[] a; int i, hi; // hoist accesses and checks from loop
   809             byte[] a; int i, hi; // hoist accesses and checks from loop
   810             if (action == null)
   810             if (action == null)
   811                 throw new NullPointerException();
   811                 throw new NullPointerException();
   812             if (((a = array).length >> 1) >= (hi = fence) &&
   812             if (((a = array).length >> 1) >= (hi = fence) &&
   813                 (i = index) >= 0 && i < (index = hi)) {
   813                 (i = index) >= 0 && i < (index = hi)) {
   814                 do { action.accept(getChar(a, i)); } while (++i < hi);
   814                 do {
       
   815                     action.accept(charAt(a, i));
       
   816                 } while (++i < hi);
   815             }
   817             }
   816         }
   818         }
   817 
   819 
   818         @Override
   820         @Override
   819         public boolean tryAdvance(IntConsumer action) {
   821         public boolean tryAdvance(IntConsumer action) {
   820             if (action == null)
   822             if (action == null)
   821                 throw new NullPointerException();
   823                 throw new NullPointerException();
   822             if (index >= 0 && index < fence) {
   824             int i = index;
   823                 action.accept(getChar(array, index++));
   825             if (i >= 0 && i < fence) {
       
   826                 action.accept(charAt(array, i));
       
   827                 index++;
   824                 return true;
   828                 return true;
   825             }
   829             }
   826             return false;
   830             return false;
   827         }
   831         }
   828 
   832 
   858             if (lo >= mid)
   862             if (lo >= mid)
   859                 return null;
   863                 return null;
   860 
   864 
   861             int midOneLess;
   865             int midOneLess;
   862             // If the mid-point intersects a surrogate pair
   866             // If the mid-point intersects a surrogate pair
   863             if (Character.isLowSurrogate(getChar(array, mid)) &&
   867             if (Character.isLowSurrogate(charAt(array, mid)) &&
   864                 Character.isHighSurrogate(getChar(array, midOneLess = (mid -1)))) {
   868                 Character.isHighSurrogate(charAt(array, midOneLess = (mid -1)))) {
   865                 // If there is only one pair it cannot be split
   869                 // If there is only one pair it cannot be split
   866                 if (lo >= midOneLess)
   870                 if (lo >= midOneLess)
   867                     return null;
   871                     return null;
   868                 // Shift the mid-point to align with the surrogate pair
   872                 // Shift the mid-point to align with the surrogate pair
   869                 return new CodePointsSpliterator(array, lo, index = midOneLess, cs);
   873                 return new CodePointsSpliterator(array, lo, index = midOneLess, cs);
   896         }
   900         }
   897 
   901 
   898         // Advance one code point from the index, i, and return the next
   902         // Advance one code point from the index, i, and return the next
   899         // index to advance from
   903         // index to advance from
   900         private static int advance(byte[] a, int i, int hi, IntConsumer action) {
   904         private static int advance(byte[] a, int i, int hi, IntConsumer action) {
   901             char c1 = getChar(a, i++);
   905             char c1 = charAt(a, i++);
   902             int cp = c1;
   906             int cp = c1;
   903             if (Character.isHighSurrogate(c1) && i < hi) {
   907             if (Character.isHighSurrogate(c1) && i < hi) {
   904                 char c2 = getChar(a, i);
   908                 char c2 = charAt(a, i);
   905                 if (Character.isLowSurrogate(c2)) {
   909                 if (Character.isLowSurrogate(c2)) {
   906                     i++;
   910                     i++;
   907                     cp = Character.toCodePoint(c1, c2);
   911                     cp = Character.toCodePoint(c1, c2);
   908                 }
   912                 }
   909             }
   913             }