1999-08-16 21:50:52 +00:00
|
|
|
/*
|
2001-03-21 20:44:20 +00:00
|
|
|
*****************************************************************************
|
1999-08-16 21:50:52 +00:00
|
|
|
*
|
2001-03-21 20:44:20 +00:00
|
|
|
* Copyright (C) 1998-2001, International Business Machines
|
2000-01-13 23:54:23 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
1999-08-16 21:50:52 +00:00
|
|
|
*
|
2001-03-21 20:44:20 +00:00
|
|
|
*****************************************************************************
|
1999-08-16 21:50:52 +00:00
|
|
|
*
|
|
|
|
* ucnv_err.c
|
|
|
|
* Implements error behaviour functions called by T_UConverter_{from,to}Unicode
|
|
|
|
*
|
2000-06-27 20:47:56 +00:00
|
|
|
*
|
|
|
|
* Change history:
|
|
|
|
*
|
|
|
|
* 06/29/2000 helena Major rewrite of the callback APIs.
|
|
|
|
*/
|
1999-08-16 21:50:52 +00:00
|
|
|
|
1999-12-28 23:39:02 +00:00
|
|
|
#include "unicode/ucnv_err.h"
|
2000-07-31 23:39:28 +00:00
|
|
|
#include "unicode/ucnv_cb.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "ucnv_cnv.h"
|
|
|
|
#include "cmemory.h"
|
1999-12-28 23:39:02 +00:00
|
|
|
#include "unicode/ucnv.h"
|
2001-08-17 01:40:34 +00:00
|
|
|
#include "ustrfmt.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
#define VALUE_STRING_LENGTH 32
|
|
|
|
/*Magic # 32 = 4(number of char in value string) * 8(max number of bytes per char for any converter) */
|
2001-09-10 03:50:45 +00:00
|
|
|
#define UNICODE_PERCENT_SIGN_CODEPOINT 0x0025
|
|
|
|
#define UNICODE_U_CODEPOINT 0x0055
|
|
|
|
#define UNICODE_X_CODEPOINT 0x0058
|
|
|
|
#define UNICODE_RS_CODEPOINT 0x005C
|
|
|
|
#define UNICODE_U_LOW_CODEPOINT 0x0075
|
|
|
|
#define UNICODE_X_LOW_CODEPOINT 0x0078
|
|
|
|
#define UNICODE_AMP_CODEPOINT 0x0026
|
|
|
|
#define UNICODE_HASH_CODEPOINT 0x0023
|
|
|
|
#define UNICODE_SEMICOLON_CODEPOINT 0x003B
|
2001-03-15 00:43:12 +00:00
|
|
|
#define UCNV_PRV_ESCAPE_ICU 0
|
2001-02-16 20:12:50 +00:00
|
|
|
#define UCNV_PRV_ESCAPE_C 'C'
|
|
|
|
#define UCNV_PRV_ESCAPE_XML_DEC 'D'
|
|
|
|
#define UCNV_PRV_ESCAPE_XML_HEX 'X'
|
|
|
|
#define UCNV_PRV_ESCAPE_JAVA 'J'
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*Function Pointer STOPS at the ILLEGAL_SEQUENCE */
|
2000-06-27 20:47:56 +00:00
|
|
|
void UCNV_FROM_U_CALLBACK_STOP (
|
2001-06-26 22:51:14 +00:00
|
|
|
const void *context,
|
2000-06-27 20:47:56 +00:00
|
|
|
UConverterFromUnicodeArgs *fromUArgs,
|
|
|
|
const UChar* codeUnits,
|
|
|
|
int32_t length,
|
|
|
|
UChar32 codePoint,
|
|
|
|
UConverterCallbackReason reason,
|
2000-07-26 00:20:19 +00:00
|
|
|
UErrorCode * err)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-07-13 00:14:10 +00:00
|
|
|
/* the caller must have set the error code accordingly */
|
1999-08-16 21:50:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*Function Pointer STOPS at the ILLEGAL_SEQUENCE */
|
2000-06-27 20:47:56 +00:00
|
|
|
void UCNV_TO_U_CALLBACK_STOP (
|
2001-06-26 22:51:14 +00:00
|
|
|
const void *context,
|
2000-06-27 20:47:56 +00:00
|
|
|
UConverterToUnicodeArgs *toUArgs,
|
|
|
|
const char* codePoints,
|
|
|
|
int32_t length,
|
|
|
|
UConverterCallbackReason reason,
|
2000-07-26 00:20:19 +00:00
|
|
|
UErrorCode * err)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-07-13 00:14:10 +00:00
|
|
|
/* the caller must have set the error code accordingly */
|
1999-08-16 21:50:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-06-27 20:47:56 +00:00
|
|
|
void UCNV_FROM_U_CALLBACK_SKIP (
|
2001-06-26 22:51:14 +00:00
|
|
|
const void *context,
|
2000-06-27 20:47:56 +00:00
|
|
|
UConverterFromUnicodeArgs *fromUArgs,
|
|
|
|
const UChar* codeUnits,
|
|
|
|
int32_t length,
|
|
|
|
UChar32 codePoint,
|
|
|
|
UConverterCallbackReason reason,
|
2000-07-26 00:20:19 +00:00
|
|
|
UErrorCode * err)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-02-16 20:12:50 +00:00
|
|
|
if(context==NULL)
|
|
|
|
{
|
|
|
|
if (reason <= UCNV_IRREGULAR)
|
|
|
|
{
|
|
|
|
*err = U_ZERO_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else if(*(char*)context=='i')
|
|
|
|
{
|
|
|
|
if(reason != UCNV_UNASSIGNED)
|
|
|
|
{
|
|
|
|
/* the caller must have set
|
|
|
|
* the error code accordingly
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*err = U_ZERO_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2000-06-27 20:47:56 +00:00
|
|
|
void UCNV_FROM_U_CALLBACK_SUBSTITUTE (
|
2001-06-26 22:51:14 +00:00
|
|
|
const void *context,
|
2000-06-27 20:47:56 +00:00
|
|
|
UConverterFromUnicodeArgs *fromArgs,
|
|
|
|
const UChar* codeUnits,
|
|
|
|
int32_t length,
|
|
|
|
UChar32 codePoint,
|
|
|
|
UConverterCallbackReason reason,
|
|
|
|
UErrorCode * err)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-02-16 20:12:50 +00:00
|
|
|
if(context == NULL)
|
|
|
|
{
|
|
|
|
if (reason > UCNV_IRREGULAR)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
*err = U_ZERO_ERROR;
|
|
|
|
ucnv_cbFromUWriteSub(fromArgs, 0, err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if(*((char*)context)=='i')
|
|
|
|
{
|
|
|
|
if(reason != UCNV_UNASSIGNED)
|
|
|
|
{
|
|
|
|
/* the caller must have set
|
|
|
|
* the error code accordingly
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*err = U_ZERO_ERROR;
|
|
|
|
ucnv_cbFromUWriteSub(fromArgs, 0, err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-08-16 01:01:57 +00:00
|
|
|
/*uses uprv_itou to get a unicode escape sequence of the offensive sequence,
|
1999-08-16 21:50:52 +00:00
|
|
|
*uses a clean copy (resetted) of the converter, to convert that unicode
|
|
|
|
*escape sequence to the target codepage (if conversion failure happens then
|
|
|
|
*we revert to substituting with subchar)
|
|
|
|
*/
|
2000-06-27 20:47:56 +00:00
|
|
|
void UCNV_FROM_U_CALLBACK_ESCAPE (
|
2001-06-26 22:51:14 +00:00
|
|
|
const void *context,
|
2000-06-27 20:47:56 +00:00
|
|
|
UConverterFromUnicodeArgs *fromArgs,
|
|
|
|
const UChar *codeUnits,
|
|
|
|
int32_t length,
|
|
|
|
UChar32 codePoint,
|
|
|
|
UConverterCallbackReason reason,
|
2000-07-26 00:20:19 +00:00
|
|
|
UErrorCode * err)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
UChar valueString[VALUE_STRING_LENGTH];
|
|
|
|
int32_t valueStringLength = 0;
|
2000-08-02 19:35:17 +00:00
|
|
|
int32_t i = 0;
|
2000-07-31 14:38:10 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
const UChar *myValueSource = NULL;
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode err2 = U_ZERO_ERROR;
|
2000-06-27 20:47:56 +00:00
|
|
|
UConverterFromUCallback original = NULL;
|
2001-06-26 22:51:14 +00:00
|
|
|
const void *originalContext;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-07-31 14:38:10 +00:00
|
|
|
UConverterFromUCallback ignoredCallback = NULL;
|
2001-06-26 22:51:14 +00:00
|
|
|
const void *ignoredContext;
|
2001-02-16 20:12:50 +00:00
|
|
|
|
2000-07-13 00:14:10 +00:00
|
|
|
if (reason > UCNV_IRREGULAR)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-07-31 14:38:10 +00:00
|
|
|
ucnv_setFromUCallBack (fromArgs->converter,
|
2001-02-16 20:12:50 +00:00
|
|
|
(UConverterFromUCallback) UCNV_FROM_U_CALLBACK_SUBSTITUTE,
|
|
|
|
NULL, /* To Do for HSYS: context is null? */
|
|
|
|
&original,
|
|
|
|
&originalContext,
|
|
|
|
&err2);
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE (err2))
|
2000-08-02 19:35:17 +00:00
|
|
|
{
|
|
|
|
*err = err2;
|
|
|
|
return;
|
2001-02-16 20:12:50 +00:00
|
|
|
}
|
|
|
|
if(context==NULL)
|
|
|
|
{
|
|
|
|
while (i < length)
|
|
|
|
{
|
2001-03-21 20:44:20 +00:00
|
|
|
valueString[valueStringLength++] = (UChar) UNICODE_PERCENT_SIGN_CODEPOINT; /* adding % */
|
|
|
|
valueString[valueStringLength++] = (UChar) UNICODE_U_CODEPOINT; /* adding U */
|
2001-08-16 01:01:57 +00:00
|
|
|
uprv_itou (valueString + valueStringLength, codeUnits[i++], 16, 4);
|
2001-02-16 20:12:50 +00:00
|
|
|
valueStringLength += 4;
|
|
|
|
}
|
2000-08-02 19:35:17 +00:00
|
|
|
}
|
2001-02-16 20:12:50 +00:00
|
|
|
else
|
2000-08-02 19:35:17 +00:00
|
|
|
{
|
2001-02-16 20:12:50 +00:00
|
|
|
switch(*((char*)context))
|
|
|
|
{
|
|
|
|
case UCNV_PRV_ESCAPE_JAVA:
|
|
|
|
while (i < length)
|
|
|
|
{
|
|
|
|
valueString[valueStringLength++] = (UChar) UNICODE_RS_CODEPOINT; /* adding \ */
|
2001-03-21 20:44:20 +00:00
|
|
|
valueString[valueStringLength++] = (UChar) UNICODE_U_LOW_CODEPOINT; /* adding u */
|
2001-08-16 01:01:57 +00:00
|
|
|
uprv_itou (valueString + valueStringLength, codeUnits[i++], 16, 4);
|
2001-02-16 20:12:50 +00:00
|
|
|
valueStringLength += 4;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UCNV_PRV_ESCAPE_C:
|
2001-03-21 20:44:20 +00:00
|
|
|
valueString[valueStringLength++] = (UChar) UNICODE_RS_CODEPOINT; /* adding \ */
|
2001-02-16 20:12:50 +00:00
|
|
|
|
|
|
|
if(length==2){
|
|
|
|
UChar32 temp = UTF16_GET_PAIR_VALUE(codeUnits[0],codeUnits[1]);
|
2001-09-10 03:50:45 +00:00
|
|
|
valueString[valueStringLength++] = (UChar) UNICODE_U_CODEPOINT; /* adding U */
|
2001-08-16 01:01:57 +00:00
|
|
|
valueStringLength += uprv_itou (valueString + valueStringLength, temp, 16, 8);
|
2001-02-16 20:12:50 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
else{
|
2001-09-10 03:50:45 +00:00
|
|
|
valueString[valueStringLength++] = (UChar) UNICODE_U_LOW_CODEPOINT; /* adding u */
|
2001-08-16 01:01:57 +00:00
|
|
|
valueStringLength += uprv_itou (valueString + valueStringLength, codeUnits[0], 16, 4);
|
2001-02-16 20:12:50 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UCNV_PRV_ESCAPE_XML_DEC:
|
|
|
|
|
2001-03-21 20:44:20 +00:00
|
|
|
valueString[valueStringLength++] = (UChar) UNICODE_AMP_CODEPOINT; /* adding & */
|
|
|
|
valueString[valueStringLength++] = (UChar) UNICODE_HASH_CODEPOINT; /* adding # */
|
2001-02-16 20:12:50 +00:00
|
|
|
if(length==2){
|
|
|
|
UChar32 temp = UTF16_GET_PAIR_VALUE(codeUnits[0],codeUnits[1]);
|
2001-08-16 01:01:57 +00:00
|
|
|
valueStringLength += uprv_itou (valueString + valueStringLength, temp, 10, 0);
|
2001-02-16 20:12:50 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
else{
|
2001-08-16 01:01:57 +00:00
|
|
|
valueStringLength += uprv_itou (valueString + valueStringLength, codeUnits[0], 10, 4);
|
2001-02-16 20:12:50 +00:00
|
|
|
}
|
2001-09-10 03:50:45 +00:00
|
|
|
valueString[valueStringLength++] = (UChar) UNICODE_SEMICOLON_CODEPOINT; /* adding ; */
|
2001-02-16 20:12:50 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UCNV_PRV_ESCAPE_XML_HEX:
|
|
|
|
|
2001-03-21 20:44:20 +00:00
|
|
|
valueString[valueStringLength++] = (UChar) UNICODE_AMP_CODEPOINT; /* adding & */
|
|
|
|
valueString[valueStringLength++] = (UChar) UNICODE_HASH_CODEPOINT; /* adding # */
|
2001-02-16 20:12:50 +00:00
|
|
|
valueString[valueStringLength++] = (UChar) UNICODE_X_LOW_CODEPOINT; /* adding x */
|
|
|
|
if(length==2){
|
|
|
|
UChar32 temp = UTF16_GET_PAIR_VALUE(codeUnits[0],codeUnits[1]);
|
2001-08-16 01:01:57 +00:00
|
|
|
valueStringLength += uprv_itou (valueString + valueStringLength, temp, 16, 0);
|
2001-02-16 20:12:50 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
else{
|
2001-08-16 01:01:57 +00:00
|
|
|
valueStringLength += uprv_itou (valueString + valueStringLength, codeUnits[0], 16, 4);
|
2001-02-16 20:12:50 +00:00
|
|
|
}
|
2001-09-10 03:50:45 +00:00
|
|
|
valueString[valueStringLength++] = (UChar) UNICODE_SEMICOLON_CODEPOINT; /* adding ; */
|
2001-02-16 20:12:50 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
while (i < length)
|
|
|
|
{
|
2001-03-21 20:44:20 +00:00
|
|
|
valueString[valueStringLength++] = (UChar) UNICODE_PERCENT_SIGN_CODEPOINT; /* adding % */
|
|
|
|
valueString[valueStringLength++] = (UChar) UNICODE_U_CODEPOINT; /* adding U */
|
2001-08-16 01:01:57 +00:00
|
|
|
uprv_itou (valueString + valueStringLength, codeUnits[i++], 16, 4);
|
2001-02-16 20:12:50 +00:00
|
|
|
valueStringLength += 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
myValueSource = valueString;
|
|
|
|
|
2000-07-31 14:38:10 +00:00
|
|
|
/* reset the error */
|
|
|
|
*err = U_ZERO_ERROR;
|
2000-07-26 00:20:19 +00:00
|
|
|
|
2000-08-02 19:35:17 +00:00
|
|
|
ucnv_cbFromUWriteUChars(fromArgs, &myValueSource, myValueSource+valueStringLength, 0, err);
|
2000-07-31 14:38:10 +00:00
|
|
|
|
|
|
|
ucnv_setFromUCallBack (fromArgs->converter,
|
|
|
|
original,
|
|
|
|
originalContext,
|
|
|
|
&ignoredCallback,
|
|
|
|
&ignoredContext,
|
|
|
|
&err2);
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE (err2))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-07-31 14:38:10 +00:00
|
|
|
*err = err2;
|
1999-08-16 21:50:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-06-27 20:47:56 +00:00
|
|
|
void UCNV_TO_U_CALLBACK_SKIP (
|
2001-06-26 22:51:14 +00:00
|
|
|
const void *context,
|
2000-06-27 20:47:56 +00:00
|
|
|
UConverterToUnicodeArgs *toArgs,
|
|
|
|
const char* codeUnits,
|
|
|
|
int32_t length,
|
|
|
|
UConverterCallbackReason reason,
|
2000-07-26 00:20:19 +00:00
|
|
|
UErrorCode * err)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-02-16 20:12:50 +00:00
|
|
|
if(context==NULL)
|
2000-07-26 00:20:19 +00:00
|
|
|
{
|
2001-02-16 20:12:50 +00:00
|
|
|
if (reason <= UCNV_IRREGULAR)
|
|
|
|
{
|
|
|
|
*err = U_ZERO_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else if(*((char*)context)=='i')
|
|
|
|
{
|
|
|
|
if(reason != UCNV_UNASSIGNED)
|
|
|
|
{
|
|
|
|
/* the caller must have set
|
|
|
|
* the error code accordingly
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*err = U_ZERO_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
2000-07-26 00:20:19 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2000-06-27 20:47:56 +00:00
|
|
|
void UCNV_TO_U_CALLBACK_SUBSTITUTE (
|
2001-06-26 22:51:14 +00:00
|
|
|
const void *context,
|
2000-06-27 20:47:56 +00:00
|
|
|
UConverterToUnicodeArgs *toArgs,
|
|
|
|
const char* codeUnits,
|
|
|
|
int32_t length,
|
|
|
|
UConverterCallbackReason reason,
|
2000-07-26 00:20:19 +00:00
|
|
|
UErrorCode * err)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-02-16 20:12:50 +00:00
|
|
|
if(context == NULL)
|
2000-07-26 00:20:19 +00:00
|
|
|
{
|
2001-02-16 20:12:50 +00:00
|
|
|
if (reason > UCNV_IRREGULAR)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
*err = U_ZERO_ERROR;
|
|
|
|
ucnv_cbToUWriteSub(toArgs,0,err);
|
2000-07-26 00:20:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-02-16 20:12:50 +00:00
|
|
|
else if(*((char*)context)=='i')
|
|
|
|
{
|
|
|
|
if(reason != UCNV_UNASSIGNED)
|
|
|
|
{
|
|
|
|
/* the caller must have set
|
|
|
|
* the error code accordingly
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*err = U_ZERO_ERROR;
|
|
|
|
ucnv_cbToUWriteSub(toArgs,0,err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2000-07-26 00:20:19 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-08-16 01:01:57 +00:00
|
|
|
/*uses uprv_itou to get a unicode escape sequence of the offensive sequence,
|
1999-08-16 21:50:52 +00:00
|
|
|
*and uses that as the substitution sequence
|
|
|
|
*/
|
2000-06-27 20:47:56 +00:00
|
|
|
void UCNV_TO_U_CALLBACK_ESCAPE (
|
2001-06-26 22:51:14 +00:00
|
|
|
const void *context,
|
2000-06-27 20:47:56 +00:00
|
|
|
UConverterToUnicodeArgs *toArgs,
|
|
|
|
const char* codeUnits,
|
|
|
|
int32_t length,
|
|
|
|
UConverterCallbackReason reason,
|
2000-07-26 00:20:19 +00:00
|
|
|
UErrorCode * err)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-03-21 20:44:20 +00:00
|
|
|
UChar uniValueString[VALUE_STRING_LENGTH];
|
|
|
|
int32_t valueStringLength = 0;
|
|
|
|
int32_t i = 0;
|
2000-07-13 00:14:10 +00:00
|
|
|
|
2001-03-21 20:44:20 +00:00
|
|
|
if (reason > UCNV_IRREGULAR)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ### TODO:
|
|
|
|
* This should use the new ucnv_cbWrite...() functions instead of doing
|
|
|
|
* "tricks" as before we had a good callback API!
|
|
|
|
* (Actually, this function is not all that bad.)
|
|
|
|
*/
|
2001-09-10 03:50:45 +00:00
|
|
|
if(context==NULL)
|
|
|
|
{
|
2001-03-21 20:44:20 +00:00
|
|
|
while (i < length)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-03-21 20:44:20 +00:00
|
|
|
uniValueString[valueStringLength++] = (UChar) UNICODE_PERCENT_SIGN_CODEPOINT; /* adding % */
|
|
|
|
uniValueString[valueStringLength++] = (UChar) UNICODE_X_CODEPOINT; /* adding X */
|
2001-08-16 01:01:57 +00:00
|
|
|
uprv_itou (uniValueString + valueStringLength, (uint8_t) codeUnits[i++], 16, 2);
|
2001-03-21 20:44:20 +00:00
|
|
|
valueStringLength += 2;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2001-09-10 03:50:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch(*((char*)context))
|
|
|
|
{
|
|
|
|
case UCNV_PRV_ESCAPE_XML_DEC:
|
|
|
|
while (i < length)
|
|
|
|
{
|
|
|
|
uniValueString[valueStringLength++] = (UChar) UNICODE_AMP_CODEPOINT; /* adding & */
|
|
|
|
uniValueString[valueStringLength++] = (UChar) UNICODE_HASH_CODEPOINT; /* adding # */
|
|
|
|
valueStringLength += uprv_itou (uniValueString + valueStringLength, codeUnits[i++], 10, 2);
|
|
|
|
uniValueString[valueStringLength++] = (UChar) UNICODE_SEMICOLON_CODEPOINT; /* adding ; */
|
|
|
|
}
|
|
|
|
break;
|
2000-07-26 00:20:19 +00:00
|
|
|
|
2001-09-10 03:50:45 +00:00
|
|
|
case UCNV_PRV_ESCAPE_XML_HEX:
|
|
|
|
while (i < length)
|
|
|
|
{
|
|
|
|
uniValueString[valueStringLength++] = (UChar) UNICODE_AMP_CODEPOINT; /* adding & */
|
|
|
|
uniValueString[valueStringLength++] = (UChar) UNICODE_HASH_CODEPOINT; /* adding # */
|
|
|
|
uniValueString[valueStringLength++] = (UChar) UNICODE_X_LOW_CODEPOINT; /* adding x */
|
|
|
|
valueStringLength += uprv_itou (uniValueString + valueStringLength, codeUnits[i++], 16, 4);
|
|
|
|
uniValueString[valueStringLength++] = (UChar) UNICODE_SEMICOLON_CODEPOINT; /* adding ; */
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case UCNV_PRV_ESCAPE_C:
|
|
|
|
while (i < length)
|
|
|
|
{
|
|
|
|
uniValueString[valueStringLength++] = (UChar) UNICODE_RS_CODEPOINT; /* adding \ */
|
|
|
|
uniValueString[valueStringLength++] = (UChar) UNICODE_X_LOW_CODEPOINT; /* adding x */
|
|
|
|
valueStringLength += uprv_itou (uniValueString + valueStringLength, codeUnits[i++], 16, 4);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
while (i < length)
|
|
|
|
{
|
|
|
|
uniValueString[valueStringLength++] = (UChar) UNICODE_PERCENT_SIGN_CODEPOINT; /* adding % */
|
|
|
|
uniValueString[valueStringLength++] = (UChar) UNICODE_X_CODEPOINT; /* adding X */
|
|
|
|
uprv_itou (uniValueString + valueStringLength, (uint8_t) codeUnits[i++], 16, 2);
|
|
|
|
valueStringLength += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-03-21 20:44:20 +00:00
|
|
|
/* reset the error */
|
|
|
|
*err = U_ZERO_ERROR;
|
2000-07-26 00:20:19 +00:00
|
|
|
|
2001-03-21 20:44:20 +00:00
|
|
|
ucnv_cbToUWriteUChars(toArgs, uniValueString, valueStringLength, 0, err);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|