1/* GENERATED SOURCE. DO NOT MODIFY. */ 2// © 2016 and later: Unicode, Inc. and others. 3// License & terms of use: http://www.unicode.org/copyright.html#License 4/* 5 ******************************************************************************* 6 * Copyright (C) 2014, International Business Machines Corporation and * 7 * others. All Rights Reserved. * 8 ******************************************************************************* 9 */ 10package android.icu.text; 11 12import java.text.CharacterIterator; 13 14import android.icu.util.BytesTrie.Result; 15import android.icu.util.CharsTrie; 16 17class CharsDictionaryMatcher extends DictionaryMatcher { 18 private CharSequence characters; 19 20 public CharsDictionaryMatcher(CharSequence chars) { 21 characters = chars; 22 } 23 24 @Override 25 public int matches(CharacterIterator text_, int maxLength, int[] lengths, int[] count_, int limit, int[] values) { 26 UCharacterIterator text = UCharacterIterator.getInstance(text_); 27 CharsTrie uct = new CharsTrie(characters, 0); 28 int c = text.nextCodePoint(); 29 if (c == UCharacterIterator.DONE) { 30 return 0; 31 } 32 Result result = uct.firstForCodePoint(c); 33 // TODO: should numChars count Character.charCount? 34 int numChars = 1; 35 int count = 0; 36 for (;;) { 37 if (result.hasValue()) { 38 if (count < limit) { 39 if (values != null) { 40 values[count] = uct.getValue(); 41 } 42 lengths[count] = numChars; 43 count++; 44 } 45 46 if (result == Result.FINAL_VALUE) { 47 break; 48 } 49 } else if (result == Result.NO_MATCH) { 50 break; 51 } 52 53 if (numChars >= maxLength) { 54 break; 55 } 56 c = text.nextCodePoint(); 57 if (c == UCharacterIterator.DONE) { 58 break; 59 } 60 ++numChars; 61 result = uct.nextForCodePoint(c); 62 } 63 count_[0] = count; 64 return numChars; 65 } 66 67 @Override 68 public int getType() { 69 return DictionaryData.TRIE_TYPE_UCHARS; 70 } 71} 72 73