]> granicus.if.org Git - icu/commitdiff
ICU-5901 RBBI.getRuleStatus(), hoist to BreakIterator from RuleBasedBreakIterator
authorAndy Heninger <andy.heninger@gmail.com>
Fri, 14 Jun 2013 00:47:11 +0000 (00:47 +0000)
committerAndy Heninger <andy.heninger@gmail.com>
Fri, 14 Jun 2013 00:47:11 +0000 (00:47 +0000)
X-SVN-Rev: 33830

icu4c/source/common/brkiter.cpp
icu4c/source/common/unicode/brkiter.h
icu4c/source/test/intltest/rbbiapts.cpp
icu4c/source/test/intltest/rbbiapts.h
icu4c/source/test/intltest/rbbitst.cpp

index 9744a2cfd3f600ef9ac7429b96721f7a00d92eca..56a532d4a5d0ac100629b581899ec63a228a62d1 100644 (file)
@@ -438,6 +438,29 @@ BreakIterator::getLocaleID(ULocDataLocaleType type, UErrorCode& status) const {
     return locBased.getLocaleID(type, status);
 }
 
+
+// This implementation of getRuleStatus is a do-nothing stub, here to
+// provide a default implementation for any derived BreakIterator classes that
+// do not implement it themselves.
+int32_t BreakIterator::getRuleStatus() const {
+    return 0;
+}
+
+// This implementation of getRuleStatusVec is a do-nothing stub, here to
+// provide a default implementation for any derived BreakIterator classes that
+// do not implement it themselves.
+int32_t BreakIterator::getRuleStatusVec(int32_t *fillInVec, int32_t capacity, UErrorCode &status) {
+    if (U_FAILURE(status)) {
+        return 0;
+    }
+    if (capacity < 1) {
+        status = U_BUFFER_OVERFLOW_ERROR;
+        return 1;
+    }
+    *fillInVec = 0;
+    return 1;
+}
+
 U_NAMESPACE_END
 
 #endif /* #if !UCONFIG_NO_BREAK_ITERATION */
index dd9d4e23db163581d571a4ed25da7554b4c58ab8..947059a801f1b61ec5246ae26dd5d25a44cce8f6 100644 (file)
@@ -290,6 +290,52 @@ public:
      */
     virtual int32_t next(int32_t n) = 0;
 
+   /**
+     * For RuleBasedBreakIterators, return the status tag from the 
+     * break rule that determined the most recently
+     * returned break position.
+     * <p>
+     * For break iterator types that do not support a rule status,
+     * a default value of 0 is returned.
+     * <p>
+     * @return the status from the break rule that determined the most recently
+     *         returned break position.
+     * @see RuleBaseBreakIterator::getRuleStatus()
+     * @see UWordBreak
+     * @draft ICU 52
+     */
+    virtual int32_t getRuleStatus() const;
+
+   /**
+    * For RuleBasedBreakIterators, get the status (tag) values from the break rule(s) 
+    * that determined the most recently returned break position.
+    * <p>
+    * For break iterator types that do not support rule status,
+    * no values are returned.
+    * <p>
+    * The returned status value(s) are stored into an array provided by the caller.
+    * The values are stored in sorted (ascending) order.
+    * If the capacity of the output array is insufficient to hold the data,
+    *  the output will be truncated to the available length, and a
+    *  U_BUFFER_OVERFLOW_ERROR will be signaled.
+    * <p>
+    * @see RuleBaseBreakIterator::getRuleStatusVec
+    *
+    * @param fillInVec an array to be filled in with the status values.
+    * @param capacity  the length of the supplied vector.  A length of zero causes
+    *                  the function to return the number of status values, in the
+    *                  normal way, without attemtping to store any values.
+    * @param status    receives error codes.
+    * @return          The number of rule status values from rules that determined
+    *                  the most recent boundary returned by the break iterator.
+    *                  In the event of a U_BUFFER_OVERFLOW_ERROR, the return value
+    *                  is the total number of status values that were available,
+    *                  not the reduced number that were actually returned.
+    * @see getRuleStatus
+    * @draft ICU 52
+    */
+    virtual int32_t getRuleStatusVec(int32_t *fillInVec, int32_t capacity, UErrorCode &status);
+
     /**
      * Create BreakIterator for word-breaks using the given locale.
      * Returns an instance of a BreakIterator implementing word breaks.
index b61f060cd99b056d3891b70f9050fd9bea00a778..4930a645a2b649fcf618b17d1e04eae9e36bf569 100644 (file)
@@ -1,5 +1,5 @@
 /********************************************************************
- * Copyright (c) 1999-2012, International Business Machines
+ * Copyright (c) 1999-2013, International Business Machines
  * Corporation and others. All Rights Reserved.
  ********************************************************************
  *   Date        Name        Description
@@ -658,7 +658,7 @@ void RBBIAPITest::TestRuleStatus() {
 
      UErrorCode status=U_ZERO_ERROR;
 
-     RuleBasedBreakIterator *bi = (RuleBasedBreakIterator *)BreakIterator::createWordInstance(Locale::getEnglish(), status);
+     BreakIterator *bi = BreakIterator::createWordInstance(Locale::getEnglish(), status);
      if(U_FAILURE(status)) {
          errcheckln(status, "Fail : in construction - %s", u_errorName(status));
      } else {
@@ -695,8 +695,7 @@ void RBBIAPITest::TestRuleStatus() {
      testString1 =   "test line. \n";
      // break type    s    s     h
 
-     bi = (RuleBasedBreakIterator *)
-         BreakIterator::createLineInstance(Locale::getEnglish(), status);
+     bi = BreakIterator::createLineInstance(Locale::getEnglish(), status);
      if(U_FAILURE(status)) {
          errcheckln(status, "failed to create word break iterator. - %s", u_errorName(status));
      } else {
@@ -1219,7 +1218,7 @@ void RBBIAPITest::runIndexedTest( int32_t index, UBool exec, const char* &name,
 //Internal subroutines
 //---------------------------------------------
 
-void RBBIAPITest::doBoundaryTest(RuleBasedBreakIterator& bi, UnicodeString& text, int32_t *boundaries){
+void RBBIAPITest::doBoundaryTest(BreakIterator& bi, UnicodeString& text, int32_t *boundaries){
      logln((UnicodeString)"testIsBoundary():");
         int32_t p = 0;
         UBool isB;
index e31b1da190348e5a32a1652b675d4eebfb411ffa..2805c887a60ba99811d82c1b40d90d4d3dfdcdba 100644 (file)
@@ -1,6 +1,6 @@
 /********************************************************************
  * COPYRIGHT: 
- * Copyright (c) 1999-2011 International Business Machines Corporation and
+ * Copyright (c) 1999-2013 International Business Machines Corporation and
  * others. All Rights Reserved.
  ********************************************************************/
 /************************************************************************
@@ -92,7 +92,7 @@ public:
      *Internal subroutines
      **/
     /* Internal subroutine used by TestIsBoundary() */ 
-    void doBoundaryTest(RuleBasedBreakIterator& bi, UnicodeString& text, int32_t *boundaries);
+    void doBoundaryTest(BreakIterator& bi, UnicodeString& text, int32_t *boundaries);
 
     /*Internal subroutine used for comparision of expected and acquired results */
     void doTest(UnicodeString& testString, int32_t start, int32_t gotoffset, int32_t expectedOffset, const char* expected);
index 00cc6d0f0485d8d935880e405ac0f03dd12e5d04..1007422ea4a76994df259b206b428dc7ca454280 100644 (file)
@@ -329,7 +329,7 @@ void RBBITest::TestStatusReturn() {
      UErrorCode status=U_ZERO_ERROR;
      UParseError    parseError;
 
-     RuleBasedBreakIterator *bi = new RuleBasedBreakIterator(rulesString1, parseError, status);
+     BreakIterator *bi = new RuleBasedBreakIterator(rulesString1, parseError, status);
      if(U_FAILURE(status)) {
          dataerrln("FAIL : in construction - %s", u_errorName(status));
      } else {
@@ -408,8 +408,7 @@ void RBBITest::TestBug3818() {
                                            0x0E43,0x0E2B,0x0E0D,0x0E48, 0x0E43,0x0E2B,0x0E0D,0x0E48, 0 };
     UnicodeString  thaiStr(thaiWordData);
 
-    RuleBasedBreakIterator* bi =
-        (RuleBasedBreakIterator *)BreakIterator::createWordInstance(Locale("th"), status);
+    BreakIterator* bi = BreakIterator::createWordInstance(Locale("th"), status);
     if (U_FAILURE(status) || bi == NULL) {
         errcheckln(status, "Fail at file %s, line %d, status = %s", __FILE__, __LINE__, u_errorName(status));
         return;