ICU-5219 Dutch IJ Titlecasing

X-SVN-Rev: 24181
This commit is contained in:
John Emmons 2008-06-14 02:38:08 +00:00
parent 924a38a76e
commit 7f5016dd78
2 changed files with 40 additions and 6 deletions

View file

@ -351,6 +351,26 @@ public final class UCharacterCaseTest extends TestFmwk
}
}
public void TestDutchTitle() {
ULocale LOC_DUTCH = new ULocale("nl");
int options = 0;
options |= UCharacter.TITLECASE_NO_LOWERCASE;
BreakIterator iter = BreakIterator.getWordInstance(LOC_DUTCH);
assertEquals("Dutch titlecase check in English",
"Ijssel Igloo Ijmuiden",
UCharacter.toTitleCase(ULocale.ENGLISH, "ijssel igloo IJMUIDEN", null));
assertEquals("Dutch titlecase check in Dutch",
"IJssel Igloo IJmuiden",
UCharacter.toTitleCase(LOC_DUTCH, "ijssel igloo IJMUIDEN", null));
iter.setText("ijssel igloo IjMUIdEN iPoD ijenough");
assertEquals("Dutch titlecase check in Dutch with nolowercase option",
"IJssel Igloo IJMUIdEN IPoD IJenough",
UCharacter.toTitleCase(LOC_DUTCH, "ijssel igloo IjMUIdEN iPoD ijenough", iter, options));
}
public void TestSpecial()
{
for (int i = 0; i < SPECIAL_LOCALES_.length; i ++) {

View file

@ -4686,7 +4686,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
StringContextIterator iter = new StringContextIterator(str);
StringBuffer result = new StringBuffer(str.length());
int[] locCache = new int[1];
int c, srcLength = str.length();
int c, nc, srcLength = str.length();
if (locale == null) {
locale = ULocale.getDefault();
@ -4700,6 +4700,8 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
int prev, titleStart, index;
boolean isFirstIndex;
boolean isDutch = locale.getLanguage().equals("nl");
boolean FirstIJ = true;
/* set up local variables */
prev=0;
@ -4747,6 +4749,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
}
if(titleStart<index) {
FirstIJ = true;
/* titlecase c which is from titleStart */
c=gCsp.toFullTitle(c, iter, result, locale, locCache);
@ -4773,16 +4776,27 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
if((options&TITLECASE_NO_LOWERCASE)!=0) {
/* Optionally just copy the rest of the word unchanged. */
int titleLimit=iter.getCPLimit();
if(titleLimit<index) {
// TODO: With Java 5, this would want to be result.append(str, titleLimit, index);
result.append(str.substring(titleLimit, index));
// TODO: With Java 5, this would want to be result.append(str, titleLimit, index);
String appendStr = str.substring(titleLimit,index);
/* Special Case - Dutch IJ Titlecasing */
if ( isDutch && c == 0x0049 && appendStr.startsWith("j")) {
appendStr = "J" + appendStr.substring(1);
}
result.append(appendStr);
iter.moveToLimit();
break;
}
} else if((c=iter.nextCaseMapCP())>=0) {
/* Normal operation: Lowercase the rest of the word. */
c=gCsp.toFullLower(c, iter, result, locale, locCache);
} else if((nc=iter.nextCaseMapCP())>=0) {
if ( isDutch && ( nc == 0x004A || nc == 0x006A ) && ( c == 0x0049 ) && ( FirstIJ == true )) {
c = 0x004A; /* J */
FirstIJ = false;
} else {
/* Normal operation: Lowercase the rest of the word. */
c=gCsp.toFullLower(nc, iter, result, locale, locCache);
}
} else {
break;
}