diff options
author | Tom Tromey <tromey@redhat.com> | 2001-09-05 00:00:55 +0000 |
---|---|---|
committer | Tom Tromey <tromey@gcc.gnu.org> | 2001-09-05 00:00:55 +0000 |
commit | a1f4e5ed0ad7c060fc1b90c3b363877cb8cca198 (patch) | |
tree | e84d2d5f42b8908733b2858f19c7f95e32335a86 /libjava/gnu/java/text/SentenceBreakIterator.java | |
parent | 45932d27fb140524de00d4a08efea4cf75dd7ca0 (diff) | |
download | gcc-a1f4e5ed0ad7c060fc1b90c3b363877cb8cca198.zip gcc-a1f4e5ed0ad7c060fc1b90c3b363877cb8cca198.tar.gz gcc-a1f4e5ed0ad7c060fc1b90c3b363877cb8cca198.tar.bz2 |
SimpleDateFormat.java: Re-merged with Classpath.
* java/text/SimpleDateFormat.java: Re-merged with Classpath.
* gnu/gcj/text/LocaleData.java, gnu/gcj/text/LocaleData_en.java,
gnu/gcj/text/LocaleData_en_US.java: Removed.
* java/text/DateFormatSymbols.java (clone): Use Classpath
implementation.
(equals): Simplified.
(DateFormatSymbols): Look in gnu.java.locale for information.
(DateFormatSymbols(DateFormatSymbols)): Removed.
(safeGetResource): Removed.
(DateFormatSymbols): Throws MissingResourceException.
(ampmsDefault, erasDefault, localPatternCharsDefault,
monthsDefault, shortMonthsDefault, shortWeekdaysDefault,
weekdaysDefault, zoneStringsDefault): Removed.
* java/text/Collator.java (getAvailableLocales): Use modified
Classpath implementation.
(getInstance): Look in gnu.java.locale for information.
(clone): Rewrote.
* java/text/MessageFormat.java: Reindented.
(clone): Rewrote.
* java/text/FieldPosition.java: Merged with Classpath.
* java/text/ParsePosition.java: Merged with Classpath.
* java/text/Format.java: Merged with Classpath.
* java/text/StringCharacterIterator.java
(StringCharacterIterator(StringCharacterIterator,int,int)): New
constructor from Classpath.
* java/text/Annotation.java,
java/text/AttributedCharacterIterator.java,
java/text/AttributedString.java,
java/text/AttributedStringIterator.java: New from Classpath.
* java/text/CharacterIterator.java: Copied from Classpath.
* java/text/ChoiceFormat.java: Reindented.
(clone): Removed.
* gnu/java/text/BaseBreakIterator.java,
gnu/java/text/CharacterBreakIterator.java,
gnu/java/text/LineBreakIterator.java,
gnu/java/text/LocaleData_en.java,
gnu/java/text/LocaleData_en_US.java,
gnu/java/text/SentenceBreakIterator.java,
gnu/java/text/WordBreakIterator.java: Renamed from gnu/gcj/text/*.
* gnu/gcj/text/BaseBreakIterator.java (last): Advance past final
character.
* java/text/BreakIterator.java (getAvailableLocales): Use
Classpath implementation.
(getInstance): Look in gnu.java.locale for information.
(getCharacterInstance, getLineInstance, getSentenceInstance,
getWordInstance): Look in gnu.java.text for implementations.
* java/text/DecimalFormatSymbols.java: Reindented
(clone): Use Classpath implementation.
(DecimalFormatSymbols(DecimalFormatSymbols)): Removed.
(DecimalFormatSymbols(Locale)): Look in gnu.java.locale for
information.
* java/text/DateFormat.java: Merged with Classpath.
(getAvailableLocales): Use Classpath implementation.
(format(Object,StringBuffer,FieldPosition)): Minor cleanup.
(computeInstance): Look in gnu.java.locale for information.
* java/text/NumberFormat.java: Reindented.
(computeInstance): Look in gnu.java.locale for information.
(getAvailableLocales): Use implementation from Classpath.
(setMaximumIntegerDigits): Likewise.
(setMinimumIntegerDigits): Likewise.
(setMaximumFractionDigits): Likewise.
(clone): Removed.
* java/text/DecimalFormat.java: Reindented.
* gnu/java/locale/LocaleInformation_en.java: Copied from Classpath.
* gnu/java/locale/LocaleInformation_en_US.java: Copied from Classpath.
* Makefile.in: Rebuilt.
* Makefile.am (ordinary_java_source_files): Added all new files.
(ordinary_java_source_files): Renamed or removed gnu/gcj/text/*.
* java/security/spec/AlgorithmParameterSpec.java,
java/security/spec/KeySpec.java: Re-merged with Classpath.
From-SVN: r45390
Diffstat (limited to 'libjava/gnu/java/text/SentenceBreakIterator.java')
-rw-r--r-- | libjava/gnu/java/text/SentenceBreakIterator.java | 243 |
1 files changed, 243 insertions, 0 deletions
diff --git a/libjava/gnu/java/text/SentenceBreakIterator.java b/libjava/gnu/java/text/SentenceBreakIterator.java new file mode 100644 index 0000000..9f9e816 --- /dev/null +++ b/libjava/gnu/java/text/SentenceBreakIterator.java @@ -0,0 +1,243 @@ +/* SentenceBreakIterator.java - Default sentence BreakIterator. + Copyright (C) 1999, 2001 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +As a special exception, if you link this library with other files to +produce an executable, this library does not by itself cause the +resulting executable to be covered by the GNU General Public License. +This exception does not however invalidate any other reasons why the +executable file might be covered by the GNU General Public License. */ + + +package gnu.java.text; + +import java.text.BreakIterator; +import java.text.CharacterIterator; + +/** + * @author Tom Tromey <tromey@cygnus.com> + * @date March 23, 1999 + * Written using The Unicode Standard, Version 2.0. + */ + +public class SentenceBreakIterator extends BaseBreakIterator +{ + public Object clone () + { + return new SentenceBreakIterator (this); + } + + public SentenceBreakIterator () + { + iter = null; + } + + private SentenceBreakIterator (SentenceBreakIterator other) + { + iter = (CharacterIterator) other.iter.clone(); + } + + public int next () + { + int end = iter.getEndIndex(); + if (iter.getIndex() == end) + return DONE; + + while (iter.getIndex() < end) + { + char c = iter.current(); + if (c == CharacterIterator.DONE) + break; + int type = Character.getType(c); + + char n = iter.next(); + if (n == CharacterIterator.DONE) + break; + + // Always break after paragraph separator. + if (type == Character.PARAGRAPH_SEPARATOR) + break; + + if (c == '!' || c == '?') + { + // Skip close punctuation. + while (n != CharacterIterator.DONE + && Character.getType(n) == Character.END_PUNCTUATION) + n = iter.next(); + // Skip spaces. + while (n != CharacterIterator.DONE + && Character.getType(n) == Character.SPACE_SEPARATOR) + n = iter.next(); + // Skip optional paragraph separator. + if (n != CharacterIterator.DONE + && Character.getType(n) == Character.PARAGRAPH_SEPARATOR) + n = iter.next(); + + // There's always a break somewhere after `!' or `?'. + break; + } + + if (c == '.') + { + int save = iter.getIndex(); + // Skip close punctuation. + while (n != CharacterIterator.DONE + && Character.getType(n) == Character.END_PUNCTUATION) + n = iter.next(); + // Skip spaces. We keep count because we need at least + // one for this period to represent a terminator. + int spcount = 0; + while (n != CharacterIterator.DONE + && Character.getType(n) == Character.SPACE_SEPARATOR) + { + n = iter.next(); + ++spcount; + } + if (spcount > 0) + { + int save2 = iter.getIndex(); + // Skip over open puncutation. + while (n != CharacterIterator.DONE + && Character.getType(n) == Character.START_PUNCTUATION) + n = iter.next(); + // Next character must not be lower case. + if (n == CharacterIterator.DONE + || ! Character.isLowerCase(n)) + { + iter.setIndex(save2); + break; + } + } + iter.setIndex(save); + } + } + + return iter.getIndex(); + } + + private final int previous_internal () + { + int start = iter.getBeginIndex(); + if (iter.getIndex() == start) + return DONE; + + while (iter.getIndex() >= start) + { + char c = iter.previous(); + if (c == CharacterIterator.DONE) + break; + + char n = iter.previous(); + if (n == CharacterIterator.DONE) + break; + iter.next(); + int nt = Character.getType(n); + + if (! Character.isLowerCase(c) + && (nt == Character.START_PUNCTUATION + || nt == Character.SPACE_SEPARATOR)) + { + int save = iter.getIndex(); + int save_nt = nt; + char save_n = n; + // Skip open punctuation. + while (n != CharacterIterator.DONE + && Character.getType(n) == Character.START_PUNCTUATION) + n = iter.previous(); + if (n == CharacterIterator.DONE) + break; + if (Character.getType(n) == Character.SPACE_SEPARATOR) + { + // Must have at least once space after the `.'. + int save2 = iter.getIndex(); + while (n != CharacterIterator.DONE + && Character.getType(n) == Character.SPACE_SEPARATOR) + n = iter.previous(); + // Skip close punctuation. + while (n != CharacterIterator.DONE + && Character.getType(n) == Character.END_PUNCTUATION) + n = iter.previous(); + if (n == CharacterIterator.DONE || n == '.') + { + // Communicate location of actual end. + period = iter.getIndex(); + iter.setIndex(save2); + break; + } + } + iter.setIndex(save); + nt = save_nt; + n = save_n; + } + + if (nt == Character.PARAGRAPH_SEPARATOR) + { + // Communicate location of actual end. + period = iter.getIndex(); + break; + } + else if (nt == Character.SPACE_SEPARATOR + || nt == Character.END_PUNCTUATION) + { + int save = iter.getIndex(); + // Skip spaces. + while (n != CharacterIterator.DONE + && Character.getType(n) == Character.SPACE_SEPARATOR) + n = iter.previous(); + // Skip close punctuation. + while (n != CharacterIterator.DONE + && Character.getType(n) == Character.END_PUNCTUATION) + n = iter.previous(); + int here = iter.getIndex(); + iter.setIndex(save); + if (n == CharacterIterator.DONE || n == '!' || n == '?') + { + // Communicate location of actual end. + period = here; + break; + } + } + else if (n == '!' || n == '?') + { + // Communicate location of actual end. + period = iter.getIndex(); + break; + } + } + + return iter.getIndex(); + } + + public int previous () + { + // We want to skip over the first sentence end to the second one. + // However, at the end of the string we want the first end. + int here = iter.getIndex(); + period = here; + int first = previous_internal (); + if (here == iter.getEndIndex() || first == DONE) + return first; + iter.setIndex(period); + return previous_internal (); + } + + // This is used for communication between previous and + // previous_internal. + private int period; +} |