2 *******************************************************************************
3 * Copyright (C) 2012, International Business Machines Corporation and *
4 * others. All Rights Reserved. *
5 *******************************************************************************
7 package com.ibm.icu.text;
9 import java.text.CharacterIterator;
11 import com.ibm.icu.impl.Assert;
12 import com.ibm.icu.util.BytesTrie;
13 import com.ibm.icu.util.BytesTrie.Result;
15 class BytesDictionaryMatcher extends DictionaryMatcher {
16 private final byte[] characters;
17 private final int transform;
19 public BytesDictionaryMatcher(byte[] chars, int transform) {
21 Assert.assrt((transform & DictionaryData.TRANSFORM_TYPE_MASK) == DictionaryData.TRANSFORM_TYPE_OFFSET);
22 // while there is only one transform type so far, save the entire transform constant so that
23 // if we add any others, we need only change code in transform() and the assert above rather
24 // than adding a "transform type" variable
25 this.transform = transform;
28 private int transform(int c) {
31 } else if (c == 0x200C) {
35 int delta = c - (transform & DictionaryData.TRANSFORM_OFFSET_MASK);
36 if (delta < 0 || 0xFD < delta) {
42 public int matches(CharacterIterator text_, int maxLength, int[] lengths, int[] count_, int limit, int[] values) {
43 UCharacterIterator text = UCharacterIterator.getInstance(text_);
44 BytesTrie bt = new BytesTrie(characters, 0);
45 int c = text.nextCodePoint();
46 Result result = bt.first(transform(c));
47 // TODO: should numChars count Character.charCount() ?
51 if (result.hasValue()) {
54 values[count] = bt.getValue();
56 lengths[count] = numChars;
59 if (result == Result.FINAL_VALUE) {
62 } else if (result == Result.NO_MATCH) {
66 if (numChars >= maxLength) {
70 c = text.nextCodePoint();
72 result = bt.next(transform(c));
78 public int getType() {
79 return DictionaryData.TRIE_TYPE_BYTES;