12ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller/* GENERATED SOURCE. DO NOT MODIFY. */ 2f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert// © 2016 and later: Unicode, Inc. and others. 3f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert// License & terms of use: http://www.unicode.org/copyright.html#License 42ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller/* 52ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller ******************************************************************************* 6bfab1e7fec36dff93fb980c546ad64a565faf9fcPaul Duffin * Copyright (C) 1996-2016, International Business Machines Corporation and * 72ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * others. All Rights Reserved. * 82ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller ******************************************************************************* 92ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 102ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 112ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerpackage android.icu.text; 122ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 132ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerimport java.text.CharacterIterator; 142ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerimport java.text.StringCharacterIterator; 152ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerimport java.util.Locale; 162ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerimport java.util.MissingResourceException; 172ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 18f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubertimport android.icu.impl.CacheValue; 192ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerimport android.icu.impl.ICUDebug; 202ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerimport android.icu.util.ICUCloneNotSupportedException; 212ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerimport android.icu.util.ULocale; 222ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 232ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller/** 241537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu enhancement]</strong> ICU's replacement for {@link java.text.BreakIterator}. Methods, fields, and other functionality specific to ICU are labeled '<strong>[icu]</strong>'. 252ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 262ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <p>A class that locates boundaries in text. This class defines a protocol for 272ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * objects that break up a piece of natural-language text according to a set 282ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * of criteria. Instances or subclasses of BreakIterator can be provided, for 292ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * example, to break a piece of text into words, sentences, or logical characters 302ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * according to the conventions of some language or group of languages. 312ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 322ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * We provide five built-in types of BreakIterator: 332ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <ul><li>getTitleInstance() returns a BreakIterator that locates boundaries 342ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * between title breaks. 352ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <li>getSentenceInstance() returns a BreakIterator that locates boundaries 362ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * between sentences. This is useful for triple-click selection, for example. 372ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <li>getWordInstance() returns a BreakIterator that locates boundaries between 382ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * words. This is useful for double-click selection or "find whole words" searches. 392ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * This type of BreakIterator makes sure there is a boundary position at the 402ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * beginning and end of each legal word. (Numbers count as words, too.) Whitespace 412ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * and punctuation are kept separate from real words. 422ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <li>getLineInstance() returns a BreakIterator that locates positions where it is 432ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * legal for a text editor to wrap lines. This is similar to word breaking, but 442ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * not the same: punctuation and whitespace are generally kept with words (you don't 452ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * want a line to start with whitespace, for example), and some special characters 462ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * can force a position to be considered a line-break position or prevent a position 472ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * from being a line-break position. 482ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <li>getCharacterInstance() returns a BreakIterator that locates boundaries between 492ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * logical characters. Because of the structure of the Unicode encoding, a logical 502ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * character may be stored internally as more than one Unicode code point. (A with an 512ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * umlaut may be stored as an a followed by a separate combining umlaut character, 522ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * for example, but the user still thinks of it as one character.) This iterator allows 532ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * various processes (especially text editors) to treat as characters the units of text 542ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * that a user would think of as characters, rather than the units of text that the 552ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * computer sees as "characters".</ul> 562ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * The text boundary positions are found according to the rules 572ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * described in Unicode Standard Annex #29, Text Boundaries, and 582ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Unicode Standard Annex #14, Line Breaking Properties. These 592ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * are available at http://www.unicode.org/reports/tr14/ and 602ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * http://www.unicode.org/reports/tr29/. 612ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <p> 622ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * BreakIterator's interface follows an "iterator" model (hence the name), meaning it 632ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * has a concept of a "current position" and methods like first(), last(), next(), 642ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * and previous() that update the current position. All BreakIterators uphold the 652ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * following invariants: 662ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <ul><li>The beginning and end of the text are always treated as boundary positions. 672ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <li>The current position of the iterator is always a boundary position (random- 682ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * access methods move the iterator to the nearest boundary position before or 692ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * after the specified position, not _to_ the specified position). 702ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <li>DONE is used as a flag to indicate when iteration has stopped. DONE is only 712ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * returned when the current position is the end of the text and the user calls next(), 722ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * or when the current position is the beginning of the text and the user calls 732ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * previous(). 742ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <li>Break positions are numbered by the positions of the characters that follow 752ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * them. Thus, under normal circumstances, the position before the first character 762ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * is 0, the position after the first character is 1, and the position after the 772ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * last character is 1 plus the length of the string. 782ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <li>The client can change the position of an iterator, or the text it analyzes, 792ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * at will, but cannot change the behavior. If the user wants different behavior, he 802ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * must instantiate a new iterator.</ul> 812ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 822ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * BreakIterator accesses the text it analyzes through a CharacterIterator, which makes 832ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * it possible to use BreakIterator to analyze text in any text-storage vehicle that 842ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * provides a CharacterIterator interface. 852ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 862ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <b>Note:</b> Some types of BreakIterator can take a long time to create, and 872ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * instances of BreakIterator are not currently cached by the system. For 882ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * optimal performance, keep instances of BreakIterator around as long as makes 892ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * sense. For example, when word-wrapping a document, don't create and destroy a 902ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * new BreakIterator for each line. Create one break iterator for the whole document 912ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * (or whatever stretch of text you're wrapping) and use it to do the whole job of 922ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * wrapping the text. 932ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 942ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <P> 952ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <strong>Examples</strong>:<P> 962ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Creating and using text boundaries 972ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <blockquote> 982ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <pre> 992ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * public static void main(String args[]) { 1002ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * if (args.length == 1) { 1012ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * String stringToExamine = args[0]; 1022ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * //print each word in order 1032ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * BreakIterator boundary = BreakIterator.getWordInstance(); 1042ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * boundary.setText(stringToExamine); 1052ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * printEachForward(boundary, stringToExamine); 1062ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * //print each sentence in reverse order 1072ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * boundary = BreakIterator.getSentenceInstance(Locale.US); 1082ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * boundary.setText(stringToExamine); 1092ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * printEachBackward(boundary, stringToExamine); 1102ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * printFirst(boundary, stringToExamine); 1112ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * printLast(boundary, stringToExamine); 1122ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * } 1132ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * } 1142ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * </pre> 1152ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * </blockquote> 1162ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 1172ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Print each element in order 1182ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <blockquote> 1192ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <pre> 1202ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * public static void printEachForward(BreakIterator boundary, String source) { 1212ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * int start = boundary.first(); 1222ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * for (int end = boundary.next(); 1232ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * end != BreakIterator.DONE; 1242ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * start = end, end = boundary.next()) { 1252ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * System.out.println(source.substring(start,end)); 1262ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * } 1272ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * } 1282ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * </pre> 1292ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * </blockquote> 1302ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 1312ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Print each element in reverse order 1322ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <blockquote> 1332ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <pre> 1342ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * public static void printEachBackward(BreakIterator boundary, String source) { 1352ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * int end = boundary.last(); 1362ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * for (int start = boundary.previous(); 1372ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * start != BreakIterator.DONE; 1382ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * end = start, start = boundary.previous()) { 1392ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * System.out.println(source.substring(start,end)); 1402ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * } 1412ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * } 1422ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * </pre> 1432ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * </blockquote> 1442ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 1452ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Print first element 1462ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <blockquote> 1472ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <pre> 1482ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * public static void printFirst(BreakIterator boundary, String source) { 1492ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * int start = boundary.first(); 1502ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * int end = boundary.next(); 1512ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * System.out.println(source.substring(start,end)); 1522ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * } 1532ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * </pre> 1542ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * </blockquote> 1552ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 1562ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Print last element 1572ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <blockquote> 1582ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <pre> 1592ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * public static void printLast(BreakIterator boundary, String source) { 1602ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * int end = boundary.last(); 1612ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * int start = boundary.previous(); 1622ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * System.out.println(source.substring(start,end)); 1632ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * } 1642ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * </pre> 1652ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * </blockquote> 1662ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 1672ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Print the element at a specified position 1682ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <blockquote> 1692ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <pre> 1702ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * public static void printAt(BreakIterator boundary, int pos, String source) { 1712ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * int end = boundary.following(pos); 1722ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * int start = boundary.previous(); 1732ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * System.out.println(source.substring(start,end)); 1742ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * } 1752ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * </pre> 1762ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * </blockquote> 1772ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 1782ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Find the next word 1792ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <blockquote> 1802ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <pre> 1812ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * public static int nextWordStartAfter(int pos, String text) { 1822ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * BreakIterator wb = BreakIterator.getWordInstance(); 1832ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * wb.setText(text); 1842ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * int last = wb.following(pos); 1852ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * int current = wb.next(); 1862ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * while (current != BreakIterator.DONE) { 187bfab1e7fec36dff93fb980c546ad64a565faf9fcPaul Duffin * for (int p = last; p < current; p++) { 1882ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * if (Character.isLetter(text.charAt(p))) 1892ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * return last; 1902ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * } 1912ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * last = current; 1922ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * current = wb.next(); 1932ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * } 1942ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * return BreakIterator.DONE; 1952ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * } 1962ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * </pre> 1972ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * (The iterator returned by BreakIterator.getWordInstance() is unique in that 1982ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * the break positions it returns don't represent both the start and end of the 1992ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * thing being iterated over. That is, a sentence-break iterator returns breaks 2002ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * that each represent the end of one sentence and the beginning of the next. 2012ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * With the word-break iterator, the characters between two boundaries might be a 2022ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * word, or they might be the punctuation or whitespace between two words. The 2032ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * above code uses a simple heuristic to determine which boundary is the beginning 2042ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * of a word: If the characters between this boundary and the next boundary 2052ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * include at least one letter (this can be an alphabetical letter, a CJK ideograph, 2062ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * a Hangul syllable, a Kana character, etc.), then the text between this boundary 2072ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * and the next is a word; otherwise, it's the material between words.) 2082ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * </blockquote> 2092ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 2102ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see CharacterIterator 2111537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * 2122ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 2132ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 2142ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerpublic abstract class BreakIterator implements Cloneable 2152ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller{ 2162ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 2172ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller private static final boolean DEBUG = ICUDebug.enabled("breakiterator"); 2182ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 2192ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 2202ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Default constructor. There is no state that is carried by this abstract 2212ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * base class. 2222ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 2232ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller protected BreakIterator() 2242ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller { 2252ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 2262ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 2272ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 2282ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Clone method. Creates another BreakIterator with the same behavior and 2292ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * current state as this one. 2302ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return The clone. 2312ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 232f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert @Override 2332ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public Object clone() 2342ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller { 2352ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller try { 2362ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return super.clone(); 2372ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 2382ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller catch (CloneNotSupportedException e) { 2392ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller ///CLOVER:OFF 2402ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller throw new ICUCloneNotSupportedException(e); 2412ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller ///CLOVER:ON 2422ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 2432ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 2442ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 2452ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 2462ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * DONE is returned by previous() and next() after all valid 2472ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * boundaries have been returned. 2482ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 2492ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static final int DONE = -1; 2502ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 2512ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 2522ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Set the iterator to the first boundary position. This is always the beginning 2532ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * index of the text this iterator iterates over. For example, if 2542ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * the iterator iterates over a whole string, this function will 2552ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * always return 0. 2562ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return The character offset of the beginning of the stretch of text 2572ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * being broken. 2582ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 2592ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public abstract int first(); 2602ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 2612ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 2622ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Set the iterator to the last boundary position. This is always the "past-the-end" 2632ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * index of the text this iterator iterates over. For example, if the 2642ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * iterator iterates over a whole string (call it "text"), this function 2652ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * will always return text.length(). 2662ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return The character offset of the end of the stretch of text 2672ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * being broken. 2682ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 2692ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public abstract int last(); 2702ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 2712ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 2722ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Move the iterator by the specified number of steps in the text. 2732ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * A positive number moves the iterator forward; a negative number 2742ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * moves the iterator backwards. If this causes the iterator 2752ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * to move off either end of the text, this function returns DONE; 2762ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * otherwise, this function returns the position of the appropriate 2772ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * boundary. Calling this function is equivalent to calling next() or 2782ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * previous() n times. 2792ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param n The number of boundaries to advance over (if positive, moves 2802ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * forward; if negative, moves backwards). 2812ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return The position of the boundary n boundaries from the current 2822ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * iteration position, or DONE if moving n boundaries causes the iterator 2832ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * to advance off either end of the text. 2842ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 2852ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public abstract int next(int n); 2862ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 2872ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 2882ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Advances the iterator forward one boundary. The current iteration 2892ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * position is updated to point to the next boundary position after the 2902ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * current position, and this is also the value that is returned. If 2912ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * the current position is equal to the value returned by last(), or to 2922ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * DONE, this function returns DONE and sets the current position to 2932ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * DONE. 2942ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return The position of the first boundary position following the 2952ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * iteration position. 2962ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 2972ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public abstract int next(); 2982ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 2992ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 3002ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Move the iterator backward one boundary. The current iteration 3012ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * position is updated to point to the last boundary position before 3022ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * the current position, and this is also the value that is returned. If 3032ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * the current position is equal to the value returned by first(), or to 3042ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * DONE, this function returns DONE and sets the current position to 3052ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * DONE. 3062ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return The position of the last boundary position preceding the 3072ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * iteration position. 3082ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 3092ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public abstract int previous(); 3102ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 3112ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 3122ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Sets the iterator's current iteration position to be the first 3132ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * boundary position following the specified position. (Whether the 3142ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * specified position is itself a boundary position or not doesn't 3152ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * matter-- this function always moves the iteration position to the 3162ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * first boundary after the specified position.) If the specified 3172ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * position is the past-the-end position, returns DONE. 3182ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param offset The character position to start searching from. 3192ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return The position of the first boundary position following 3202ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * "offset" (whether or not "offset" itself is a boundary position), 3212ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * or DONE if "offset" is the past-the-end offset. 3222ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 3232ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public abstract int following(int offset); 3242ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 3252ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 3262ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Sets the iterator's current iteration position to be the last 3272ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * boundary position preceding the specified position. (Whether the 3282ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * specified position is itself a boundary position or not doesn't 3292ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * matter-- this function always moves the iteration position to the 3302ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * last boundary before the specified position.) If the specified 3312ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * position is the starting position, returns DONE. 3322ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param offset The character position to start searching from. 3332ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return The position of the last boundary position preceding 3342ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * "offset" (whether of not "offset" itself is a boundary position), 3352ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * or DONE if "offset" is the starting offset of the iterator. 3362ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 3372ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public int preceding(int offset) { 3382ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // NOTE: This implementation is here solely because we can't add new 3392ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // abstract methods to an existing class. There is almost ALWAYS a 3402ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // better, faster way to do this. 3412ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller int pos = following(offset); 3422ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller while (pos >= offset && pos != DONE) 3432ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller pos = previous(); 3442ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return pos; 3452ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 3462ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 3472ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 3482ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Return true if the specified position is a boundary position. If the 3492ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * function returns true, the current iteration position is set to the 3502ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * specified position; if the function returns false, the current 3512ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * iteration position is set as though following() had been called. 3522ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param offset the offset to check. 3532ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return True if "offset" is a boundary position. 3542ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 3552ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public boolean isBoundary(int offset) { 3562ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // Again, this is the default implementation, which is provided solely because 3572ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // we couldn't add a new abstract method to an existing class. The real 3582ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // implementations will usually need to do a little more work. 3592ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (offset == 0) { 3602ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return true; 3612ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 3622ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller else 3632ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return following(offset - 1) == offset; 3642ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 3652ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 3662ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 3672ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Return the iterator's current position. 3682ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return The iterator's current position. 3692ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 3702ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public abstract int current(); 3712ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 372f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert 373f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert /** 374f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert * Tag value for "words" that do not fit into any of other categories. 375f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert * Includes spaces and most punctuation. 3762ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 3772ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static final int WORD_NONE = 0; 3782ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 3792ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 380f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert * Upper bound for tags for uncategorized words. 3812ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 3822ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static final int WORD_NONE_LIMIT = 100; 3832ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 3842ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 385f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert * Tag value for words that appear to be numbers, lower limit. 3862ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 3872ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static final int WORD_NUMBER = 100; 3882ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 389f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert /** 3902ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Tag value for words that appear to be numbers, upper limit. 3912ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 3922ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static final int WORD_NUMBER_LIMIT = 200; 3932ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 394f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert /** 3952ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Tag value for words that contain letters, excluding 396f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert * hiragana, katakana or ideographic characters, lower limit. 3972ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 3982ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static final int WORD_LETTER = 200; 3992ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 400f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert /** 401f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert * Tag value for words containing letters, upper limit 4022ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 4032ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static final int WORD_LETTER_LIMIT = 300; 4042ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 405f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert /** 4062ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Tag value for words containing kana characters, lower limit 4072ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 4082ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static final int WORD_KANA = 300; 4092ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 410f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert /** 4112ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Tag value for words containing kana characters, upper limit 4122ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 4132ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static final int WORD_KANA_LIMIT = 400; 4142ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 4152ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 4162ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Tag value for words containing ideographic characters, lower limit 4172ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 4182ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static final int WORD_IDEO = 400; 4192ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 4202ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 4212ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Tag value for words containing ideographic characters, upper limit 4222ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 4232ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static final int WORD_IDEO_LIMIT = 500; 4242ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 4252ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 4262ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * For RuleBasedBreakIterators, return the status tag from the 4272ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * break rule that determined the most recently 4282ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * returned break position. 4292ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <p> 4302ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * For break iterator types that do not support a rule status, 4312ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * a default value of 0 is returned. 4322ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <p> 4332ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return The status from the break rule that determined the most recently 4342ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * returned break position. 4352ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 4362ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 4372ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public int getRuleStatus() { 4382ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return 0; 4392ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 4402ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 4412ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 4422ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * For RuleBasedBreakIterators, get the status (tag) values from the break rule(s) 4432ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * that determined the most recently returned break position. 4442ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <p> 4452ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * For break iterator types that do not support rule status, 4462ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * no values are returned. 4472ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <p> 4482ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * If the size of the output array is insufficient to hold the data, 4492ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * the output will be truncated to the available length. No exception 4502ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * will be thrown. 4512ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 4522ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param fillInArray an array to be filled in with the status values. 4532ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return The number of rule status values from rules that determined 4542ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * the most recent boundary returned by the break iterator. 4552ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * In the event that the array is too small, the return value 4562ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * is the total number of status values that were available, 4572ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * not the reduced number that were actually returned. 4582ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 4592ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public int getRuleStatusVec(int[] fillInArray) { 4602ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (fillInArray != null && fillInArray.length > 0) { 4612ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller fillInArray[0] = 0; 4622ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 4632ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return 1; 4642ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 4652ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 4662ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 4672ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Returns a CharacterIterator over the text being analyzed. 4682ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * For at least some subclasses of BreakIterator, this is a reference 4692ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * to the <b>actual iterator being used</b> by the BreakIterator, 4702ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * and therefore, this function's return value should be treated as 4712ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <tt>const</tt>. No guarantees are made about the current position 4722ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * of this iterator when it is returned. If you need to move that 4732ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * position to examine the text, clone this function's return value first. 4742ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return A CharacterIterator over the text being analyzed. 4752ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 4762ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public abstract CharacterIterator getText(); 4772ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 4782ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 4792ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Sets the iterator to analyze a new piece of text. The new 4802ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * piece of text is passed in as a String, and the current 4812ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * iteration position is reset to the beginning of the string. 4822ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * (The old text is dropped.) 4832ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param newText A String containing the text to analyze with 4842ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * this BreakIterator. 4852ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 4862ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public void setText(String newText) 4872ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller { 4882ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller setText(new StringCharacterIterator(newText)); 4892ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 4902ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 4912ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 4922ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Sets the iterator to analyze a new piece of text. The 4932ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * BreakIterator is passed a CharacterIterator through which 4942ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * it will access the text itself. The current iteration 4952ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * position is reset to the CharacterIterator's start index. 4962ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * (The old iterator is dropped.) 4972ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param newText A CharacterIterator referring to the text 4982ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * to analyze with this BreakIterator (the iterator's current 4992ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * position is ignored, but its other state is significant). 5002ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 5012ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public abstract void setText(CharacterIterator newText); 5022ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 5032ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 5041537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu]</strong> 5052ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 5062ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static final int KIND_CHARACTER = 0; 5072ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 5081537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu]</strong> 5092ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 5102ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static final int KIND_WORD = 1; 5112ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 5121537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu]</strong> 5132ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 5142ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static final int KIND_LINE = 2; 5152ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 5161537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu]</strong> 5172ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 5182ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static final int KIND_SENTENCE = 3; 5192ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 5201537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu]</strong> 5212ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 5222ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static final int KIND_TITLE = 4; 5232ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 5242ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 5252ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 5262ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller private static final int KIND_COUNT = 5; 5272ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 528f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert private static final CacheValue<?>[] iterCache = new CacheValue<?>[5]; 5292ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 5302ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 5312ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Returns a new instance of BreakIterator that locates word boundaries. 5322ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * This function assumes that the text being analyzed is in the default 5332ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * locale's language. 5342ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return An instance of BreakIterator that locates word boundaries. 5352ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 5362ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static BreakIterator getWordInstance() 5372ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller { 5382ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return getWordInstance(ULocale.getDefault()); 5392ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 5402ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 5412ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 5422ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Returns a new instance of BreakIterator that locates word boundaries. 5432ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param where A locale specifying the language of the text to be 5442ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * analyzed. 5452ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return An instance of BreakIterator that locates word boundaries. 5462ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @throws NullPointerException if <code>where</code> is null. 5472ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 5482ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static BreakIterator getWordInstance(Locale where) 5492ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller { 5502ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return getBreakInstance(ULocale.forLocale(where), KIND_WORD); 5512ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 5522ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 5532ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 5541537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu]</strong> Returns a new instance of BreakIterator that locates word boundaries. 5552ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param where A locale specifying the language of the text to be 5562ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * analyzed. 5572ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return An instance of BreakIterator that locates word boundaries. 5582ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @throws NullPointerException if <code>where</code> is null. 5592ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 5602ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static BreakIterator getWordInstance(ULocale where) 5612ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller { 5622ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return getBreakInstance(where, KIND_WORD); 5632ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 5642ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 5652ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 5662ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Returns a new instance of BreakIterator that locates legal line- 5672ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * wrapping positions. This function assumes the text being broken 5682ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * is in the default locale's language. 5692ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return A new instance of BreakIterator that locates legal 5702ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * line-wrapping positions. 5712ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 5722ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static BreakIterator getLineInstance() 5732ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller { 5742ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return getLineInstance(ULocale.getDefault()); 5752ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 5762ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 5772ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 5782ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Returns a new instance of BreakIterator that locates legal line- 5792ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * wrapping positions. 5802ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param where A Locale specifying the language of the text being broken. 5812ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return A new instance of BreakIterator that locates legal 5822ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * line-wrapping positions. 5832ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @throws NullPointerException if <code>where</code> is null. 5842ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 5852ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static BreakIterator getLineInstance(Locale where) 5862ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller { 5872ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return getBreakInstance(ULocale.forLocale(where), KIND_LINE); 5882ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 5892ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 5902ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 5911537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu]</strong> Returns a new instance of BreakIterator that locates legal line- 5922ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * wrapping positions. 5932ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param where A Locale specifying the language of the text being broken. 5942ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return A new instance of BreakIterator that locates legal 5952ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * line-wrapping positions. 5962ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @throws NullPointerException if <code>where</code> is null. 5972ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 5982ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static BreakIterator getLineInstance(ULocale where) 5992ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller { 6002ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return getBreakInstance(where, KIND_LINE); 6012ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 6022ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 6032ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 6042ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Returns a new instance of BreakIterator that locates logical-character 6052ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * boundaries. This function assumes that the text being analyzed is 6062ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * in the default locale's language. 6072ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return A new instance of BreakIterator that locates logical-character 6082ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * boundaries. 6092ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 6102ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static BreakIterator getCharacterInstance() 6112ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller { 6122ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return getCharacterInstance(ULocale.getDefault()); 6132ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 6142ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 6152ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 6162ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Returns a new instance of BreakIterator that locates logical-character 6172ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * boundaries. 6182ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param where A Locale specifying the language of the text being analyzed. 6192ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return A new instance of BreakIterator that locates logical-character 6202ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * boundaries. 6212ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @throws NullPointerException if <code>where</code> is null. 6222ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 6232ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static BreakIterator getCharacterInstance(Locale where) 6242ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller { 6252ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return getBreakInstance(ULocale.forLocale(where), KIND_CHARACTER); 6262ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 6272ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 6282ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 6291537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu]</strong> Returns a new instance of BreakIterator that locates logical-character 6302ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * boundaries. 6312ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param where A Locale specifying the language of the text being analyzed. 6322ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return A new instance of BreakIterator that locates logical-character 6332ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * boundaries. 6342ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @throws NullPointerException if <code>where</code> is null. 6352ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 6362ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static BreakIterator getCharacterInstance(ULocale where) 6372ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller { 6382ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return getBreakInstance(where, KIND_CHARACTER); 6392ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 6402ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 6412ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 6422ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Returns a new instance of BreakIterator that locates sentence boundaries. 6432ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * This function assumes the text being analyzed is in the default locale's 6442ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * language. 6452ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return A new instance of BreakIterator that locates sentence boundaries. 6462ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 6472ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static BreakIterator getSentenceInstance() 6482ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller { 6492ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return getSentenceInstance(ULocale.getDefault()); 6502ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 6512ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 6522ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 6532ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Returns a new instance of BreakIterator that locates sentence boundaries. 6542ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param where A Locale specifying the language of the text being analyzed. 6552ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return A new instance of BreakIterator that locates sentence boundaries. 6562ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @throws NullPointerException if <code>where</code> is null. 6572ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 6582ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static BreakIterator getSentenceInstance(Locale where) 6592ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller { 6602ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return getBreakInstance(ULocale.forLocale(where), KIND_SENTENCE); 6612ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 6622ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 6632ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 6641537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu]</strong> Returns a new instance of BreakIterator that locates sentence boundaries. 6652ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param where A Locale specifying the language of the text being analyzed. 6662ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return A new instance of BreakIterator that locates sentence boundaries. 6672ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @throws NullPointerException if <code>where</code> is null. 6682ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 6692ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static BreakIterator getSentenceInstance(ULocale where) 6702ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller { 6712ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return getBreakInstance(where, KIND_SENTENCE); 6722ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 6732ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 6742ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 6751537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu]</strong> Returns a new instance of BreakIterator that locates title boundaries. 6762ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * This function assumes the text being analyzed is in the default locale's 6772ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * language. The iterator returned locates title boundaries as described for 6782ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Unicode 3.2 only. For Unicode 4.0 and above title boundary iteration, 6792ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * please use a word boundary iterator. {@link #getWordInstance} 6802ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return A new instance of BreakIterator that locates title boundaries. 6812ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 6822ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static BreakIterator getTitleInstance() 6832ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller { 6842ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return getTitleInstance(ULocale.getDefault()); 6852ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 6862ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 6872ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 6881537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu]</strong> Returns a new instance of BreakIterator that locates title boundaries. 6892ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * The iterator returned locates title boundaries as described for 6902ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Unicode 3.2 only. For Unicode 4.0 and above title boundary iteration, 6912ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * please use Word Boundary iterator.{@link #getWordInstance} 6922ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param where A Locale specifying the language of the text being analyzed. 6932ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return A new instance of BreakIterator that locates title boundaries. 6942ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @throws NullPointerException if <code>where</code> is null. 6952ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 6962ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static BreakIterator getTitleInstance(Locale where) 6972ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller { 6982ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return getBreakInstance(ULocale.forLocale(where), KIND_TITLE); 6992ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 7002ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 7012ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 7021537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu]</strong> Returns a new instance of BreakIterator that locates title boundaries. 7032ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * The iterator returned locates title boundaries as described for 7042ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Unicode 3.2 only. For Unicode 4.0 and above title boundary iteration, 7052ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * please use Word Boundary iterator.{@link #getWordInstance} 7062ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param where A Locale specifying the language of the text being analyzed. 7072ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return A new instance of BreakIterator that locates title boundaries. 7081fba789ac68efdd9120a7373f49daef42833e674Neil Fuller * @throws NullPointerException if <code>where</code> is null.*/ 7092ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static BreakIterator getTitleInstance(ULocale where) 7102ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller { 7112ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return getBreakInstance(where, KIND_TITLE); 7122ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 7132ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 7142ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 7151537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu]</strong> Registers a new break iterator of the indicated kind, to use in the given 7162ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * locale. Clones of the iterator will be returned if a request for a break iterator 7172ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * of the given kind matches or falls back to this locale. 718f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert * 7192ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <p>Because ICU may choose to cache BreakIterator objects internally, this must 7202ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * be called at application startup, prior to any calls to 7212ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * BreakIterator.getInstance to avoid undefined behavior. 722f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert * 7232ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param iter the BreakIterator instance to adopt. 7242ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param locale the Locale for which this instance is to be registered 7252ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param kind the type of iterator for which this instance is to be registered 7262ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return a registry key that can be used to unregister this instance 727ee0f20f8e03a1df95ced34550ed1b0ee06238ecaNeil Fuller * @hide unsupported on Android 7282ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 7292ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static Object registerInstance(BreakIterator iter, Locale locale, int kind) { 7302ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return registerInstance(iter, ULocale.forLocale(locale), kind); 7312ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 7322ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 7332ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 7341537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu]</strong> Registers a new break iterator of the indicated kind, to use in the given 7352ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * locale. Clones of the iterator will be returned if a request for a break iterator 7362ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * of the given kind matches or falls back to this locale. 737f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert * 7382ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <p>Because ICU may choose to cache BreakIterator objects internally, this must 7392ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * be called at application startup, prior to any calls to 7402ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * BreakIterator.getInstance to avoid undefined behavior. 741f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert * 7422ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param iter the BreakIterator instance to adopt. 7432ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param locale the Locale for which this instance is to be registered 7442ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param kind the type of iterator for which this instance is to be registered 7452ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return a registry key that can be used to unregister this instance 746ee0f20f8e03a1df95ced34550ed1b0ee06238ecaNeil Fuller * @hide unsupported on Android 7472ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 7482ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static Object registerInstance(BreakIterator iter, ULocale locale, int kind) { 7492ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // If the registered object matches the one in the cache, then 7502ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // flush the cached object. 7512ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (iterCache[kind] != null) { 7522ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller BreakIteratorCache cache = (BreakIteratorCache) iterCache[kind].get(); 7532ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (cache != null) { 7542ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (cache.getLocale().equals(locale)) { 7552ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller iterCache[kind] = null; 7562ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 7572ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 7582ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 7592ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return getShim().registerInstance(iter, locale, kind); 7602ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 7612ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 7622ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 7631537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu]</strong> Unregisters a previously-registered BreakIterator using the key returned 7642ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * from the register call. Key becomes invalid after this call and should not be used 7652ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * again. 7662ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param key the registry key returned by a previous call to registerInstance 7672ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return true if the iterator for the key was successfully unregistered 768ee0f20f8e03a1df95ced34550ed1b0ee06238ecaNeil Fuller * @hide unsupported on Android 7692ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 7702ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static boolean unregister(Object key) { 7712ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (key == null) { 7722ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller throw new IllegalArgumentException("registry key must not be null"); 7732ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 7742ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // TODO: we don't do code coverage for the following lines 7752ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // because in getBreakInstance we always instantiate the shim, 7762ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // and test execution is such that we always instantiate a 7772ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // breakiterator before we get to the break iterator tests. 7782ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // this is for modularization, and we could remove the 7792ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // dependencies in getBreakInstance by rewriting part of the 7802ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // LocaleData code, or perhaps by accepting it into the 7812ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // module. 7822ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller ///CLOVER:OFF 7832ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (shim != null) { 7842ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // Unfortunately, we don't know what is being unregistered 7852ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // -- what `kind' and what locale -- so we flush all 7862ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // caches. This is safe but inefficient if people are 7872ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // actively registering and unregistering. 7882ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller for (int kind=0; kind<KIND_COUNT; ++kind) { 7892ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller iterCache[kind] = null; 7902ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 7912ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return shim.unregister(key); 7922ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 7932ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return false; 7942ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller ///CLOVER:ON 7952ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 7962ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 7972ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // end of registration 7982ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 7992ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 8002ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Returns a particular kind of BreakIterator for a locale. 8012ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Avoids writing a switch statement with getXYZInstance(where) calls. 8022ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @deprecated This API is ICU internal only. 80393cf604e9dd0525f15bc0a7450b2a35f3884c298Neil Fuller * @hide original deprecated declaration 804836e6b40a94ec3fb7545a76cb072960442b7eee9Neil Fuller * @hide draft / provisional / internal are hidden on Android 8052ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 8062ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller @Deprecated 8072ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static BreakIterator getBreakInstance(ULocale where, int kind) { 8082ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (where == null) { 8092ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller throw new NullPointerException("Specified locale is null"); 8102ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 8112ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (iterCache[kind] != null) { 8122ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller BreakIteratorCache cache = (BreakIteratorCache)iterCache[kind].get(); 8132ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (cache != null) { 8142ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (cache.getLocale().equals(where)) { 8152ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return cache.createBreakInstance(); 8162ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 8172ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 8182ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 8192ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 8202ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // sigh, all to avoid linking in ICULocaleData... 8212ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller BreakIterator result = getShim().createBreakIterator(where, kind); 8222ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 8232ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller BreakIteratorCache cache = new BreakIteratorCache(where, result); 824f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert iterCache[kind] = CacheValue.getInstance(cache); 8252ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (result instanceof RuleBasedBreakIterator) { 8262ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller RuleBasedBreakIterator rbbi = (RuleBasedBreakIterator)result; 8272ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller rbbi.setBreakType(kind); 8282ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 8292ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 8302ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return result; 8312ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 8322ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 8332ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 8342ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 8352ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Returns a list of locales for which BreakIterators can be used. 8362ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return An array of Locales. All of the locales in the array can 8372ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * be used when creating a BreakIterator. 8382ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 8392ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static synchronized Locale[] getAvailableLocales() 8402ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller { 8412ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // to avoid linking ICULocaleData 8422ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return getShim().getAvailableLocales(); 8432ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 8442ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 8452ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 8461537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu]</strong> Returns a list of locales for which BreakIterators can be used. 8472ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return An array of Locales. All of the locales in the array can 8482ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * be used when creating a BreakIterator. 849836e6b40a94ec3fb7545a76cb072960442b7eee9Neil Fuller * @hide draft / provisional / internal are hidden on Android 8502ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 8512ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public static synchronized ULocale[] getAvailableULocales() 8522ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller { 8532ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // to avoid linking ICULocaleData 8542ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return getShim().getAvailableULocales(); 8552ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 8562ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 8572ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller private static final class BreakIteratorCache { 8582ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 8592ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller private BreakIterator iter; 8602ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller private ULocale where; 8612ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 8622ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller BreakIteratorCache(ULocale where, BreakIterator iter) { 8632ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller this.where = where; 8642ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller this.iter = (BreakIterator) iter.clone(); 8652ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 8662ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 8672ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller ULocale getLocale() { 8682ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return where; 8692ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 8702ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 8712ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller BreakIterator createBreakInstance() { 8722ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return (BreakIterator) iter.clone(); 8732ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 8742ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 8752ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 8762ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller static abstract class BreakIteratorServiceShim { 8772ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public abstract Object registerInstance(BreakIterator iter, ULocale l, int k); 8782ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public abstract boolean unregister(Object key); 8792ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public abstract Locale[] getAvailableLocales(); 8802ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public abstract ULocale[] getAvailableULocales(); 8812ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public abstract BreakIterator createBreakIterator(ULocale l, int k); 8822ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 8832ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 8842ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller private static BreakIteratorServiceShim shim; 8852ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller private static BreakIteratorServiceShim getShim() { 8862ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // Note: this instantiation is safe on loose-memory-model configurations 8872ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // despite lack of synchronization, since the shim instance has no state-- 8882ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // it's all in the class init. The worst problem is we might instantiate 8892ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // two shim instances, but they'll share the same state so that's ok. 8902ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (shim == null) { 8912ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller try { 8922ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller Class<?> cls = Class.forName("android.icu.text.BreakIteratorFactory"); 8932ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller shim = (BreakIteratorServiceShim)cls.newInstance(); 8942ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 8952ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller catch (MissingResourceException e) 8962ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller { 8972ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller throw e; 8982ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 8992ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller catch (Exception e) { 9002ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller ///CLOVER:OFF 9012ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if(DEBUG){ 9022ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller e.printStackTrace(); 9032ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 9042ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller throw new RuntimeException(e.getMessage()); 9052ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller ///CLOVER:ON 9062ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 9072ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 9082ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return shim; 9092ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 9102ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 9112ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // -------- BEGIN ULocale boilerplate -------- 9122ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 9132ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 9141537b2f39245c07b00aa78c3600f7aebcb172490Neil Fuller * <strong>[icu]</strong> Returns the locale that was used to create this object, or null. 9152ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * This may may differ from the locale requested at the time of 9162ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * this object's creation. For example, if an object is created 9172ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * for locale <tt>en_US_CALIFORNIA</tt>, the actual data may be 9182ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * drawn from <tt>en</tt> (the <i>actual</i> locale), and 9192ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <tt>en_US</tt> may be the most specific locale that exists (the 9202ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <i>valid</i> locale). 9212ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 9222ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <p>Note: The <i>actual</i> locale is returned correctly, but the <i>valid</i> 9232ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * locale is not, in most cases. 9242ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param type type of information requested, either {@link 9252ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * android.icu.util.ULocale#VALID_LOCALE} or {@link 9262ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * android.icu.util.ULocale#ACTUAL_LOCALE}. 9272ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return the information specified by <i>type</i>, or null if 9282ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * this object was not constructed from locale data. 9292ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see android.icu.util.ULocale 9302ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see android.icu.util.ULocale#VALID_LOCALE 9312ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see android.icu.util.ULocale#ACTUAL_LOCALE 932836e6b40a94ec3fb7545a76cb072960442b7eee9Neil Fuller * @hide draft / provisional / internal are hidden on Android 9332ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 9342ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public final ULocale getLocale(ULocale.Type type) { 9352ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return type == ULocale.ACTUAL_LOCALE ? 9362ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller this.actualLocale : this.validLocale; 9372ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 9382ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 9392ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 9402ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Set information about the locales that were used to create this 9412ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * object. If the object was not constructed from locale data, 9422ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * both arguments should be set to null. Otherwise, neither 9432ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * should be null. The actual locale must be at the same level or 9442ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * less specific than the valid locale. This method is intended 9452ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * for use by factories or other entities that create objects of 9462ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * this class. 9472ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param valid the most specific locale containing any resource 9482ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * data, or null 9492ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param actual the locale containing data used to construct this 9502ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * object, or null 9512ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see android.icu.util.ULocale 9522ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see android.icu.util.ULocale#VALID_LOCALE 9532ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see android.icu.util.ULocale#ACTUAL_LOCALE 9542ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 9552ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller final void setLocale(ULocale valid, ULocale actual) { 9562ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // Change the following to an assertion later 9572ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if ((valid == null) != (actual == null)) { 9582ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller ///CLOVER:OFF 9592ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller throw new IllegalArgumentException(); 9602ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller ///CLOVER:ON 9612ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 9622ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // Another check we could do is that the actual locale is at 9632ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // the same level or less specific than the valid locale. 9642ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller this.validLocale = valid; 9652ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller this.actualLocale = actual; 9662ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 9672ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 9682ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 9692ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * The most specific locale containing any resource data, or null. 9702ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see android.icu.util.ULocale 9712ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 9722ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller private ULocale validLocale; 9732ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 9742ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 9752ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * The locale containing data used to construct this object, or 9762ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * null. 9772ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see android.icu.util.ULocale 9782ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 9792ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller private ULocale actualLocale; 9802ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 9812ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // -------- END ULocale boilerplate -------- 9822ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller} 983