ICU-5891 Implementation of CSS2 escaping.

X-SVN-Rev: 22703
This commit is contained in:
David Bertoni 2007-09-19 16:45:00 +00:00
parent 17fc0d7fbf
commit 65457ffe5b
3 changed files with 57 additions and 4 deletions

View File

@ -40,12 +40,14 @@
#define UNICODE_PLUS_CODEPOINT 0x002B #define UNICODE_PLUS_CODEPOINT 0x002B
#define UNICODE_LEFT_CURLY_CODEPOINT 0x007B #define UNICODE_LEFT_CURLY_CODEPOINT 0x007B
#define UNICODE_RIGHT_CURLY_CODEPOINT 0x007D #define UNICODE_RIGHT_CURLY_CODEPOINT 0x007D
#define UNICODE_SPACE_CODEPOINT 0x0020
#define UCNV_PRV_ESCAPE_ICU 0 #define UCNV_PRV_ESCAPE_ICU 0
#define UCNV_PRV_ESCAPE_C 'C' #define UCNV_PRV_ESCAPE_C 'C'
#define UCNV_PRV_ESCAPE_XML_DEC 'D' #define UCNV_PRV_ESCAPE_XML_DEC 'D'
#define UCNV_PRV_ESCAPE_XML_HEX 'X' #define UCNV_PRV_ESCAPE_XML_HEX 'X'
#define UCNV_PRV_ESCAPE_JAVA 'J' #define UCNV_PRV_ESCAPE_JAVA 'J'
#define UCNV_PRV_ESCAPE_UNICODE 'U' #define UCNV_PRV_ESCAPE_UNICODE 'U'
#define UCNV_PRV_ESCAPE_CSS2 'S'
#define UCNV_PRV_STOP_ON_ILLEGAL 'i' #define UCNV_PRV_STOP_ON_ILLEGAL 'i'
/*Function Pointer STOPS at the ILLEGAL_SEQUENCE */ /*Function Pointer STOPS at the ILLEGAL_SEQUENCE */
@ -241,6 +243,18 @@ UCNV_FROM_U_CALLBACK_ESCAPE (
valueString[valueStringLength++] = (UChar) UNICODE_RIGHT_CURLY_CODEPOINT; /* adding } */ valueString[valueStringLength++] = (UChar) UNICODE_RIGHT_CURLY_CODEPOINT; /* adding } */
break; break;
case UCNV_PRV_ESCAPE_CSS2:
valueString[valueStringLength++] = (UChar) UNICODE_RS_CODEPOINT; /* adding \ */
if (length == 2) {
valueStringLength += uprv_itou (valueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, codePoint, 16, 0);
} else {
valueStringLength += uprv_itou (valueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, (uint16_t)codeUnits[0], 16, 0);
}
/* Always add space character, becase the next character might be whitespace,
which would erroneously be considered the termination of the escape sequence. */
valueString[valueStringLength++] = (UChar) UNICODE_SPACE_CODEPOINT;
break;
default: default:
while (i < length) while (i < length)
{ {

View File

@ -1,6 +1,6 @@
/* /*
********************************************************************** **********************************************************************
* Copyright (C) 1999-2005, International Business Machines * Copyright (C) 1999-2007, International Business Machines
* Corporation and others. All Rights Reserved. * Corporation and others. All Rights Reserved.
********************************************************************** **********************************************************************
* *
@ -134,11 +134,18 @@ typedef struct UConverter UConverter;
*/ */
#define UCNV_ESCAPE_XML_HEX "X" #define UCNV_ESCAPE_XML_HEX "X"
/** /**
* FROM_U_CALLBACK_ESCAPE context option to escape teh code unit according to Unicode (U+XXXXX) * FROM_U_CALLBACK_ESCAPE context option to escape the code unit according to Unicode (U+XXXXX)
* @stable ICU 2.0 * @stable ICU 2.0
*/ */
#define UCNV_ESCAPE_UNICODE "U" #define UCNV_ESCAPE_UNICODE "U"
/**
* FROM_U_CALLBACK_ESCAPE context option to escape the code unit according to CSS2 conventions (\\X{XXXXX} followed by
* a space.
* @stable ICU 4.0
*/
#define UCNV_ESCAPE_CSS2 "S"
/** /**
* The process condition code to be used with the callbacks. * The process condition code to be used with the callbacks.
* Codes which are greater than UCNV_IRREGULAR should be * Codes which are greater than UCNV_IRREGULAR should be

View File

@ -1,6 +1,6 @@
/******************************************************************** /********************************************************************
* COPYRIGHT: * COPYRIGHT:
* Copyright (c) 1997-2006, International Business Machines Corporation and * Copyright (c) 1997-2007, International Business Machines Corporation and
* others. All Rights Reserved. * others. All Rights Reserved.
********************************************************************/ ********************************************************************/
/* /*
@ -2177,6 +2177,39 @@ static void TestSubWithValue(int32_t inputsize, int32_t outputsize)
UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_cnOffs7_v2, NULL, 0,"K" ,U_ZERO_ERROR )) UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_cnOffs7_v2, NULL, 0,"K" ,U_ZERO_ERROR ))
log_err("u-> iso-2022-cn with sub & K did not match.\n"); log_err("u-> iso-2022-cn with sub & K did not match.\n");
}
{
static const UChar iso_2022_cn_inputText8[]={
0x3000,
0xD84D, 0xDC56,
0x3001,
0xD84D, 0xDC56,
0xDBFF, 0xDFFF,
0x0042,
0x0902};
static const uint8_t to_iso_2022_cn8_v2[]={
0x1b, 0x24, 0x29, 0x41, 0x0e, 0x21, 0x21,
0x0f, 0x5c, 0x32, 0x33, 0x34, 0x35, 0x36, 0x20,
0x0e, 0x21, 0x22,
0x0f, 0x5c, 0x32, 0x33, 0x34, 0x35, 0x36, 0x20,
0x5c, 0x31, 0x30, 0x46, 0x46, 0x46, 0x46, 0x20,
0x42,
0x5c, 0x39, 0x30, 0x32, 0x20
};
static const int32_t from_iso_2022_cnOffs8_v2 [] ={
0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1,
3, 3, 3,
4, 4, 4, 4, 4, 4, 4, 4,
6, 6, 6, 6, 6, 6, 6, 6,
8,
9, 9, 9, 9, 9
};
if(!testConvertFromUnicodeWithContext(iso_2022_cn_inputText8, sizeof(iso_2022_cn_inputText8)/sizeof(iso_2022_cn_inputText8[0]),
to_iso_2022_cn8_v2, sizeof(to_iso_2022_cn8_v2), "iso-2022-cn",
UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_cnOffs8_v2, NULL, 0,UCNV_ESCAPE_CSS2,U_ZERO_ERROR ))
log_err("u-> iso-2022-cn with sub & UCNV_ESCAPE_CSS2 did not match.\n");
} }
{ {
static const uint8_t to_iso_2022_cn4_v3[]={ static const uint8_t to_iso_2022_cn4_v3[]={
@ -3351,4 +3384,3 @@ static void TestCallBackFailure(void) {
log_err("Error: ucnv_cbToUWriteUChars did not react correctly to a bad UErrorCode\n"); log_err("Error: ucnv_cbToUWriteUChars did not react correctly to a bad UErrorCode\n");
} }
} }