]> granicus.if.org Git - icu/commitdiff
ICU-13337 public string option for not resetting an Edits object: U_EDITS_NO_RESET
authorMarkus Scherer <markus.icu@gmail.com>
Wed, 13 Sep 2017 16:15:28 +0000 (16:15 +0000)
committerMarkus Scherer <markus.icu@gmail.com>
Wed, 13 Sep 2017 16:15:28 +0000 (16:15 +0000)
X-SVN-Rev: 40394

icu4c/source/common/filterednormalizer2.cpp
icu4c/source/common/norm2allmodes.h
icu4c/source/common/normalizer2.cpp
icu4c/source/common/ucasemap.cpp
icu4c/source/common/unicode/casemap.h
icu4c/source/common/unicode/normalizer2.h
icu4c/source/common/unicode/stringoptions.h
icu4c/source/common/ustr_imp.h
icu4c/source/common/ustrcase.cpp
icu4c/source/test/intltest/strcase.cpp

index f627b601ce070638aa7eaa816ff254e8065965fa..1a0914d3f7b34c625472c3d5ba4f322efa3d723a 100644 (file)
 
 #include "unicode/edits.h"
 #include "unicode/normalizer2.h"
+#include "unicode/stringoptions.h"
 #include "unicode/uniset.h"
 #include "unicode/unistr.h"
 #include "unicode/unorm.h"
 #include "cpputils.h"
-#include "ustr_imp.h"  // U_EDITS_NO_RESET
 
 U_NAMESPACE_BEGIN
 
index 3305f05f64f1905a155397b5e3c01a43af9caab2..96b0ebe0828a5e6976f5c99d04141c98a11c89bd 100644 (file)
 
 #include "unicode/edits.h"
 #include "unicode/normalizer2.h"
+#include "unicode/stringoptions.h"
 #include "unicode/unistr.h"
 #include "cpputils.h"
 #include "normalizer2impl.h"
-#include "ustr_imp.h"  // U_EDITS_NO_RESET
 
 U_NAMESPACE_BEGIN
 
index 8915c1ddc31d543ccb4ce6bf4ae2fcc78853fc58..ef0f7d56b03fc245107182a1c3ece4468512c024 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "unicode/edits.h"
 #include "unicode/normalizer2.h"
+#include "unicode/stringoptions.h"
 #include "unicode/unistr.h"
 #include "unicode/unorm.h"
 #include "cstring.h"
@@ -30,7 +31,6 @@
 #include "normalizer2impl.h"
 #include "uassert.h"
 #include "ucln_cmn.h"
-#include "ustr_imp.h"  // U_EDITS_NO_RESET
 
 using icu::Normalizer2Impl;
 
index 57bf3a52a4edd2171a4e3961e84560a70f239bd0..6e550aadcd8d01e84287c0249c853325102c449f 100644 (file)
@@ -22,6 +22,7 @@
 #include "unicode/brkiter.h"
 #include "unicode/casemap.h"
 #include "unicode/edits.h"
+#include "unicode/stringoptions.h"
 #include "unicode/ubrk.h"
 #include "unicode/uloc.h"
 #include "unicode/ustring.h"
index 581f1ab532ae6a628787f856cfa80b2337640572..6a29a4266056c3ae7ae5600f6041ead35443b8f4 100644 (file)
@@ -36,7 +36,7 @@ public:
      * The source string and the destination buffer must not overlap.
      *
      * @param locale    The locale ID. ("" = root locale, NULL = default locale.)
-     * @param options   Options bit set, usually 0. See U_OMIT_UNCHANGED_TEXT.
+     * @param options   Options bit set, usually 0. See U_OMIT_UNCHANGED_TEXT and U_EDITS_NO_RESET.
      * @param src       The original string.
      * @param srcLength The length of the original string. If -1, then src must be NUL-terminated.
      * @param dest      A buffer for the result string. The result will be NUL-terminated if
@@ -48,7 +48,8 @@ public:
      * @param edits     Records edits for index mapping, working with styled text,
      *                  and getting only changes (if any).
      *                  The Edits contents is undefined if any error occurs.
-     *                  This function calls edits->reset() first. edits can be NULL.
+     *                  This function calls edits->reset() first unless
+     *                  options includes U_EDITS_NO_RESET. edits can be NULL.
      * @param errorCode Reference to an in/out error code value
      *                  which must not indicate a failure before the function call.
      * @return The length of the result string, if successful.
@@ -71,7 +72,7 @@ public:
      * The source string and the destination buffer must not overlap.
      *
      * @param locale    The locale ID. ("" = root locale, NULL = default locale.)
-     * @param options   Options bit set, usually 0. See U_OMIT_UNCHANGED_TEXT.
+     * @param options   Options bit set, usually 0. See U_OMIT_UNCHANGED_TEXT and U_EDITS_NO_RESET.
      * @param src       The original string.
      * @param srcLength The length of the original string. If -1, then src must be NUL-terminated.
      * @param dest      A buffer for the result string. The result will be NUL-terminated if
@@ -83,7 +84,8 @@ public:
      * @param edits     Records edits for index mapping, working with styled text,
      *                  and getting only changes (if any).
      *                  The Edits contents is undefined if any error occurs.
-     *                  This function calls edits->reset() first. edits can be NULL.
+     *                  This function calls edits->reset() first unless
+     *                  options includes U_EDITS_NO_RESET. edits can be NULL.
      * @param errorCode Reference to an in/out error code value
      *                  which must not indicate a failure before the function call.
      * @return The length of the result string, if successful.
@@ -112,7 +114,7 @@ public:
      * all others. (This can be modified with options bits.)
      *
      * @param locale    The locale ID. ("" = root locale, NULL = default locale.)
-     * @param options   Options bit set, usually 0. See U_OMIT_UNCHANGED_TEXT,
+     * @param options   Options bit set, usually 0. See U_OMIT_UNCHANGED_TEXT, U_EDITS_NO_RESET,
      *                  U_TITLECASE_NO_LOWERCASE,
      *                  U_TITLECASE_NO_BREAK_ADJUSTMENT, U_TITLECASE_ADJUST_TO_CASED,
      *                  U_TITLECASE_WHOLE_STRING, U_TITLECASE_SENTENCES.
@@ -132,7 +134,8 @@ public:
      * @param edits     Records edits for index mapping, working with styled text,
      *                  and getting only changes (if any).
      *                  The Edits contents is undefined if any error occurs.
-     *                  This function calls edits->reset() first. edits can be NULL.
+     *                  This function calls edits->reset() first unless
+     *                  options includes U_EDITS_NO_RESET. edits can be NULL.
      * @param errorCode Reference to an in/out error code value
      *                  which must not indicate a failure before the function call.
      * @return The length of the result string, if successful.
@@ -161,7 +164,7 @@ public:
      * The result may be longer or shorter than the original.
      * The source string and the destination buffer must not overlap.
      *
-     * @param options   Options bit set, usually 0. See U_OMIT_UNCHANGED_TEXT,
+     * @param options   Options bit set, usually 0. See U_OMIT_UNCHANGED_TEXT, U_EDITS_NO_RESET,
      *                  U_FOLD_CASE_DEFAULT, U_FOLD_CASE_EXCLUDE_SPECIAL_I.
      * @param src       The original string.
      * @param srcLength The length of the original string. If -1, then src must be NUL-terminated.
@@ -174,7 +177,8 @@ public:
      * @param edits     Records edits for index mapping, working with styled text,
      *                  and getting only changes (if any).
      *                  The Edits contents is undefined if any error occurs.
-     *                  This function calls edits->reset() first. edits can be NULL.
+     *                  This function calls edits->reset() first unless
+     *                  options includes U_EDITS_NO_RESET. edits can be NULL.
      * @param errorCode Reference to an in/out error code value
      *                  which must not indicate a failure before the function call.
      * @return The length of the result string, if successful.
@@ -197,7 +201,7 @@ public:
      * The source string and the destination buffer must not overlap.
      *
      * @param locale    The locale ID. ("" = root locale, NULL = default locale.)
-     * @param options   Options bit set, usually 0. See U_OMIT_UNCHANGED_TEXT.
+     * @param options   Options bit set, usually 0. See U_OMIT_UNCHANGED_TEXT and U_EDITS_NO_RESET.
      * @param src       The original string.
      * @param srcLength The length of the original string. If -1, then src must be NUL-terminated.
      * @param dest      A buffer for the result string. The result will be NUL-terminated if
@@ -209,7 +213,8 @@ public:
      * @param edits     Records edits for index mapping, working with styled text,
      *                  and getting only changes (if any).
      *                  The Edits contents is undefined if any error occurs.
-     *                  This function calls edits->reset() first. edits can be NULL.
+     *                  This function calls edits->reset() first unless
+     *                  options includes U_EDITS_NO_RESET. edits can be NULL.
      * @param errorCode Reference to an in/out error code value
      *                  which must not indicate a failure before the function call.
      * @return The length of the result string, if successful.
@@ -232,7 +237,7 @@ public:
      * The source string and the destination buffer must not overlap.
      *
      * @param locale    The locale ID. ("" = root locale, NULL = default locale.)
-     * @param options   Options bit set, usually 0. See U_OMIT_UNCHANGED_TEXT.
+     * @param options   Options bit set, usually 0. See U_OMIT_UNCHANGED_TEXT and U_EDITS_NO_RESET.
      * @param src       The original string.
      * @param srcLength The length of the original string. If -1, then src must be NUL-terminated.
      * @param dest      A buffer for the result string. The result will be NUL-terminated if
@@ -244,7 +249,8 @@ public:
      * @param edits     Records edits for index mapping, working with styled text,
      *                  and getting only changes (if any).
      *                  The Edits contents is undefined if any error occurs.
-     *                  This function calls edits->reset() first. edits can be NULL.
+     *                  This function calls edits->reset() first unless
+     *                  options includes U_EDITS_NO_RESET. edits can be NULL.
      * @param errorCode Reference to an in/out error code value
      *                  which must not indicate a failure before the function call.
      * @return The length of the result string, if successful.
@@ -273,7 +279,7 @@ public:
      * all others. (This can be modified with options bits.)
      *
      * @param locale    The locale ID. ("" = root locale, NULL = default locale.)
-     * @param options   Options bit set, usually 0. See U_OMIT_UNCHANGED_TEXT,
+     * @param options   Options bit set, usually 0. See U_OMIT_UNCHANGED_TEXT, U_EDITS_NO_RESET,
      *                  U_TITLECASE_NO_LOWERCASE,
      *                  U_TITLECASE_NO_BREAK_ADJUSTMENT, U_TITLECASE_ADJUST_TO_CASED,
      *                  U_TITLECASE_WHOLE_STRING, U_TITLECASE_SENTENCES.
@@ -293,7 +299,8 @@ public:
      * @param edits     Records edits for index mapping, working with styled text,
      *                  and getting only changes (if any).
      *                  The Edits contents is undefined if any error occurs.
-     *                  This function calls edits->reset() first. edits can be NULL.
+     *                  This function calls edits->reset() first unless
+     *                  options includes U_EDITS_NO_RESET. edits can be NULL.
      * @param errorCode Reference to an in/out error code value
      *                  which must not indicate a failure before the function call.
      * @return The length of the result string, if successful.
@@ -321,7 +328,7 @@ public:
      * The result may be longer or shorter than the original.
      * The source string and the destination buffer must not overlap.
      *
-     * @param options   Options bit set, usually 0. See U_OMIT_UNCHANGED_TEXT,
+     * @param options   Options bit set, usually 0. See U_OMIT_UNCHANGED_TEXT, U_EDITS_NO_RESET,
      *                  U_FOLD_CASE_DEFAULT, U_FOLD_CASE_EXCLUDE_SPECIAL_I.
      * @param src       The original string.
      * @param srcLength The length of the original string. If -1, then src must be NUL-terminated.
@@ -334,7 +341,8 @@ public:
      * @param edits     Records edits for index mapping, working with styled text,
      *                  and getting only changes (if any).
      *                  The Edits contents is undefined if any error occurs.
-     *                  This function calls edits->reset() first. edits can be NULL.
+     *                  This function calls edits->reset() first unless
+     *                  options includes U_EDITS_NO_RESET. edits can be NULL.
      * @param errorCode Reference to an in/out error code value
      *                  which must not indicate a failure before the function call.
      * @return The length of the result string, if successful.
index 631e29bafef18390b3726c6495d5fd7bce131e40..97337c5300e3ddf46506938fad0e4caaca5b6b83 100644 (file)
@@ -228,14 +228,15 @@ public:
      * (UNORM2_COMPOSE and UNORM2_COMPOSE_CONTIGUOUS).
      * Otherwise currently converts to & from UTF-16 and does not support edits.
      *
-     * @param options   Options bit set, usually 0. See U_OMIT_UNCHANGED_TEXT.
+     * @param options   Options bit set, usually 0. See U_OMIT_UNCHANGED_TEXT and U_EDITS_NO_RESET.
      * @param src       Source UTF-8 string.
      * @param sink      A ByteSink to which the normalized UTF-8 result string is written.
      *                  sink.Flush() is called at the end.
      * @param edits     Records edits for index mapping, working with styled text,
      *                  and getting only changes (if any).
      *                  The Edits contents is undefined if any error occurs.
-     *                  This function calls edits->reset() first. edits can be nullptr.
+     *                  This function calls edits->reset() first unless
+     *                  options includes U_EDITS_NO_RESET. edits can be nullptr.
      * @param errorCode Standard ICU error code. Its input value must
      *                  pass the U_SUCCESS() test, or else the function returns
      *                  immediately. Check for U_FAILURE() on output or use with
@@ -545,14 +546,15 @@ public:
      * (UNORM2_COMPOSE and UNORM2_COMPOSE_CONTIGUOUS).
      * Otherwise currently converts to & from UTF-16 and does not support edits.
      *
-     * @param options   Options bit set, usually 0. See U_OMIT_UNCHANGED_TEXT.
+     * @param options   Options bit set, usually 0. See U_OMIT_UNCHANGED_TEXT and U_EDITS_NO_RESET.
      * @param src       Source UTF-8 string.
      * @param sink      A ByteSink to which the normalized UTF-8 result string is written.
      *                  sink.Flush() is called at the end.
      * @param edits     Records edits for index mapping, working with styled text,
      *                  and getting only changes (if any).
      *                  The Edits contents is undefined if any error occurs.
-     *                  This function calls edits->reset() first. edits can be nullptr.
+     *                  This function calls edits->reset() first unless
+     *                  options includes U_EDITS_NO_RESET. edits can be nullptr.
      * @param errorCode Standard ICU error code. Its input value must
      *                  pass the U_SUCCESS() test, or else the function returns
      *                  immediately. Check for U_FAILURE() on output or use with
index d8b29fd40d84520ea0c99f431331ea2bc427182e..f2de96e9634a02e355eb13ea79f08d758a2e3bdd 100644 (file)
  */
 #define U_TITLECASE_ADJUST_TO_CASED 0x400
 
+/**
+ * Option for string transformation functions to not first reset the Edits object.
+ * Used for example in some case-mapping and normalization functions.
+ *
+ * @see CaseMap
+ * @see Edits
+ * @see Normalizer2
+ * @draft ICU 60
+ */
+#define U_EDITS_NO_RESET 0x2000
+
 /**
  * Omit unchanged text when recording how source substrings
  * relate to changed and unchanged result substrings.
 // ucasemap_imp.h #define U_TITLECASE_ITERATOR_MASK 0xe0
 // ucasemap_imp.h #define U_TITLECASE_ADJUSTMENT_MASK 0x600
 // ustr_imp.h #define _STRNCMP_STYLE 0x1000
-// ustr_imp.h #define U_EDITS_NO_RESET 0x2000
 // unormcmp.cpp #define _COMPARE_EQUIV 0x80000
 
 #endif  // __STRINGOPTIONS_H__
index 3c2d8574f8de5a3aba9be3ac03f113104168be38..9815915ff5294589f6845dd8e0f3134c317b6cf1 100644 (file)
  */
 #define _STRNCMP_STYLE 0x1000
 
-/**
- * Internal option for string transformation functions to not first reset the Edits object.
- */
-#define U_EDITS_NO_RESET 0x2000
-
 /**
  * Compare two strings in code point order or code unit order.
  * Works in strcmp style (both lengths -1),
index bd910cf0dc5b616de2459b095d762d1511472f30..a96c57cef2e2074ca41c926501bb2aa09d961f9d 100644 (file)
@@ -24,6 +24,7 @@
 #include "unicode/brkiter.h"
 #include "unicode/casemap.h"
 #include "unicode/edits.h"
+#include "unicode/stringoptions.h"
 #include "unicode/ustring.h"
 #include "unicode/ucasemap.h"
 #include "unicode/ubrk.h"
index 854f4ec9140fb79ca3eadea3e7db1b1c7cf2321a..3551305246191d0540562d95220ce66132978f4b 100644 (file)
@@ -1272,18 +1272,23 @@ void StringCaseTest::TestCaseMapWithEdits() {
             TRUE, errorCode);
 #endif
 
-    edits.reset();
-    length = CaseMap::fold(U_OMIT_UNCHANGED_TEXT | U_FOLD_CASE_EXCLUDE_SPECIAL_I,
+    // No explicit nor automatic edits.reset(). Edits should be appended.
+    length = CaseMap::fold(U_OMIT_UNCHANGED_TEXT | U_EDITS_NO_RESET | U_FOLD_CASE_EXCLUDE_SPECIAL_I,
                            u"IßtanBul", 8, dest, UPRV_LENGTHOF(dest), &edits, errorCode);
     assertEquals(u"foldCase(IßtanBul)", UnicodeString(u"ıssb"), UnicodeString(TRUE, dest, length));
     static const EditChange foldExpectedChanges[] = {
+            // From titlecasing.
+            { FALSE, 1, 1 },
+            { TRUE, 1, 1 },
+            { FALSE, 10, 10 },
+            // From case folding.
             { TRUE, 1, 1 },
             { TRUE, 1, 2 },
             { FALSE, 3, 3 },
             { TRUE, 1, 1 },
             { FALSE, 2, 2 }
     };
-    TestUtility::checkEditsIter(*this, u"foldCase(IßtanBul)",
+    TestUtility::checkEditsIter(*this, u"foldCase(no Edits reset, IßtanBul)",
             edits.getFineIterator(), edits.getFineIterator(),
             foldExpectedChanges, UPRV_LENGTHOF(foldExpectedChanges),
             TRUE, errorCode);
@@ -1348,12 +1353,18 @@ void StringCaseTest::TestCaseMapUTF8WithEdits() {
             TRUE, errorCode);
 #endif
 
-    edits.reset();
-    length = CaseMap::utf8Fold(U_OMIT_UNCHANGED_TEXT | U_FOLD_CASE_EXCLUDE_SPECIAL_I,
+    // No explicit nor automatic edits.reset(). Edits should be appended.
+    length = CaseMap::utf8Fold(U_OMIT_UNCHANGED_TEXT | U_EDITS_NO_RESET |
+                                   U_FOLD_CASE_EXCLUDE_SPECIAL_I,
                                u8"IßtanBul", 1 + 2 + 6, dest, UPRV_LENGTHOF(dest), &edits, errorCode);
     assertEquals(u"foldCase(IßtanBul)", UnicodeString(u"ıssb"),
                  UnicodeString::fromUTF8(StringPiece(dest, length)));
     static const EditChange foldExpectedChanges[] = {
+            // From titlecasing.
+            { FALSE, 1, 1 },
+            { TRUE, 1, 1 },
+            { FALSE, 10, 10 },
+            // From case folding.
             { TRUE, 1, 2 },
             { TRUE, 2, 2 },
             { FALSE, 3, 3 },