/* 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[ */
// 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();
}
}
// 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();
}
}
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);
// 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();
}
}