]> granicus.if.org Git - icu/commitdiff
ICU-12410 bug fixes
authorMarkus Scherer <markus.icu@gmail.com>
Thu, 9 Feb 2017 23:09:08 +0000 (23:09 +0000)
committerMarkus Scherer <markus.icu@gmail.com>
Thu, 9 Feb 2017 23:09:08 +0000 (23:09 +0000)
X-SVN-Rev: 39657

icu4c/source/common/ustrcase.cpp
icu4j/main/classes/core/src/com/ibm/icu/impl/CaseMapImpl.java
icu4j/main/classes/core/src/com/ibm/icu/lang/UCharacter.java

index 31522047870a147a90a96bae84e30bc42c7f9734..6661bdc497a85cda360910f6cb616923230a2af5 100644 (file)
@@ -322,17 +322,27 @@ ustrcase_internalToTitle(int32_t caseLocale, uint32_t options, BreakIterator *it
                 /* Special case Dutch IJ titlecasing */
                 if (titleStart+1 < index &&
                         caseLocale == UCASE_LOC_DUTCH &&
-                        (src[titleStart] == 0x0049 || src[titleStart] == 0x0069) &&
-                        src[titleStart+1] == 0x006A) {
-                    destIndex=appendUChar(dest, destIndex, destCapacity, 0x004A);
-                    if(destIndex<0) {
-                        errorCode=U_INDEX_OUTOFBOUNDS_ERROR;
-                        return 0;
-                    }
-                    if(edits!=NULL) {
-                        edits->addReplace(1, 1);
+                        (src[titleStart] == 0x0049 || src[titleStart] == 0x0069)) {
+                    if (src[titleStart+1] == 0x006A) {
+                        destIndex=appendUChar(dest, destIndex, destCapacity, 0x004A);
+                        if(destIndex<0) {
+                            errorCode=U_INDEX_OUTOFBOUNDS_ERROR;
+                            return 0;
+                        }
+                        if(edits!=NULL) {
+                            edits->addReplace(1, 1);
+                        }
+                        titleLimit++;
+                    } else if (src[titleStart+1] == 0x004A) {
+                        // Keep the capital J from getting lowercased.
+                        destIndex=appendUnchanged(dest, destIndex, destCapacity,
+                                                  src+titleStart+1, 1, options, edits);
+                        if(destIndex<0) {
+                            errorCode=U_INDEX_OUTOFBOUNDS_ERROR;
+                            return 0;
+                        }
+                        titleLimit++;
                     }
-                    titleLimit++;
                 }
 
                 /* lowercase [titleLimit..index[ */
index c8cfadb5bafcc0604a92aa13e9de595717362a8e..f28e60ed5eaa358434124237189ec49a34a9877e 100644 (file)
@@ -303,16 +303,25 @@ public final class CaseMapImpl {
                         // Special case Dutch IJ titlecasing
                         if (titleStart+1 < index && caseLocale == UCaseProps.LOC_DUTCH) {
                             char c1 = src.charAt(titleStart);
-                            char c2 = src.charAt(titleStart+1);
-                            if ((c1 == 'i' || c1 == 'I') && c2 == 'j') {
-                                dest.append('J');
-                                if (edits != null) {
-                                    edits.addReplace(1, 1);
+                            if ((c1 == 'i' || c1 == 'I')) {
+                                char c2 = src.charAt(titleStart+1);
+                                if (c2 == 'j') {
+                                    dest.append('J');
+                                    if (edits != null) {
+                                        edits.addReplace(1, 1);
+                                    }
+                                    c = iter.nextCaseMapCP();
+                                    titleLimit++;
+                                    assert c == c2;
+                                    assert titleLimit == iter.getCPLimit();
+                                } else if (c2 == 'J') {
+                                    // Keep the capital J from getting lowercased.
+                                    appendUnchanged(src, titleStart + 1, 1, dest, options, edits);
+                                    c = iter.nextCaseMapCP();
+                                    titleLimit++;
+                                    assert c == c2;
+                                    assert titleLimit == iter.getCPLimit();
                                 }
-                                c=iter.nextCaseMapCP();
-                                titleLimit++;
-                                assert c == c2;
-                                assert titleLimit == iter.getCPLimit();
                             }
                         }
 
index 7b2af3061c8e44f41ad687675103552de0aea2f9..65cebb36a92a16cdb769583201a183bc5421c568 100644 (file)
@@ -4974,11 +4974,11 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
             // Good if no or few changes. Bad (slow) if many changes.
             Edits edits = new Edits();
             StringBuilder replacementChars = CaseMapImpl.toTitle(
-                    caseLocale, CaseMapImpl.OMIT_UNCHANGED_TEXT, titleIter, str,
+                    caseLocale, options | CaseMapImpl.OMIT_UNCHANGED_TEXT, titleIter, str,
                     new StringBuilder(), edits);
             return applyEdits(str, replacementChars, edits);
         } else {
-            return CaseMapImpl.toTitle(caseLocale, 0, titleIter, str,
+            return CaseMapImpl.toTitle(caseLocale, options, titleIter, str,
                     new StringBuilder(str.length()), null).toString();
         }
     }
@@ -5124,6 +5124,9 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
     public static String toTitleCase(ULocale locale, String str,
             BreakIterator titleIter, int options) {
         if(titleIter == null) {
+            if (locale == null) {
+                locale = ULocale.getDefault();
+            }
             titleIter = BreakIterator.getWordInstance(locale);
         }
         titleIter.setText(str);
@@ -5359,10 +5362,10 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
             // Good if no or few changes. Bad (slow) if many changes.
             Edits edits = new Edits();
             StringBuilder replacementChars = CaseMapImpl.fold(
-                    CaseMapImpl.OMIT_UNCHANGED_TEXT, str, new StringBuilder(), edits);
+                    options | CaseMapImpl.OMIT_UNCHANGED_TEXT, str, new StringBuilder(), edits);
             return applyEdits(str, replacementChars, edits);
         } else {
-            return CaseMapImpl.fold(0, str, new StringBuilder(str.length()), null).toString();
+            return CaseMapImpl.fold(options, str, new StringBuilder(str.length()), null).toString();
         }
     }