jdk/src/share/classes/java/text/BreakIterator.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1996-2006 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * The original version of this source code and documentation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * is copyrighted and owned by Taligent, Inc., a wholly-owned
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * subsidiary of IBM. These materials are provided under terms
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * of a License Agreement between Taligent and Sun. This technology
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * is protected by multiple US and International patents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * This notice and attribution to Taligent may not be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * Taligent is a registered trademark of Taligent, Inc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
package java.text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.lang.ref.SoftReference;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.text.CharacterIterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.text.StringCharacterIterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.text.spi.BreakIteratorProvider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import java.util.MissingResourceException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import java.util.ResourceBundle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import java.util.spi.LocaleServiceProvider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import sun.util.LocaleServiceProviderPool;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import sun.util.resources.LocaleData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * The <code>BreakIterator</code> class implements methods for finding
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * the location of boundaries in text. Instances of <code>BreakIterator</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * maintain a current position and scan over text
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * returning the index of characters where boundaries occur.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * Internally, <code>BreakIterator</code> scans text using a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * <code>CharacterIterator</code>, and is thus able to scan text held
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * by any object implementing that protocol. A <code>StringCharacterIterator</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * is used to scan <code>String</code> objects passed to <code>setText</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * You use the factory methods provided by this class to create
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * instances of various types of break iterators. In particular,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * use <code>getWordInstance</code>, <code>getLineInstance</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * <code>getSentenceInstance</code>, and <code>getCharacterInstance</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * to create <code>BreakIterator</code>s that perform
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * word, line, sentence, and character boundary analysis respectively.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * A single <code>BreakIterator</code> can work only on one unit
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * (word, line, sentence, and so on). You must use a different iterator
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * for each unit boundary analysis you wish to perform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * <p><a name="line"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * Line boundary analysis determines where a text string can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * broken when line-wrapping. The mechanism correctly handles
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * punctuation and hyphenated words. Actual line breaking needs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * to also consider the available line width and is handled by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * higher-level software.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * <p><a name="sentence"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * Sentence boundary analysis allows selection with correct interpretation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * of periods within numbers and abbreviations, and trailing punctuation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * marks such as quotation marks and parentheses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * <p><a name="word"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * Word boundary analysis is used by search and replace functions, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * well as within text editing applications that allow the user to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * select words with a double click. Word selection provides correct
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * interpretation of punctuation marks within and following
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * words. Characters that are not part of a word, such as symbols
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * or punctuation marks, have word-breaks on both sides.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * <p><a name="character"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * Character boundary analysis allows users to interact with characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * as they expect to, for example, when moving the cursor through a text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * string. Character boundary analysis provides correct navigation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * through character strings, regardless of how the character is stored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * The boundaries returned may be those of supplementary characters,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * combining character sequences, or ligature clusters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * For example, an accented character might be stored as a base character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * and a diacritical mark. What users consider to be a character can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * differ between languages.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * The <code>BreakIterator</code> instances returned by the factory methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * of this class are intended for use with natural languages only, not for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * programming language text. It is however possible to define subclasses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * that tokenize a programming language.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * <strong>Examples</strong>:<P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * Creating and using text boundaries:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * public static void main(String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 *      if (args.length == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 *          String stringToExamine = args[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 *          //print each word in order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 *          BreakIterator boundary = BreakIterator.getWordInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 *          boundary.setText(stringToExamine);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 *          printEachForward(boundary, stringToExamine);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 *          //print each sentence in reverse order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 *          boundary = BreakIterator.getSentenceInstance(Locale.US);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 *          boundary.setText(stringToExamine);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 *          printEachBackward(boundary, stringToExamine);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 *          printFirst(boundary, stringToExamine);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 *          printLast(boundary, stringToExamine);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 *      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * Print each element in order:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * public static void printEachForward(BreakIterator boundary, String source) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 *     int start = boundary.first();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 *     for (int end = boundary.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 *          end != BreakIterator.DONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 *          start = end, end = boundary.next()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 *          System.out.println(source.substring(start,end));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 * Print each element in reverse order:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 * public static void printEachBackward(BreakIterator boundary, String source) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 *     int end = boundary.last();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 *     for (int start = boundary.previous();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 *          start != BreakIterator.DONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 *          end = start, start = boundary.previous()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 *         System.out.println(source.substring(start,end));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 * Print first element:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 * public static void printFirst(BreakIterator boundary, String source) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
 *     int start = boundary.first();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
 *     int end = boundary.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
 *     System.out.println(source.substring(start,end));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
 * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
 * Print last element:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
 * public static void printLast(BreakIterator boundary, String source) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
 *     int end = boundary.last();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
 *     int start = boundary.previous();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
 *     System.out.println(source.substring(start,end));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
 * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
 * Print the element at a specified position:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
 * public static void printAt(BreakIterator boundary, int pos, String source) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
 *     int end = boundary.following(pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
 *     int start = boundary.previous();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
 *     System.out.println(source.substring(start,end));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
 * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
 * Find the next word:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
 * public static int nextWordStartAfter(int pos, String text) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
 *     BreakIterator wb = BreakIterator.getWordInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
 *     wb.setText(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
 *     int last = wb.following(pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
 *     int current = wb.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
 *     while (current != BreakIterator.DONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
 *         for (int p = last; p < current; p++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
 *             if (Character.isLetter(text.codePointAt(p)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
 *                 return last;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
 *         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
 *         last = current;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
 *         current = wb.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
 *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
 *     return BreakIterator.DONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
 * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
 * (The iterator returned by BreakIterator.getWordInstance() is unique in that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
 * the break positions it returns don't represent both the start and end of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
 * thing being iterated over.  That is, a sentence-break iterator returns breaks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
 * that each represent the end of one sentence and the beginning of the next.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
 * With the word-break iterator, the characters between two boundaries might be a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
 * word, or they might be the punctuation or whitespace between two words.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
 * above code uses a simple heuristic to determine which boundary is the beginning
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
 * of a word: If the characters between this boundary and the next boundary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
 * include at least one letter (this can be an alphabetical letter, a CJK ideograph,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
 * a Hangul syllable, a Kana character, etc.), then the text between this boundary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
 * and the next is a word; otherwise, it's the material between words.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
 * @see CharacterIterator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
public abstract class BreakIterator implements Cloneable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * Constructor. BreakIterator is stateless and has no default behavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    protected BreakIterator()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * Create a copy of this iterator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @return A copy of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    public Object clone()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            return super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        catch (CloneNotSupportedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            throw new InternalError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * DONE is returned by previous(), next(), next(int), preceding(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * and following(int) when either the first or last text boundary has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * reached.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    public static final int DONE = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * Returns the first boundary. The iterator's current position is set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * to the first text boundary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * @return The character index of the first text boundary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    public abstract int first();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * Returns the last boundary. The iterator's current position is set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * to the last text boundary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * @return The character index of the last text boundary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    public abstract int last();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * Returns the nth boundary from the current boundary. If either
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * the first or last text boundary has been reached, it returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * <code>BreakIterator.DONE</code> and the current position is set to either
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * the first or last text boundary depending on which one is reached. Otherwise,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * the iterator's current position is set to the new boundary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * For example, if the iterator's current position is the mth text boundary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * and three more boundaries exist from the current boundary to the last text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * boundary, the next(2) call will return m + 2. The new text position is set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * to the (m + 2)th text boundary. A next(4) call would return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * <code>BreakIterator.DONE</code> and the last text boundary would become the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * new text position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * @param n which boundary to return.  A value of 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * does nothing.  Negative values move to previous boundaries
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * and positive values move to later boundaries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * @return The character index of the nth boundary from the current position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * or <code>BreakIterator.DONE</code> if either first or last text boundary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * has been reached.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    public abstract int next(int n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * Returns the boundary following the current boundary. If the current boundary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * is the last text boundary, it returns <code>BreakIterator.DONE</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * the iterator's current position is unchanged. Otherwise, the iterator's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * current position is set to the boundary following the current boundary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * @return The character index of the next text boundary or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * <code>BreakIterator.DONE</code> if the current boundary is the last text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * boundary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * Equivalent to next(1).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * @see #next(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    public abstract int next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * Returns the boundary preceding the current boundary. If the current boundary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * is the first text boundary, it returns <code>BreakIterator.DONE</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * the iterator's current position is unchanged. Otherwise, the iterator's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * current position is set to the boundary preceding the current boundary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * @return The character index of the previous text boundary or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * <code>BreakIterator.DONE</code> if the current boundary is the first text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * boundary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    public abstract int previous();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * Returns the first boundary following the specified character offset. If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * specified offset equals to the last text boundary, it returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * <code>BreakIterator.DONE</code> and the iterator's current position is unchanged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * Otherwise, the iterator's current position is set to the returned boundary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * The value returned is always greater than the offset or the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * <code>BreakIterator.DONE</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * @param offset the character offset to begin scanning.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * @return The first boundary after the specified offset or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * <code>BreakIterator.DONE</code> if the last text boundary is passed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * as the offset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * @exception  IllegalArgumentException if the specified offset is less than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * the first text boundary or greater than the last text boundary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    public abstract int following(int offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * Returns the last boundary preceding the specified character offset. If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * specified offset equals to the first text boundary, it returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * <code>BreakIterator.DONE</code> and the iterator's current position is unchanged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * Otherwise, the iterator's current position is set to the returned boundary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * The value returned is always less than the offset or the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * <code>BreakIterator.DONE</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * @param offset the characater offset to begin scanning.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * @return The last boundary before the specified offset or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * <code>BreakIterator.DONE</code> if the first text boundary is passed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * as the offset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * @exception   IllegalArgumentException if the specified offset is less than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * the first text boundary or greater than the last text boundary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    public int preceding(int offset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        // NOTE:  This implementation is here solely because we can't add new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        // abstract methods to an existing class.  There is almost ALWAYS a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        // better, faster way to do this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        int pos = following(offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        while (pos >= offset && pos != DONE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            pos = previous();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        return pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * Returns true if the specified character offset is a text boundary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * @param offset the character offset to check.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * @return <code>true</code> if "offset" is a boundary position,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * @exception   IllegalArgumentException if the specified offset is less than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * the first text boundary or greater than the last text boundary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    public boolean isBoundary(int offset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        // NOTE: This implementation probably is wrong for most situations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        // because it fails to take into account the possibility that a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        // CharacterIterator passed to setText() may not have a begin offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        // of 0.  But since the abstract BreakIterator doesn't have that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        // knowledge, it assumes the begin offset is 0.  If you subclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        // BreakIterator, copy the SimpleTextBoundary implementation of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        // function into your subclass.  [This should have been abstract at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        // this level, but it's too late to fix that now.]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        if (offset == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        int boundary = following(offset - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        if (boundary == DONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        return boundary == offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * Returns character index of the text boundary that was most
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * recently returned by next(), next(int), previous(), first(), last(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * following(int) or preceding(int). If any of these methods returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * <code>BreakIterator.DONE</code> because either first or last text boundary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * has been reached, it returns the first or last text boundary depending on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * which one is reached.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * @return The text boundary returned from the above methods, first or last
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * text boundary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * @see #next()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * @see #next(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * @see #previous()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * @see #first()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * @see #last()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * @see #following(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * @see #preceding(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    public abstract int current();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * Get the text being scanned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * @return the text being scanned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    public abstract CharacterIterator getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * Set a new text string to be scanned.  The current scan
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * position is reset to first().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * @param newText new text to scan.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    public void setText(String newText)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        setText(new StringCharacterIterator(newText));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * Set a new text for scanning.  The current scan
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * position is reset to first().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * @param newText new text to scan.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    public abstract void setText(CharacterIterator newText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    private static final int CHARACTER_INDEX = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    private static final int WORD_INDEX = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    private static final int LINE_INDEX = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    private static final int SENTENCE_INDEX = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    private static final SoftReference[] iterCache = new SoftReference[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * Returns a new <code>BreakIterator</code> instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * for <a href="#word">word breaks</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * for the {@linkplain Locale#getDefault() default locale}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * @return A break iterator for word breaks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    public static BreakIterator getWordInstance()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        return getWordInstance(Locale.getDefault());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * Returns a new <code>BreakIterator</code> instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * for <a href="#word">word breaks</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * for the given locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * @param locale the desired locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * @return A break iterator for word breaks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * @exception NullPointerException if <code>locale</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    public static BreakIterator getWordInstance(Locale locale)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        return getBreakInstance(locale,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                                WORD_INDEX,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                                "WordData",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                                "WordDictionary");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * Returns a new <code>BreakIterator</code> instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * for <a href="#line">line breaks</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * for the {@linkplain Locale#getDefault() default locale}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * @return A break iterator for line breaks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    public static BreakIterator getLineInstance()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        return getLineInstance(Locale.getDefault());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * Returns a new <code>BreakIterator</code> instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * for <a href="#line">line breaks</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * for the given locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * @param locale the desired locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * @return A break iterator for line breaks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * @exception NullPointerException if <code>locale</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    public static BreakIterator getLineInstance(Locale locale)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        return getBreakInstance(locale,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                                LINE_INDEX,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                                "LineData",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                                "LineDictionary");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * Returns a new <code>BreakIterator</code> instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * for <a href="#character">character breaks</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * for the {@linkplain Locale#getDefault() default locale}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * @return A break iterator for character breaks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    public static BreakIterator getCharacterInstance()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        return getCharacterInstance(Locale.getDefault());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * Returns a new <code>BreakIterator</code> instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * for <a href="#character">character breaks</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * for the given locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * @param locale the desired locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * @return A break iterator for character breaks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * @exception NullPointerException if <code>locale</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    public static BreakIterator getCharacterInstance(Locale locale)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        return getBreakInstance(locale,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                                CHARACTER_INDEX,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                                "CharacterData",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                                "CharacterDictionary");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * Returns a new <code>BreakIterator</code> instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * for <a href="#sentence">sentence breaks</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * for the {@linkplain Locale#getDefault() default locale}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * @return A break iterator for sentence breaks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    public static BreakIterator getSentenceInstance()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        return getSentenceInstance(Locale.getDefault());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * Returns a new <code>BreakIterator</code> instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * for <a href="#sentence">sentence breaks</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * for the given locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * @param locale the desired locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * @return A break iterator for sentence breaks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * @exception NullPointerException if <code>locale</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    public static BreakIterator getSentenceInstance(Locale locale)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        return getBreakInstance(locale,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                                SENTENCE_INDEX,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                                "SentenceData",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                                "SentenceDictionary");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    private static BreakIterator getBreakInstance(Locale locale,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                                                  int type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                                                  String dataName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                                                  String dictionaryName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        if (iterCache[type] != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            BreakIteratorCache cache = (BreakIteratorCache) iterCache[type].get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            if (cache != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                if (cache.getLocale().equals(locale)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                    return cache.createBreakInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        BreakIterator result = createBreakInstance(locale,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                                                   type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                                                   dataName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                                                   dictionaryName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        BreakIteratorCache cache = new BreakIteratorCache(locale, result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        iterCache[type] = new SoftReference(cache);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    private static ResourceBundle getBundle(final String baseName, final Locale locale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
         return (ResourceBundle) AccessController.doPrivileged(new PrivilegedAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
            public Object run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                return ResourceBundle.getBundle(baseName, locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    private static BreakIterator createBreakInstance(Locale locale,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                                                     int type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                                                     String dataName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                                                     String dictionaryName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        // Check whether a provider can provide an implementation that's closer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        // to the requested locale than what the Java runtime itself can provide.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        LocaleServiceProviderPool pool =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            LocaleServiceProviderPool.getPool(BreakIteratorProvider.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        if (pool.hasProviders()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            BreakIterator providersInstance = pool.getLocalizedObject(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                                                    BreakIteratorGetter.INSTANCE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                                                    locale, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            if (providersInstance != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                return providersInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        ResourceBundle bundle = getBundle(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                        "sun.text.resources.BreakIteratorInfo", locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        String[] classNames = bundle.getStringArray("BreakIteratorClasses");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        String dataFile = bundle.getString(dataName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            if (classNames[type].equals("RuleBasedBreakIterator")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                return new RuleBasedBreakIterator(dataFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            else if (classNames[type].equals("DictionaryBasedBreakIterator")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                String dictionaryFile = bundle.getString(dictionaryName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                return new DictionaryBasedBreakIterator(dataFile, dictionaryFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                throw new IllegalArgumentException("Invalid break iterator class \"" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                                classNames[type] + "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            throw new InternalError(e.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * Returns an array of all locales for which the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * <code>get*Instance</code> methods of this class can return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * localized instances.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * The returned array represents the union of locales supported by the Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * runtime and by installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * {@link java.text.spi.BreakIteratorProvider BreakIteratorProvider} implementations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * It must contain at least a <code>Locale</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * instance equal to {@link java.util.Locale#US Locale.US}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * @return An array of locales for which localized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     *         <code>BreakIterator</code> instances are available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    public static synchronized Locale[] getAvailableLocales()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        LocaleServiceProviderPool pool =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            LocaleServiceProviderPool.getPool(BreakIteratorProvider.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        return pool.getAvailableLocales();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    private static final class BreakIteratorCache {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        private BreakIterator iter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        private Locale locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        BreakIteratorCache(Locale locale, BreakIterator iter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            this.locale = locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
            this.iter = (BreakIterator) iter.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        Locale getLocale() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            return locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        BreakIterator createBreakInstance() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            return (BreakIterator) iter.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    static long getLong(byte[] buf, int offset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        long num = buf[offset]&0xFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        for (int i = 1; i < 8; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            num = num<<8 | (buf[offset+i]&0xFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        return num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    static int getInt(byte[] buf, int offset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        int num = buf[offset]&0xFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        for (int i = 1; i < 4; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            num = num<<8 | (buf[offset+i]&0xFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        return num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    static short getShort(byte[] buf, int offset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        short num = (short)(buf[offset]&0xFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        num = (short)(num<<8 | (buf[offset+1]&0xFF));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        return num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * Obtains a BreakIterator instance from a BreakIteratorProvider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     * implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
    private static class BreakIteratorGetter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        implements LocaleServiceProviderPool.LocalizedObjectGetter<BreakIteratorProvider, BreakIterator> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        private static final BreakIteratorGetter INSTANCE =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            new BreakIteratorGetter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        public BreakIterator getObject(BreakIteratorProvider breakIteratorProvider,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                                Locale locale,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                                String key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                                Object... params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            assert params.length == 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            switch ((Integer)params[0]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            case CHARACTER_INDEX:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                return breakIteratorProvider.getCharacterInstance(locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            case WORD_INDEX:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                return breakIteratorProvider.getWordInstance(locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            case LINE_INDEX:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                return breakIteratorProvider.getLineInstance(locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            case SENTENCE_INDEX:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                return breakIteratorProvider.getSentenceInstance(locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                assert false : "should not happen";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
}