| OLD | NEW |
| 1 /* | 1 /* |
| 2 ***************************************************************************** | 2 ***************************************************************************** |
| 3 * | 3 * |
| 4 * Copyright (C) 1998-2007, International Business Machines | 4 * Copyright (C) 1998-2014, International Business Machines |
| 5 * Corporation and others. All Rights Reserved. | 5 * Corporation and others. All Rights Reserved. |
| 6 * | 6 * |
| 7 ***************************************************************************** | 7 ***************************************************************************** |
| 8 * | 8 * |
| 9 * ucnv_err.c | 9 * ucnv_err.c |
| 10 * Implements error behaviour functions called by T_UConverter_{from,to}Unicode | 10 * Implements error behaviour functions called by T_UConverter_{from,to}Unicode |
| 11 * | 11 * |
| 12 * | 12 * |
| 13 * Change history: | 13 * Change history: |
| 14 * | 14 * |
| (...skipping 28 matching lines...) Expand all Loading... |
| 43 #define UNICODE_SPACE_CODEPOINT 0x0020 | 43 #define UNICODE_SPACE_CODEPOINT 0x0020 |
| 44 #define UCNV_PRV_ESCAPE_ICU 0 | 44 #define UCNV_PRV_ESCAPE_ICU 0 |
| 45 #define UCNV_PRV_ESCAPE_C 'C' | 45 #define UCNV_PRV_ESCAPE_C 'C' |
| 46 #define UCNV_PRV_ESCAPE_XML_DEC 'D' | 46 #define UCNV_PRV_ESCAPE_XML_DEC 'D' |
| 47 #define UCNV_PRV_ESCAPE_XML_HEX 'X' | 47 #define UCNV_PRV_ESCAPE_XML_HEX 'X' |
| 48 #define UCNV_PRV_ESCAPE_JAVA 'J' | 48 #define UCNV_PRV_ESCAPE_JAVA 'J' |
| 49 #define UCNV_PRV_ESCAPE_UNICODE 'U' | 49 #define UCNV_PRV_ESCAPE_UNICODE 'U' |
| 50 #define UCNV_PRV_ESCAPE_CSS2 'S' | 50 #define UCNV_PRV_ESCAPE_CSS2 'S' |
| 51 #define UCNV_PRV_STOP_ON_ILLEGAL 'i' | 51 #define UCNV_PRV_STOP_ON_ILLEGAL 'i' |
| 52 | 52 |
| 53 /* |
| 54 * IS_DEFAULT_IGNORABLE_CODE_POINT |
| 55 * This is to check if a code point has the default ignorable unicode property. |
| 56 * As such, this list needs to be updated if the ignorable code point list ever |
| 57 * changes. |
| 58 * To avoid dependency on other code, this list is hard coded here. |
| 59 * When an ignorable code point is found and is unmappable, the default callback
s |
| 60 * will ignore them. |
| 61 * For a list of the default ignorable code points, use this link: http://unicod
e.org/cldr/utility/list-unicodeset.jsp?a=[%3ADI%3A]&g= |
| 62 * |
| 63 * This list should be sync with the one in CharsetCallback.java |
| 64 */ |
| 65 #define IS_DEFAULT_IGNORABLE_CODE_POINT(c) (\ |
| 66 (c == 0x00AD) || \ |
| 67 (c == 0x034F) || \ |
| 68 (c == 0x061C) || \ |
| 69 (c == 0x115F) || \ |
| 70 (c == 0x1160) || \ |
| 71 (0x17B4 <= c && c <= 0x17B5) || \ |
| 72 (0x180B <= c && c <= 0x180E) || \ |
| 73 (0x200B <= c && c <= 0x200F) || \ |
| 74 (0x202A <= c && c <= 0x202E) || \ |
| 75 (c == 0x2060) || \ |
| 76 (0x2066 <= c && c <= 0x2069) || \ |
| 77 (0x2061 <= c && c <= 0x2064) || \ |
| 78 (0x206A <= c && c <= 0x206F) || \ |
| 79 (c == 0x3164) || \ |
| 80 (0x0FE00 <= c && c <= 0x0FE0F) || \ |
| 81 (c == 0x0FEFF) || \ |
| 82 (c == 0x0FFA0) || \ |
| 83 (0x01BCA0 <= c && c <= 0x01BCA3) || \ |
| 84 (0x01D173 <= c && c <= 0x01D17A) || \ |
| 85 (c == 0x0E0001) || \ |
| 86 (0x0E0020 <= c && c <= 0x0E007F) || \ |
| 87 (0x0E0100 <= c && c <= 0x0E01EF) || \ |
| 88 (c == 0x2065) || \ |
| 89 (0x0FFF0 <= c && c <= 0x0FFF8) || \ |
| 90 (c == 0x0E0000) || \ |
| 91 (0x0E0002 <= c && c <= 0x0E001F) || \ |
| 92 (0x0E0080 <= c && c <= 0x0E00FF) || \ |
| 93 (0x0E01F0 <= c && c <= 0x0E0FFF) \ |
| 94 ) |
| 95 |
| 96 |
| 53 /*Function Pointer STOPS at the ILLEGAL_SEQUENCE */ | 97 /*Function Pointer STOPS at the ILLEGAL_SEQUENCE */ |
| 54 U_CAPI void U_EXPORT2 | 98 U_CAPI void U_EXPORT2 |
| 55 UCNV_FROM_U_CALLBACK_STOP ( | 99 UCNV_FROM_U_CALLBACK_STOP ( |
| 56 const void *context, | 100 const void *context, |
| 57 UConverterFromUnicodeArgs *fromUArgs, | 101 UConverterFromUnicodeArgs *fromUArgs, |
| 58 const UChar* codeUnits, | 102 const UChar* codeUnits, |
| 59 int32_t length, | 103 int32_t length, |
| 60 UChar32 codePoint, | 104 UChar32 codePoint, |
| 61 UConverterCallbackReason reason, | 105 UConverterCallbackReason reason, |
| 62 UErrorCode * err) | 106 UErrorCode * err) |
| 63 { | 107 { |
| 108 if (reason == UCNV_UNASSIGNED && IS_DEFAULT_IGNORABLE_CODE_POINT(codePoint)) |
| 109 { |
| 110 /* |
| 111 * Skip if the codepoint has unicode property of default ignorable. |
| 112 */ |
| 113 *err = U_ZERO_ERROR; |
| 114 } |
| 64 /* the caller must have set the error code accordingly */ | 115 /* the caller must have set the error code accordingly */ |
| 65 return; | 116 return; |
| 66 } | 117 } |
| 67 | 118 |
| 68 | 119 |
| 69 /*Function Pointer STOPS at the ILLEGAL_SEQUENCE */ | 120 /*Function Pointer STOPS at the ILLEGAL_SEQUENCE */ |
| 70 U_CAPI void U_EXPORT2 | 121 U_CAPI void U_EXPORT2 |
| 71 UCNV_TO_U_CALLBACK_STOP ( | 122 UCNV_TO_U_CALLBACK_STOP ( |
| 72 const void *context, | 123 const void *context, |
| 73 UConverterToUnicodeArgs *toUArgs, | 124 UConverterToUnicodeArgs *toUArgs, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 85 const void *context, | 136 const void *context, |
| 86 UConverterFromUnicodeArgs *fromUArgs, | 137 UConverterFromUnicodeArgs *fromUArgs, |
| 87 const UChar* codeUnits, | 138 const UChar* codeUnits, |
| 88 int32_t length, | 139 int32_t length, |
| 89 UChar32 codePoint, | 140 UChar32 codePoint, |
| 90 UConverterCallbackReason reason, | 141 UConverterCallbackReason reason, |
| 91 UErrorCode * err) | 142 UErrorCode * err) |
| 92 { | 143 { |
| 93 if (reason <= UCNV_IRREGULAR) | 144 if (reason <= UCNV_IRREGULAR) |
| 94 { | 145 { |
| 95 if (context == NULL || (*((char*)context) == UCNV_PRV_STOP_ON_ILLEGAL &&
reason == UCNV_UNASSIGNED)) | 146 if (reason == UCNV_UNASSIGNED && IS_DEFAULT_IGNORABLE_CODE_POINT(codePoi
nt)) |
| 147 { |
| 148 /* |
| 149 * Skip if the codepoint has unicode property of default ignorable. |
| 150 */ |
| 151 *err = U_ZERO_ERROR; |
| 152 } |
| 153 else if (context == NULL || (*((char*)context) == UCNV_PRV_STOP_ON_ILLEG
AL && reason == UCNV_UNASSIGNED)) |
| 96 { | 154 { |
| 97 *err = U_ZERO_ERROR; | 155 *err = U_ZERO_ERROR; |
| 98 } | 156 } |
| 99 /* else the caller must have set the error code accordingly. */ | 157 /* else the caller must have set the error code accordingly. */ |
| 100 } | 158 } |
| 101 /* else ignore the reset, close and clone calls. */ | 159 /* else ignore the reset, close and clone calls. */ |
| 102 } | 160 } |
| 103 | 161 |
| 104 U_CAPI void U_EXPORT2 | 162 U_CAPI void U_EXPORT2 |
| 105 UCNV_FROM_U_CALLBACK_SUBSTITUTE ( | 163 UCNV_FROM_U_CALLBACK_SUBSTITUTE ( |
| 106 const void *context, | 164 const void *context, |
| 107 UConverterFromUnicodeArgs *fromArgs, | 165 UConverterFromUnicodeArgs *fromArgs, |
| 108 const UChar* codeUnits, | 166 const UChar* codeUnits, |
| 109 int32_t length, | 167 int32_t length, |
| 110 UChar32 codePoint, | 168 UChar32 codePoint, |
| 111 UConverterCallbackReason reason, | 169 UConverterCallbackReason reason, |
| 112 UErrorCode * err) | 170 UErrorCode * err) |
| 113 { | 171 { |
| 114 if (reason <= UCNV_IRREGULAR) | 172 if (reason <= UCNV_IRREGULAR) |
| 115 { | 173 { |
| 116 if (context == NULL || (*((char*)context) == UCNV_PRV_STOP_ON_ILLEGAL &&
reason == UCNV_UNASSIGNED)) | 174 if (reason == UCNV_UNASSIGNED && IS_DEFAULT_IGNORABLE_CODE_POINT(codePoi
nt)) |
| 175 { |
| 176 /* |
| 177 * Skip if the codepoint has unicode property of default ignorable. |
| 178 */ |
| 179 *err = U_ZERO_ERROR; |
| 180 } |
| 181 else if (context == NULL || (*((char*)context) == UCNV_PRV_STOP_ON_ILLEG
AL && reason == UCNV_UNASSIGNED)) |
| 117 { | 182 { |
| 118 *err = U_ZERO_ERROR; | 183 *err = U_ZERO_ERROR; |
| 119 ucnv_cbFromUWriteSub(fromArgs, 0, err); | 184 ucnv_cbFromUWriteSub(fromArgs, 0, err); |
| 120 } | 185 } |
| 121 /* else the caller must have set the error code accordingly. */ | 186 /* else the caller must have set the error code accordingly. */ |
| 122 } | 187 } |
| 123 /* else ignore the reset, close and clone calls. */ | 188 /* else ignore the reset, close and clone calls. */ |
| 124 } | 189 } |
| 125 | 190 |
| 126 /*uses uprv_itou to get a unicode escape sequence of the offensive sequence, | 191 /*uses uprv_itou to get a unicode escape sequence of the offensive sequence, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 148 UConverterFromUCallback original = NULL; | 213 UConverterFromUCallback original = NULL; |
| 149 const void *originalContext; | 214 const void *originalContext; |
| 150 | 215 |
| 151 UConverterFromUCallback ignoredCallback = NULL; | 216 UConverterFromUCallback ignoredCallback = NULL; |
| 152 const void *ignoredContext; | 217 const void *ignoredContext; |
| 153 | 218 |
| 154 if (reason > UCNV_IRREGULAR) | 219 if (reason > UCNV_IRREGULAR) |
| 155 { | 220 { |
| 156 return; | 221 return; |
| 157 } | 222 } |
| 223 else if (reason == UCNV_UNASSIGNED && IS_DEFAULT_IGNORABLE_CODE_POINT(codePoin
t)) |
| 224 { |
| 225 /* |
| 226 * Skip if the codepoint has unicode property of default ignorable. |
| 227 */ |
| 228 *err = U_ZERO_ERROR; |
| 229 return; |
| 230 } |
| 158 | 231 |
| 159 ucnv_setFromUCallBack (fromArgs->converter, | 232 ucnv_setFromUCallBack (fromArgs->converter, |
| 160 (UConverterFromUCallback) UCNV_FROM_U_CALLBACK_SUBSTITUTE, | 233 (UConverterFromUCallback) UCNV_FROM_U_CALLBACK_SUBSTITUTE, |
| 161 NULL, | 234 NULL, |
| 162 &original, | 235 &original, |
| 163 &originalContext, | 236 &originalContext, |
| 164 &err2); | 237 &err2); |
| 165 | 238 |
| 166 if (U_FAILURE (err2)) | 239 if (U_FAILURE (err2)) |
| 167 { | 240 { |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 } | 470 } |
| 398 } | 471 } |
| 399 } | 472 } |
| 400 /* reset the error */ | 473 /* reset the error */ |
| 401 *err = U_ZERO_ERROR; | 474 *err = U_ZERO_ERROR; |
| 402 | 475 |
| 403 ucnv_cbToUWriteUChars(toArgs, uniValueString, valueStringLength, 0, err); | 476 ucnv_cbToUWriteUChars(toArgs, uniValueString, valueStringLength, 0, err); |
| 404 } | 477 } |
| 405 | 478 |
| 406 #endif | 479 #endif |
| OLD | NEW |