diff --git a/icu4j/src/com/ibm/icu/dev/test/util/TestAll.java b/icu4j/src/com/ibm/icu/dev/test/util/TestAll.java index 4c0d6c30bb5..f66f2260297 100644 --- a/icu4j/src/com/ibm/icu/dev/test/util/TestAll.java +++ b/icu4j/src/com/ibm/icu/dev/test/util/TestAll.java @@ -5,8 +5,8 @@ ******************************************************************************* * * $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/util/TestAll.java,v $ - * $Date: 2003/02/05 05:50:05 $ - * $Revision: 1.1 $ + * $Date: 2003/05/09 03:31:49 $ + * $Revision: 1.2 $ * ******************************************************************************* */ @@ -30,6 +30,7 @@ public class TestAll extends TestGroup { "CompactArrayTest", "StringTokenizerTest", "CurrencyTest", + "UtilityTest" }, "Test miscellaneous public utilities"); } diff --git a/icu4j/src/com/ibm/icu/dev/test/util/UtilityTest.java b/icu4j/src/com/ibm/icu/dev/test/util/UtilityTest.java new file mode 100644 index 00000000000..1dea55ad417 --- /dev/null +++ b/icu4j/src/com/ibm/icu/dev/test/util/UtilityTest.java @@ -0,0 +1,37 @@ +/* +********************************************************************** +* Copyright (c) 2003, International Business Machines +* Corporation and others. All Rights Reserved. +********************************************************************** +* Author: Alan Liu +* Created: March 8 2003 +* Since: ICU 2.6 +********************************************************************** +*/ +package com.ibm.icu.dev.test.util; +import com.ibm.icu.dev.test.TestFmwk; +import com.ibm.icu.impl.Utility; + +/** + * @test + * @summary Test of internal Utility class + */ +public class UtilityTest extends TestFmwk { + + public static void main(String[] args) throws Exception { + new UtilityTest().run(args); + } + + public void TestUnescape() { + final String input = + "Sch\\u00f6nes Auto: \\u20ac 11240.\\fPrivates Zeichen: \\U00102345\\e\\cC\\n \\x1b\\x{263a}"; + + final String expect = + "Sch\u00F6nes Auto: \u20AC 11240.\u000CPrivates Zeichen: \uDBC8\uDF45\u001B\u0003\012 \u001B\u263A"; + + String result = Utility.unescape(input); + if (!result.equals(expect)) { + errln("FAIL: Utility.unescape() returned " + result + ", exp. " + expect); + } + } +} diff --git a/icu4j/src/com/ibm/icu/impl/Utility.java b/icu4j/src/com/ibm/icu/impl/Utility.java index 3d9b4b02c00..6c7d01c88db 100755 --- a/icu4j/src/com/ibm/icu/impl/Utility.java +++ b/icu4j/src/com/ibm/icu/impl/Utility.java @@ -5,8 +5,8 @@ ******************************************************************************* * * $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/impl/Utility.java,v $ - * $Date: 2003/02/11 00:49:09 $ - * $Revision: 1.37 $ + * $Date: 2003/05/09 03:31:49 $ + * $Revision: 1.38 $ * ***************************************************************************************** */ @@ -719,6 +719,7 @@ public final class Utility { int bitsPerDigit = 4; int dig; int i; + boolean braces = false; /* Check that offset is in range */ int offset = offset16[0]; @@ -741,7 +742,13 @@ public final class Utility { break; case 'x': minDig = 1; - maxDig = 2; + if (offset < length && UTF16.charAt(s, offset) == 0x7B /*{*/) { + ++offset; + braces = true; + maxDig = 8; + } else { + maxDig = 2; + } break; default: dig = UCharacter.digit(c, 8); @@ -756,25 +763,24 @@ public final class Utility { } if (minDig != 0) { while (offset < length && n < maxDig) { - // TEMPORARY - // TODO: Restore the char32-based code when UCharacter.digit - // is working (Bug 66). - - //c = UTF16.charAt(s, offset); - //dig = UCharacter.digit(c, (bitsPerDigit == 3) ? 8 : 16); - c = s.charAt(offset); - dig = Character.digit((char)c, (bitsPerDigit == 3) ? 8 : 16); + c = UTF16.charAt(s, offset); + dig = UCharacter.digit(c, (bitsPerDigit == 3) ? 8 : 16); if (dig < 0) { break; } result = (result << bitsPerDigit) | dig; - //offset += UTF16.getCharCount(c); - ++offset; + offset += UTF16.getCharCount(c); ++n; } if (n < minDig) { return -1; } + if (braces) { + if (c != 0x7D /*}*/) { + return -1; + } + ++offset; + } offset16[0] = offset; return result; }