1 // © 2016 and later: Unicode, Inc. and others. 2 // License & terms of use: http://www.unicode.org/copyright.html#License 3 /* 4 ******************************************************************************* 5 * Copyright (C) 2012-2014, International Business Machines 6 * Corporation and others. All Rights Reserved. 7 ******************************************************************************* 8 * IterCollationIterator.java, ported from uitercollationiterator.h/.cpp 9 * 10 * C++ version created on: 2012sep23 (from utf16collationiterator.h) 11 * created by: Markus W. Scherer 12 */ 13 14 package com.ibm.icu.impl.coll; 15 16 import com.ibm.icu.text.UCharacterIterator; 17 18 /** 19 * UCharIterator-based collation element and character iterator. 20 * Handles normalized text, with length or NUL-terminated. 21 * Unnormalized text is handled by a subclass. 22 */ 23 public class IterCollationIterator extends CollationIterator { IterCollationIterator(CollationData d, boolean numeric, UCharacterIterator ui)24 public IterCollationIterator(CollationData d, boolean numeric, UCharacterIterator ui) { 25 super(d, numeric); 26 iter = ui; 27 } 28 29 @Override resetToOffset(int newOffset)30 public void resetToOffset(int newOffset) { 31 reset(); 32 iter.setIndex(newOffset); 33 } 34 35 @Override getOffset()36 public int getOffset() { 37 return iter.getIndex(); 38 } 39 40 @Override nextCodePoint()41 public int nextCodePoint() { 42 return iter.nextCodePoint(); 43 } 44 45 @Override previousCodePoint()46 public int previousCodePoint() { 47 return iter.previousCodePoint(); 48 } 49 50 @Override handleNextCE32()51 protected long handleNextCE32() { 52 int c = iter.next(); 53 if(c < 0) { 54 return NO_CP_AND_CE32; 55 } 56 return makeCodePointAndCE32Pair(c, trie.getFromU16SingleLead((char)c)); 57 } 58 59 @Override handleGetTrailSurrogate()60 protected char handleGetTrailSurrogate() { 61 int trail = iter.next(); 62 if(!isTrailSurrogate(trail) && trail >= 0) { iter.previous(); } 63 return (char)trail; 64 } 65 66 @Override forwardNumCodePoints(int num)67 protected void forwardNumCodePoints(int num) { 68 iter.moveCodePointIndex(num); 69 } 70 71 @Override backwardNumCodePoints(int num)72 protected void backwardNumCodePoints(int num) { 73 iter.moveCodePointIndex(-num); 74 } 75 76 protected UCharacterIterator iter; 77 } 78