/* * IS_DEFAULT_IGNORABLE_CODE_POINT * This is to check if a code point has the default ignorable unicode property. * As such, this list needs to be updated if the ignorable code point list ever * changes. * To avoid dependency on other code, this list is hard coded here. * When an ignorable code point is found and is unmappable, the default callbacks * will ignore them. * For a list of the default ignorable code points, use this link: * https://util.unicode.org/UnicodeJsps/list-unicodeset.jsp?a=%5B%3ADI%3A%5D&abb=on&g=&i=n> * * This list should be sync with the one in CharsetCallback.java
*/ #define IS_DEFAULT_IGNORABLE_CODE_POINT(c) ( \
(c == 0x00AD) || \
(c == 0x034F) || \
(c == 0x061C) || \
(c == 0x115F) || \
(c == 0x1160) || \
(0x17B4 <= c && c <= 0x17B5) || \
(0x180B <= c && c <= 0x180F) || \
(0x200B <= c && c <= 0x200F) || \
(0x202A <= c && c <= 0x202E) || \
(0x2060 <= c && c <= 0x206F) || \
(c == 0x3164) || \
(0xFE00 <= c && c <= 0xFE0F) || \
(c == 0xFEFF) || \
(c == 0xFFA0) || \
(0xFFF0 <= c && c <= 0xFFF8) || \
(0x1BCA0 <= c && c <= 0x1BCA3) || \
(0x1D173 <= c && c <= 0x1D17A) || \
(0xE0000 <= c && c <= 0xE0FFF))
/*Function Pointer STOPS at the ILLEGAL_SEQUENCE */
U_CAPI void U_EXPORT2
UCNV_FROM_U_CALLBACK_STOP ( constvoid *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))
{ /* * Skip if the codepoint has unicode property of default ignorable.
*/
*err = U_ZERO_ERROR;
} /* the caller must have set the error code accordingly */
}
/*Function Pointer STOPS at the ILLEGAL_SEQUENCE */
U_CAPI void U_EXPORT2
UCNV_TO_U_CALLBACK_STOP ( constvoid *context,
UConverterToUnicodeArgs *toUArgs, constchar* codePoints,
int32_t length,
UConverterCallbackReason reason,
UErrorCode * err)
{ /* the caller must have set the error code accordingly */
(void)context; (void)toUArgs; (void)codePoints; (void)length; (void)reason; (void)err;
}
U_CAPI void U_EXPORT2
UCNV_FROM_U_CALLBACK_SKIP ( constvoid *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))
{ /* * Skip if the codepoint has unicode property of default ignorable.
*/
*err = U_ZERO_ERROR;
} elseif (context == nullptr || (*((char*)context) == UCNV_PRV_STOP_ON_ILLEGAL && reason == UCNV_UNASSIGNED))
{
*err = U_ZERO_ERROR;
} /* else the caller must have set the error code accordingly. */
} /* else ignore the reset, close and clone calls. */
}
U_CAPI void U_EXPORT2
UCNV_FROM_U_CALLBACK_SUBSTITUTE ( constvoid *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))
{ /* * Skip if the codepoint has unicode property of default ignorable.
*/
*err = U_ZERO_ERROR;
} elseif (context == nullptr || (*((char*)context) == UCNV_PRV_STOP_ON_ILLEGAL && reason == UCNV_UNASSIGNED))
{
*err = U_ZERO_ERROR;
ucnv_cbFromUWriteSub(fromArgs, 0, err);
} /* else the caller must have set the error code accordingly. */
} /* else ignore the reset, close and clone calls. */
}
/*uses uprv_itou to get a unicode escape sequence of the offensive sequence, *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)
*/
U_CAPI void U_EXPORT2
UCNV_FROM_U_CALLBACK_ESCAPE ( constvoid *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;
case UCNV_PRV_ESCAPE_CSS2:
valueString[valueStringLength++] = (char16_t) UNICODE_RS_CODEPOINT; /* adding \ */
valueStringLength += uprv_itou (valueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, codePoint, 16, 0); /* Always add space character, because the next character might be whitespace,
which would erroneously be considered the termination of the escape sequence. */
valueString[valueStringLength++] = (char16_t) UNICODE_SPACE_CODEPOINT; break;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.