ICU-2804 implement \x{...}

X-SVN-Rev: 11857
This commit is contained in:
Alan Liu 2003-05-09 00:22:25 +00:00
parent 58b5029f21
commit 4e449ef99e
3 changed files with 17 additions and 3 deletions

View file

@ -930,6 +930,7 @@ u_memrchr32(const UChar *s, UChar32 c, int32_t count);
* \uhhhh 4 hex digits; h in [0-9A-Fa-f]
* \Uhhhhhhhh 8 hex digits
* \xhh 1-2 hex digits
* \x{h...} 1-8 hex digits
* \ooo 1-3 octal digits; o in [0-7]
* \cX control-X; X is masked with 0x1F
*

View file

@ -1419,6 +1419,7 @@ u_unescapeAt(UNESCAPE_CHAR_AT charAt,
int8_t bitsPerDigit = 4;
int8_t dig;
int32_t i;
UBool braces = FALSE;
/* Check that offset is in range */
if (*offset < 0 || *offset >= length) {
@ -1438,7 +1439,13 @@ u_unescapeAt(UNESCAPE_CHAR_AT charAt,
break;
case 0x0078 /*'x'*/:
minDig = 1;
maxDig = 2;
if (*offset < length && charAt(*offset, context) == 0x7B /*{*/) {
++(*offset);
braces = TRUE;
maxDig = 8;
} else {
maxDig = 2;
}
break;
default:
dig = _digit8(c);
@ -1465,6 +1472,12 @@ u_unescapeAt(UNESCAPE_CHAR_AT charAt,
if (n < minDig) {
goto err;
}
if (braces) {
if (c != 0x7D /*}*/) {
goto err;
}
++(*offset);
}
return result;
}

View file

@ -1098,13 +1098,13 @@ TestUnescape() {
static UChar buffer[200];
static const char* input =
"Sch\\u00f6nes Auto: \\u20ac 11240.\\fPrivates Zeichen: \\U00102345\\e\\cC\\n";
"Sch\\u00f6nes Auto: \\u20ac 11240.\\fPrivates Zeichen: \\U00102345\\e\\cC\\n \\x1b\\x{263a}";
static const UChar expect[]={
0x53, 0x63, 0x68, 0xf6, 0x6e, 0x65, 0x73, 0x20, 0x41, 0x75, 0x74, 0x6f, 0x3a, 0x20,
0x20ac, 0x20, 0x31, 0x31, 0x32, 0x34, 0x30, 0x2e, 0x0c,
0x50, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x73, 0x20,
0x5a, 0x65, 0x69, 0x63, 0x68, 0x65, 0x6e, 0x3a, 0x20, 0xdbc8, 0xdf45, 0x1b, 0x03, 0x0a, 0
0x5a, 0x65, 0x69, 0x63, 0x68, 0x65, 0x6e, 0x3a, 0x20, 0xdbc8, 0xdf45, 0x1b, 0x03, 0x0a, 0x20, 0x1b, 0x263A, 0
};
static const int32_t explength = sizeof(expect)/sizeof(expect[0])-1;
int32_t length;