ICU-2804 implement \x{...}
X-SVN-Rev: 11858
This commit is contained in:
parent
4e449ef99e
commit
239a55e4ce
@ -5,8 +5,8 @@
|
|||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*
|
*
|
||||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/util/TestAll.java,v $
|
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/util/TestAll.java,v $
|
||||||
* $Date: 2003/02/05 05:50:05 $
|
* $Date: 2003/05/09 03:31:49 $
|
||||||
* $Revision: 1.1 $
|
* $Revision: 1.2 $
|
||||||
*
|
*
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
@ -30,6 +30,7 @@ public class TestAll extends TestGroup {
|
|||||||
"CompactArrayTest",
|
"CompactArrayTest",
|
||||||
"StringTokenizerTest",
|
"StringTokenizerTest",
|
||||||
"CurrencyTest",
|
"CurrencyTest",
|
||||||
|
"UtilityTest"
|
||||||
},
|
},
|
||||||
"Test miscellaneous public utilities");
|
"Test miscellaneous public utilities");
|
||||||
}
|
}
|
||||||
|
37
icu4j/src/com/ibm/icu/dev/test/util/UtilityTest.java
Normal file
37
icu4j/src/com/ibm/icu/dev/test/util/UtilityTest.java
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -5,8 +5,8 @@
|
|||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*
|
*
|
||||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/impl/Utility.java,v $
|
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/impl/Utility.java,v $
|
||||||
* $Date: 2003/02/11 00:49:09 $
|
* $Date: 2003/05/09 03:31:49 $
|
||||||
* $Revision: 1.37 $
|
* $Revision: 1.38 $
|
||||||
*
|
*
|
||||||
*****************************************************************************************
|
*****************************************************************************************
|
||||||
*/
|
*/
|
||||||
@ -719,6 +719,7 @@ public final class Utility {
|
|||||||
int bitsPerDigit = 4;
|
int bitsPerDigit = 4;
|
||||||
int dig;
|
int dig;
|
||||||
int i;
|
int i;
|
||||||
|
boolean braces = false;
|
||||||
|
|
||||||
/* Check that offset is in range */
|
/* Check that offset is in range */
|
||||||
int offset = offset16[0];
|
int offset = offset16[0];
|
||||||
@ -741,7 +742,13 @@ public final class Utility {
|
|||||||
break;
|
break;
|
||||||
case 'x':
|
case 'x':
|
||||||
minDig = 1;
|
minDig = 1;
|
||||||
maxDig = 2;
|
if (offset < length && UTF16.charAt(s, offset) == 0x7B /*{*/) {
|
||||||
|
++offset;
|
||||||
|
braces = true;
|
||||||
|
maxDig = 8;
|
||||||
|
} else {
|
||||||
|
maxDig = 2;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
dig = UCharacter.digit(c, 8);
|
dig = UCharacter.digit(c, 8);
|
||||||
@ -756,25 +763,24 @@ public final class Utility {
|
|||||||
}
|
}
|
||||||
if (minDig != 0) {
|
if (minDig != 0) {
|
||||||
while (offset < length && n < maxDig) {
|
while (offset < length && n < maxDig) {
|
||||||
// TEMPORARY
|
c = UTF16.charAt(s, offset);
|
||||||
// TODO: Restore the char32-based code when UCharacter.digit
|
dig = UCharacter.digit(c, (bitsPerDigit == 3) ? 8 : 16);
|
||||||
// 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);
|
|
||||||
if (dig < 0) {
|
if (dig < 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
result = (result << bitsPerDigit) | dig;
|
result = (result << bitsPerDigit) | dig;
|
||||||
//offset += UTF16.getCharCount(c);
|
offset += UTF16.getCharCount(c);
|
||||||
++offset;
|
|
||||||
++n;
|
++n;
|
||||||
}
|
}
|
||||||
if (n < minDig) {
|
if (n < minDig) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
if (braces) {
|
||||||
|
if (c != 0x7D /*}*/) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
++offset;
|
||||||
|
}
|
||||||
offset16[0] = offset;
|
offset16[0] = offset;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user