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) 2016, International Business Machines Corporation and * 6 * others. All Rights Reserved. * 7 ******************************************************************************* 8 */ 9package com.ibm.icu.text; 10 11import static com.ibm.icu.impl.CharacterIteration.DONE32; 12 13import java.text.CharacterIterator; 14 15import com.ibm.icu.impl.CharacterIteration; 16import com.ibm.icu.lang.UCharacter; 17import com.ibm.icu.lang.UProperty; 18 19final class UnhandledBreakEngine implements LanguageBreakEngine { 20 // TODO: Use two arrays of UnicodeSet, one with all frozen sets, one with unfrozen. 21 // in handleChar(), update the unfrozen version, clone, freeze, replace the frozen one. 22 private final UnicodeSet[] fHandled = new UnicodeSet[BreakIterator.KIND_TITLE + 1]; 23 public UnhandledBreakEngine() { 24 for (int i = 0; i < fHandled.length; i++) { 25 fHandled[i] = new UnicodeSet(); 26 } 27 } 28 29 public boolean handles(int c, int breakType) { 30 return (breakType >= 0 && breakType < fHandled.length) && 31 (fHandled[breakType].contains(c)); 32 } 33 34 public int findBreaks(CharacterIterator text, int startPos, int endPos, 35 boolean reverse, int breakType, DictionaryBreakEngine.DequeI foundBreaks) { 36 if (breakType >= 0 && breakType < fHandled.length) { 37 int c = CharacterIteration.current32(text); 38 if (reverse) { 39 while (text.getIndex() > startPos && fHandled[breakType].contains(c)) { 40 CharacterIteration.previous32(text); 41 c = CharacterIteration.current32(text); 42 } 43 } else { 44 while (text.getIndex() < endPos && fHandled[breakType].contains(c)) { 45 CharacterIteration.next32(text); 46 c = CharacterIteration.current32(text); 47 } 48 } 49 } 50 return 0; 51 } 52 53 public synchronized void handleChar(int c, int breakType) { 54 if (breakType >= 0 && breakType < fHandled.length && c != DONE32) { 55 if (!fHandled[breakType].contains(c)) { 56 int script = UCharacter.getIntPropertyValue(c, UProperty.SCRIPT); 57 fHandled[breakType].applyIntPropertyValue(UProperty.SCRIPT, script); 58 } 59 } 60 } 61} 62