#include "unicode/utypes.h"
#if !UCONFIG_NO_CONVERSION
#include "unicode/ucnv_err.h"
#include "unicode/ucnv_cb.h"
#include "ucnv_cnv.h"
#include "cmemory.h"
#include "unicode/ucnv.h"
#include "ustrfmt.h"
#define VALUE_STRING_LENGTH …
#define UNICODE_PERCENT_SIGN_CODEPOINT …
#define UNICODE_U_CODEPOINT …
#define UNICODE_X_CODEPOINT …
#define UNICODE_RS_CODEPOINT …
#define UNICODE_U_LOW_CODEPOINT …
#define UNICODE_X_LOW_CODEPOINT …
#define UNICODE_AMP_CODEPOINT …
#define UNICODE_HASH_CODEPOINT …
#define UNICODE_SEMICOLON_CODEPOINT …
#define UNICODE_PLUS_CODEPOINT …
#define UNICODE_LEFT_CURLY_CODEPOINT …
#define UNICODE_RIGHT_CURLY_CODEPOINT …
#define UNICODE_SPACE_CODEPOINT …
#define UCNV_PRV_ESCAPE_ICU …
#define UCNV_PRV_ESCAPE_C …
#define UCNV_PRV_ESCAPE_XML_DEC …
#define UCNV_PRV_ESCAPE_XML_HEX …
#define UCNV_PRV_ESCAPE_JAVA …
#define UCNV_PRV_ESCAPE_UNICODE …
#define UCNV_PRV_ESCAPE_CSS2 …
#define UCNV_PRV_STOP_ON_ILLEGAL …
#define IS_DEFAULT_IGNORABLE_CODE_POINT …
U_CAPI void U_EXPORT2
UCNV_FROM_U_CALLBACK_STOP (
const void *context,
UConverterFromUnicodeArgs *fromUArgs,
const char16_t* codeUnits,
int32_t length,
UChar32 codePoint,
UConverterCallbackReason reason,
UErrorCode * err)
{
(void)context;
(void)fromUArgs;
(void)codeUnits;
(void)length;
if (reason == UCNV_UNASSIGNED && IS_DEFAULT_IGNORABLE_CODE_POINT(codePoint))
{
*err = U_ZERO_ERROR;
}
}
U_CAPI void U_EXPORT2
UCNV_TO_U_CALLBACK_STOP (
const void *context,
UConverterToUnicodeArgs *toUArgs,
const char* codePoints,
int32_t length,
UConverterCallbackReason reason,
UErrorCode * err)
{
(void)context; (void)toUArgs; (void)codePoints; (void)length; (void)reason; (void)err;
}
U_CAPI void U_EXPORT2
UCNV_FROM_U_CALLBACK_SKIP (
const void *context,
UConverterFromUnicodeArgs *fromUArgs,
const char16_t* codeUnits,
int32_t length,
UChar32 codePoint,
UConverterCallbackReason reason,
UErrorCode * err)
{
(void)fromUArgs;
(void)codeUnits;
(void)length;
if (reason <= UCNV_IRREGULAR)
{
if (reason == UCNV_UNASSIGNED && IS_DEFAULT_IGNORABLE_CODE_POINT(codePoint))
{
*err = U_ZERO_ERROR;
}
else if (context == nullptr || (*((char*)context) == UCNV_PRV_STOP_ON_ILLEGAL && reason == UCNV_UNASSIGNED))
{
*err = U_ZERO_ERROR;
}
}
}
U_CAPI void U_EXPORT2
UCNV_FROM_U_CALLBACK_SUBSTITUTE (
const void *context,
UConverterFromUnicodeArgs *fromArgs,
const char16_t* codeUnits,
int32_t length,
UChar32 codePoint,
UConverterCallbackReason reason,
UErrorCode * err)
{
(void)codeUnits;
(void)length;
if (reason <= UCNV_IRREGULAR)
{
if (reason == UCNV_UNASSIGNED && IS_DEFAULT_IGNORABLE_CODE_POINT(codePoint))
{
*err = U_ZERO_ERROR;
}
else if (context == nullptr || (*((char*)context) == UCNV_PRV_STOP_ON_ILLEGAL && reason == UCNV_UNASSIGNED))
{
*err = U_ZERO_ERROR;
ucnv_cbFromUWriteSub(fromArgs, 0, err);
}
}
}
U_CAPI void U_EXPORT2
UCNV_FROM_U_CALLBACK_ESCAPE (
const void *context,
UConverterFromUnicodeArgs *fromArgs,
const char16_t *codeUnits,
int32_t length,
UChar32 codePoint,
UConverterCallbackReason reason,
UErrorCode * err)
{
char16_t valueString[VALUE_STRING_LENGTH];
int32_t valueStringLength = 0;
int32_t i = 0;
const char16_t *myValueSource = nullptr;
UErrorCode err2 = U_ZERO_ERROR;
UConverterFromUCallback original = nullptr;
const void *originalContext;
UConverterFromUCallback ignoredCallback = nullptr;
const void *ignoredContext;
if (reason > UCNV_IRREGULAR)
{
return;
}
else if (reason == UCNV_UNASSIGNED && IS_DEFAULT_IGNORABLE_CODE_POINT(codePoint))
{
*err = U_ZERO_ERROR;
return;
}
ucnv_setFromUCallBack (fromArgs->converter,
(UConverterFromUCallback) UCNV_FROM_U_CALLBACK_SUBSTITUTE,
nullptr,
&original,
&originalContext,
&err2);
if (U_FAILURE (err2))
{
*err = err2;
return;
}
if(context==nullptr)
{
while (i < length)
{
valueString[valueStringLength++] = (char16_t) UNICODE_PERCENT_SIGN_CODEPOINT;
valueString[valueStringLength++] = (char16_t) UNICODE_U_CODEPOINT;
valueStringLength += uprv_itou (valueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, (uint16_t)codeUnits[i++], 16, 4);
}
}
else
{
switch(*((char*)context))
{
case UCNV_PRV_ESCAPE_JAVA:
while (i < length)
{
valueString[valueStringLength++] = (char16_t) UNICODE_RS_CODEPOINT;
valueString[valueStringLength++] = (char16_t) UNICODE_U_LOW_CODEPOINT;
valueStringLength += uprv_itou (valueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, (uint16_t)codeUnits[i++], 16, 4);
}
break;
case UCNV_PRV_ESCAPE_C:
valueString[valueStringLength++] = (char16_t) UNICODE_RS_CODEPOINT;
if(length==2){
valueString[valueStringLength++] = (char16_t) UNICODE_U_CODEPOINT;
valueStringLength += uprv_itou (valueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, codePoint, 16, 8);
}
else{
valueString[valueStringLength++] = (char16_t) UNICODE_U_LOW_CODEPOINT;
valueStringLength += uprv_itou (valueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, (uint16_t)codeUnits[0], 16, 4);
}
break;
case UCNV_PRV_ESCAPE_XML_DEC:
valueString[valueStringLength++] = (char16_t) UNICODE_AMP_CODEPOINT;
valueString[valueStringLength++] = (char16_t) UNICODE_HASH_CODEPOINT;
if(length==2){
valueStringLength += uprv_itou (valueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, codePoint, 10, 0);
}
else{
valueStringLength += uprv_itou (valueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, (uint16_t)codeUnits[0], 10, 0);
}
valueString[valueStringLength++] = (char16_t) UNICODE_SEMICOLON_CODEPOINT;
break;
case UCNV_PRV_ESCAPE_XML_HEX:
valueString[valueStringLength++] = (char16_t) UNICODE_AMP_CODEPOINT;
valueString[valueStringLength++] = (char16_t) UNICODE_HASH_CODEPOINT;
valueString[valueStringLength++] = (char16_t) UNICODE_X_LOW_CODEPOINT;
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);
}
valueString[valueStringLength++] = (char16_t) UNICODE_SEMICOLON_CODEPOINT;
break;
case UCNV_PRV_ESCAPE_UNICODE:
valueString[valueStringLength++] = (char16_t) UNICODE_LEFT_CURLY_CODEPOINT;
valueString[valueStringLength++] = (char16_t) UNICODE_U_CODEPOINT;
valueString[valueStringLength++] = (char16_t) UNICODE_PLUS_CODEPOINT;
if (length == 2) {
valueStringLength += uprv_itou (valueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, codePoint, 16, 4);
} else {
valueStringLength += uprv_itou (valueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, (uint16_t)codeUnits[0], 16, 4);
}
valueString[valueStringLength++] = (char16_t) UNICODE_RIGHT_CURLY_CODEPOINT;
break;
case UCNV_PRV_ESCAPE_CSS2:
valueString[valueStringLength++] = (char16_t) UNICODE_RS_CODEPOINT;
valueStringLength += uprv_itou (valueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, codePoint, 16, 0);
valueString[valueStringLength++] = (char16_t) UNICODE_SPACE_CODEPOINT;
break;
default:
while (i < length)
{
valueString[valueStringLength++] = (char16_t) UNICODE_PERCENT_SIGN_CODEPOINT;
valueString[valueStringLength++] = (char16_t) UNICODE_U_CODEPOINT;
valueStringLength += uprv_itou (valueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, (uint16_t)codeUnits[i++], 16, 4);
}
}
}
myValueSource = valueString;
*err = U_ZERO_ERROR;
ucnv_cbFromUWriteUChars(fromArgs, &myValueSource, myValueSource+valueStringLength, 0, err);
ucnv_setFromUCallBack (fromArgs->converter,
original,
originalContext,
&ignoredCallback,
&ignoredContext,
&err2);
if (U_FAILURE (err2))
{
*err = err2;
return;
}
}
U_CAPI void U_EXPORT2
UCNV_TO_U_CALLBACK_SKIP (
const void *context,
UConverterToUnicodeArgs *toArgs,
const char* codeUnits,
int32_t length,
UConverterCallbackReason reason,
UErrorCode * err)
{
(void)toArgs;
(void)codeUnits;
(void)length;
if (reason <= UCNV_IRREGULAR)
{
if (context == nullptr || (*((char*)context) == UCNV_PRV_STOP_ON_ILLEGAL && reason == UCNV_UNASSIGNED))
{
*err = U_ZERO_ERROR;
}
}
}
U_CAPI void U_EXPORT2
UCNV_TO_U_CALLBACK_SUBSTITUTE (
const void *context,
UConverterToUnicodeArgs *toArgs,
const char* codeUnits,
int32_t length,
UConverterCallbackReason reason,
UErrorCode * err)
{
(void)codeUnits;
(void)length;
if (reason <= UCNV_IRREGULAR)
{
if (context == nullptr || (*((char*)context) == UCNV_PRV_STOP_ON_ILLEGAL && reason == UCNV_UNASSIGNED))
{
*err = U_ZERO_ERROR;
ucnv_cbToUWriteSub(toArgs,0,err);
}
}
}
U_CAPI void U_EXPORT2
UCNV_TO_U_CALLBACK_ESCAPE (
const void *context,
UConverterToUnicodeArgs *toArgs,
const char* codeUnits,
int32_t length,
UConverterCallbackReason reason,
UErrorCode * err)
{
char16_t uniValueString[VALUE_STRING_LENGTH];
int32_t valueStringLength = 0;
int32_t i = 0;
if (reason > UCNV_IRREGULAR)
{
return;
}
if(context==nullptr)
{
while (i < length)
{
uniValueString[valueStringLength++] = (char16_t) UNICODE_PERCENT_SIGN_CODEPOINT;
uniValueString[valueStringLength++] = (char16_t) UNICODE_X_CODEPOINT;
valueStringLength += uprv_itou (uniValueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, (uint8_t) codeUnits[i++], 16, 2);
}
}
else
{
switch(*((char*)context))
{
case UCNV_PRV_ESCAPE_XML_DEC:
while (i < length)
{
uniValueString[valueStringLength++] = (char16_t) UNICODE_AMP_CODEPOINT;
uniValueString[valueStringLength++] = (char16_t) UNICODE_HASH_CODEPOINT;
valueStringLength += uprv_itou (uniValueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, (uint8_t)codeUnits[i++], 10, 0);
uniValueString[valueStringLength++] = (char16_t) UNICODE_SEMICOLON_CODEPOINT;
}
break;
case UCNV_PRV_ESCAPE_XML_HEX:
while (i < length)
{
uniValueString[valueStringLength++] = (char16_t) UNICODE_AMP_CODEPOINT;
uniValueString[valueStringLength++] = (char16_t) UNICODE_HASH_CODEPOINT;
uniValueString[valueStringLength++] = (char16_t) UNICODE_X_LOW_CODEPOINT;
valueStringLength += uprv_itou (uniValueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, (uint8_t)codeUnits[i++], 16, 0);
uniValueString[valueStringLength++] = (char16_t) UNICODE_SEMICOLON_CODEPOINT;
}
break;
case UCNV_PRV_ESCAPE_C:
while (i < length)
{
uniValueString[valueStringLength++] = (char16_t) UNICODE_RS_CODEPOINT;
uniValueString[valueStringLength++] = (char16_t) UNICODE_X_LOW_CODEPOINT;
valueStringLength += uprv_itou (uniValueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, (uint8_t)codeUnits[i++], 16, 2);
}
break;
default:
while (i < length)
{
uniValueString[valueStringLength++] = (char16_t) UNICODE_PERCENT_SIGN_CODEPOINT;
uniValueString[valueStringLength++] = (char16_t) UNICODE_X_CODEPOINT;
uprv_itou (uniValueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, (uint8_t) codeUnits[i++], 16, 2);
valueStringLength += 2;
}
}
}
*err = U_ZERO_ERROR;
ucnv_cbToUWriteUChars(toArgs, uniValueString, valueStringLength, 0, err);
}
#endif