ICU-10592 ICU4J BreakIterator, hoist rule status constants to base BreakIterator class

X-SVN-Rev: 34890
This commit is contained in:
Andy Heninger 2014-01-14 22:27:51 +00:00
parent 77c39a1091
commit a82255096c
3 changed files with 113 additions and 75 deletions

View file

@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (C) 1996-2013, International Business Machines Corporation and *
* Copyright (C) 1996-2014, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
@ -372,6 +372,79 @@ public abstract class BreakIterator implements Cloneable
*/
public abstract int current();
/**
* Tag value for "words" that do not fit into any of other categories.
* Includes spaces and most punctuation.
* @draft ICU 53
* @provisional This is a draft API and might change in a future release of ICU.
*/
public static final int WORD_NONE = 0;
/**
* Upper bound for tags for uncategorized words.
* @draft ICU 53
* @provisional This is a draft API and might change in a future release of ICU.
*/
public static final int WORD_NONE_LIMIT = 100;
/**
* Tag value for words that appear to be numbers, lower limit.
* @draft ICU 53
* @provisional This is a draft API and might change in a future release of ICU.
*/
public static final int WORD_NUMBER = 100;
/**
* Tag value for words that appear to be numbers, upper limit.
* @draft ICU 53
* @provisional This is a draft API and might change in a future release of ICU.
*/
public static final int WORD_NUMBER_LIMIT = 200;
/**
* Tag value for words that contain letters, excluding
* hiragana, katakana or ideographic characters, lower limit.
* @draft ICU 53
* @provisional This is a draft API and might change in a future release of ICU.
*/
public static final int WORD_LETTER = 200;
/**
* Tag value for words containing letters, upper limit
* @draft ICU 53
* @provisional This is a draft API and might change in a future release of ICU.
*/
public static final int WORD_LETTER_LIMIT = 300;
/**
* Tag value for words containing kana characters, lower limit
* @draft ICU 53
* @provisional This is a draft API and might change in a future release of ICU.
*/
public static final int WORD_KANA = 300;
/**
* Tag value for words containing kana characters, upper limit
* @draft ICU 53
* @provisional This is a draft API and might change in a future release of ICU.
*/
public static final int WORD_KANA_LIMIT = 400;
/**
* Tag value for words containing ideographic characters, lower limit
* @draft ICU 53
* @provisional This is a draft API and might change in a future release of ICU.
*/
public static final int WORD_IDEO = 400;
/**
* Tag value for words containing ideographic characters, upper limit
* @draft ICU 53
* @provisional This is a draft API and might change in a future release of ICU.
*/
public static final int WORD_IDEO_LIMIT = 500;
/**
    * For RuleBasedBreakIterators, return the status tag from the
    * break rule that determined the most recently

View file

@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (C) 2005-2013 International Business Machines Corporation and *
* Copyright (C) 2005-2014 International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
@ -172,77 +172,6 @@ public class RuleBasedBreakIterator extends BreakIterator {
return fRData.fRuleSource.hashCode();
}
/**
* Tag value for "words" that do not fit into any of other categories.
* Includes spaces and most punctuation.
* @draft ICU 3.0
* @provisional This is a draft API and might change in a future release of ICU.
*/
public static final int WORD_NONE = 0;
/**
* Upper bound for tags for uncategorized words.
* @draft ICU 3.0
* @provisional This is a draft API and might change in a future release of ICU.
*/
public static final int WORD_NONE_LIMIT = 100;
/**
* Tag value for words that appear to be numbers, lower limit.
* @draft ICU 3.0
* @provisional This is a draft API and might change in a future release of ICU.
*/
public static final int WORD_NUMBER = 100;
/**
* Tag value for words that appear to be numbers, upper limit.
* @draft ICU 3.0
* @provisional This is a draft API and might change in a future release of ICU.
*/
public static final int WORD_NUMBER_LIMIT = 200;
/**
* Tag value for words that contain letters, excluding
* hiragana, katakana or ideographic characters, lower limit.
* @draft ICU 3.0
* @provisional This is a draft API and might change in a future release of ICU.
*/
public static final int WORD_LETTER = 200;
/**
* Tag value for words containing letters, upper limit
* @draft ICU 3.0
* @provisional This is a draft API and might change in a future release of ICU.
*/
public static final int WORD_LETTER_LIMIT = 300;
/**
* Tag value for words containing kana characters, lower limit
* @draft ICU 3.0
* @provisional This is a draft API and might change in a future release of ICU.
*/
public static final int WORD_KANA = 300;
/**
* Tag value for words containing kana characters, upper limit
* @draft ICU 3.0
* @provisional This is a draft API and might change in a future release of ICU.
*/
public static final int WORD_KANA_LIMIT = 400;
/**
* Tag value for words containing ideographic characters, lower limit
* @draft ICU 3.0
* @provisional This is a draft API and might change in a future release of ICU.
*/
public static final int WORD_IDEO = 400;
/**
* Tag value for words containing ideographic characters, upper limit
* @draft ICU 3.0
* @provisional This is a draft API and might change in a future release of ICU.
*/
public static final int WORD_IDEO_LIMIT = 500;
private static final int START_STATE = 1; // The state number of the starting state
private static final int STOP_STATE = 0; // The state-transition value indicating "stop"

View file

@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (C) 2001-2010, International Business Machines Corporation and *
* Copyright (C) 2001-2014, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
@ -18,6 +18,7 @@ import java.util.Locale;
import com.ibm.icu.text.BreakIterator;
import com.ibm.icu.text.RuleBasedBreakIterator;
import com.ibm.icu.util.ULocale;
/**
* API Test the RuleBasedBreakIterator class
@ -377,6 +378,41 @@ public class RBBIAPITest extends com.ibm.icu.dev.test.TestFmwk {
doBoundaryTest(wordIter2, testString1, bounds2);
}
/**
* Tests the rule status return value constants
*/
public void TestRuleStatus() {
BreakIterator bi = BreakIterator.getWordInstance(ULocale.ENGLISH);
bi.setText("# ");
assertEquals(null, bi.next(), 1);
assertTrue(null, bi.getRuleStatus() >= RuleBasedBreakIterator.WORD_NONE);
assertTrue(null, bi.getRuleStatus() < RuleBasedBreakIterator.WORD_NONE_LIMIT);
bi.setText("3 ");
assertEquals(null, bi.next(), 1);
assertTrue(null, bi.getRuleStatus() >= RuleBasedBreakIterator.WORD_NUMBER);
assertTrue(null, bi.getRuleStatus() < RuleBasedBreakIterator.WORD_NUMBER_LIMIT);
bi.setText("a ");
assertEquals(null, bi.next(), 1);
assertTrue(null, bi.getRuleStatus() >= RuleBasedBreakIterator.WORD_LETTER );
assertTrue(null, bi.getRuleStatus() < RuleBasedBreakIterator.WORD_LETTER_LIMIT);
bi.setText("");
assertEquals(null, bi.next(), 1);
assertTrue(null, bi.getRuleStatus() >= RuleBasedBreakIterator.WORD_KANA );
// TODO: ticket #10261, Kana is not returning the correct status.
// assertTrue(null, bi.getRuleStatus() < RuleBasedBreakIterator.WORD_KANA_LIMIT);
// System.out.println("\n" + bi.getRuleStatus());
bi.setText("退 ");
assertEquals(null, bi.next(), 1);
assertTrue(null, bi.getRuleStatus() >= RuleBasedBreakIterator.WORD_IDEO );
assertTrue(null, bi.getRuleStatus() < RuleBasedBreakIterator.WORD_IDEO_LIMIT);
}
//---------------------------------------------
//Internal subroutines
//---------------------------------------------
@ -416,4 +452,4 @@ public class RBBIAPITest extends com.ibm.icu.dev.test.TestFmwk {
else
logln("****selected \"" + selected + "\"");
}
}
}