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