From 7f5016dd784324dc5574a3d4f2755f81a1daaac9 Mon Sep 17 00:00:00 2001 From: John Emmons Date: Sat, 14 Jun 2008 02:38:08 +0000 Subject: [PATCH] ICU-5219 Dutch IJ Titlecasing X-SVN-Rev: 24181 --- .../icu/dev/test/lang/UCharacterCaseTest.java | 20 ++++++++++++++ icu4j/src/com/ibm/icu/lang/UCharacter.java | 26 ++++++++++++++----- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/icu4j/src/com/ibm/icu/dev/test/lang/UCharacterCaseTest.java b/icu4j/src/com/ibm/icu/dev/test/lang/UCharacterCaseTest.java index 120062b4ac6..c5d6224278c 100644 --- a/icu4j/src/com/ibm/icu/dev/test/lang/UCharacterCaseTest.java +++ b/icu4j/src/com/ibm/icu/dev/test/lang/UCharacterCaseTest.java @@ -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 ++) { diff --git a/icu4j/src/com/ibm/icu/lang/UCharacter.java b/icu4j/src/com/ibm/icu/lang/UCharacter.java index c0931860002..39be6425d2d 100644 --- a/icu4j/src/com/ibm/icu/lang/UCharacter.java +++ b/icu4j/src/com/ibm/icu/lang/UCharacter.java @@ -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=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; }