OLD | NEW |
1 /* | 1 /* |
2 ********************************************************************** | 2 ********************************************************************** |
3 * Copyright (C) 2002-2012, International Business Machines | 3 * Copyright (C) 2002-2012, International Business Machines |
4 * Corporation and others. All Rights Reserved. | 4 * Corporation and others. All Rights Reserved. |
5 ********************************************************************** | 5 ********************************************************************** |
6 * file name: ucnv_u8.c | 6 * file name: ucnv_u8.c |
7 * encoding: US-ASCII | 7 * encoding: US-ASCII |
8 * tab size: 8 (not used) | 8 * tab size: 8 (not used) |
9 * indentation:4 | 9 * indentation:4 |
10 * | 10 * |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 | 80 |
81 /* | 81 /* |
82 * Starting with Unicode 3.0.1: | 82 * Starting with Unicode 3.0.1: |
83 * UTF-8 byte sequences of length N _must_ encode code points of or above utf8_m
inChar32[N]; | 83 * UTF-8 byte sequences of length N _must_ encode code points of or above utf8_m
inChar32[N]; |
84 * byte sequences with more than 4 bytes are illegal in UTF-8, | 84 * byte sequences with more than 4 bytes are illegal in UTF-8, |
85 * which is tested with impossible values for them | 85 * which is tested with impossible values for them |
86 */ | 86 */ |
87 static const uint32_t | 87 static const uint32_t |
88 utf8_minChar32[7]={ 0, 0, 0x80, 0x800, 0x10000, 0xffffffff, 0xffffffff }; | 88 utf8_minChar32[7]={ 0, 0, 0x80, 0x800, 0x10000, 0xffffffff, 0xffffffff }; |
89 | 89 |
90 static UBool hasCESU8Data(const UConverter *cnv) | |
91 { | |
92 #if UCONFIG_NO_NON_HTML5_CONVERSION | |
93 return FALSE; | |
94 #else | |
95 return (UBool)(cnv->sharedData == &_CESU8Data); | |
96 #endif | |
97 } | |
98 | |
99 static void ucnv_toUnicode_UTF8 (UConverterToUnicodeArgs * args, | 90 static void ucnv_toUnicode_UTF8 (UConverterToUnicodeArgs * args, |
100 UErrorCode * err) | 91 UErrorCode * err) |
101 { | 92 { |
102 UConverter *cnv = args->converter; | 93 UConverter *cnv = args->converter; |
103 const unsigned char *mySource = (unsigned char *) args->source; | 94 const unsigned char *mySource = (unsigned char *) args->source; |
104 UChar *myTarget = args->target; | 95 UChar *myTarget = args->target; |
105 const unsigned char *sourceLimit = (unsigned char *) args->sourceLimit; | 96 const unsigned char *sourceLimit = (unsigned char *) args->sourceLimit; |
106 const UChar *targetLimit = args->targetLimit; | 97 const UChar *targetLimit = args->targetLimit; |
107 unsigned char *toUBytes = cnv->toUBytes; | 98 unsigned char *toUBytes = cnv->toUBytes; |
108 UBool isCESU8 = hasCESU8Data(cnv); | 99 UBool isCESU8 = (UBool)(cnv->sharedData == &_CESU8Data); |
109 uint32_t ch, ch2 = 0; | 100 uint32_t ch, ch2 = 0; |
110 int32_t i, inBytes; | 101 int32_t i, inBytes; |
111 | 102 |
112 /* Restore size of current sequence */ | 103 /* Restore size of current sequence */ |
113 if (cnv->toUnicodeStatus && myTarget < targetLimit) | 104 if (cnv->toUnicodeStatus && myTarget < targetLimit) |
114 { | 105 { |
115 inBytes = cnv->mode; /* restore # of bytes to consume */ | 106 inBytes = cnv->mode; /* restore # of bytes to consume */ |
116 i = cnv->toULength; /* restore # of bytes consumed */ | 107 i = cnv->toULength; /* restore # of bytes consumed */ |
117 cnv->toULength = 0; | 108 cnv->toULength = 0; |
118 | 109 |
119 ch = cnv->toUnicodeStatus;/*Stores the previously calculated ch from a p
revious call*/ | 110 ch = cnv->toUnicodeStatus;/*Stores the previously calculated ch from a p
revious call*/ |
120 cnv->toUnicodeStatus = 0; | 111 cnv->toUnicodeStatus = 0; |
121 goto morebytes; | 112 goto morebytes; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 UErrorCode * err) | 219 UErrorCode * err) |
229 { | 220 { |
230 UConverter *cnv = args->converter; | 221 UConverter *cnv = args->converter; |
231 const unsigned char *mySource = (unsigned char *) args->source; | 222 const unsigned char *mySource = (unsigned char *) args->source; |
232 UChar *myTarget = args->target; | 223 UChar *myTarget = args->target; |
233 int32_t *myOffsets = args->offsets; | 224 int32_t *myOffsets = args->offsets; |
234 int32_t offsetNum = 0; | 225 int32_t offsetNum = 0; |
235 const unsigned char *sourceLimit = (unsigned char *) args->sourceLimit; | 226 const unsigned char *sourceLimit = (unsigned char *) args->sourceLimit; |
236 const UChar *targetLimit = args->targetLimit; | 227 const UChar *targetLimit = args->targetLimit; |
237 unsigned char *toUBytes = cnv->toUBytes; | 228 unsigned char *toUBytes = cnv->toUBytes; |
238 UBool isCESU8 = hasCESU8Data(cnv); | 229 UBool isCESU8 = (UBool)(cnv->sharedData == &_CESU8Data); |
239 uint32_t ch, ch2 = 0; | 230 uint32_t ch, ch2 = 0; |
240 int32_t i, inBytes; | 231 int32_t i, inBytes; |
241 | 232 |
242 /* Restore size of current sequence */ | 233 /* Restore size of current sequence */ |
243 if (cnv->toUnicodeStatus && myTarget < targetLimit) | 234 if (cnv->toUnicodeStatus && myTarget < targetLimit) |
244 { | 235 { |
245 inBytes = cnv->mode; /* restore # of bytes to consume */ | 236 inBytes = cnv->mode; /* restore # of bytes to consume */ |
246 i = cnv->toULength; /* restore # of bytes consumed */ | 237 i = cnv->toULength; /* restore # of bytes consumed */ |
247 cnv->toULength = 0; | 238 cnv->toULength = 0; |
248 | 239 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 { | 350 { |
360 UConverter *cnv = args->converter; | 351 UConverter *cnv = args->converter; |
361 const UChar *mySource = args->source; | 352 const UChar *mySource = args->source; |
362 const UChar *sourceLimit = args->sourceLimit; | 353 const UChar *sourceLimit = args->sourceLimit; |
363 uint8_t *myTarget = (uint8_t *) args->target; | 354 uint8_t *myTarget = (uint8_t *) args->target; |
364 const uint8_t *targetLimit = (uint8_t *) args->targetLimit; | 355 const uint8_t *targetLimit = (uint8_t *) args->targetLimit; |
365 uint8_t *tempPtr; | 356 uint8_t *tempPtr; |
366 UChar32 ch; | 357 UChar32 ch; |
367 uint8_t tempBuf[4]; | 358 uint8_t tempBuf[4]; |
368 int32_t indexToWrite; | 359 int32_t indexToWrite; |
369 UBool isNotCESU8 = !hasCESU8Data(cnv); | 360 UBool isNotCESU8 = (UBool)(cnv->sharedData != &_CESU8Data); |
370 | 361 |
371 if (cnv->fromUChar32 && myTarget < targetLimit) | 362 if (cnv->fromUChar32 && myTarget < targetLimit) |
372 { | 363 { |
373 ch = cnv->fromUChar32; | 364 ch = cnv->fromUChar32; |
374 cnv->fromUChar32 = 0; | 365 cnv->fromUChar32 = 0; |
375 goto lowsurrogate; | 366 goto lowsurrogate; |
376 } | 367 } |
377 | 368 |
378 while (mySource < sourceLimit && myTarget < targetLimit) | 369 while (mySource < sourceLimit && myTarget < targetLimit) |
379 { | 370 { |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 const UChar *mySource = args->source; | 466 const UChar *mySource = args->source; |
476 int32_t *myOffsets = args->offsets; | 467 int32_t *myOffsets = args->offsets; |
477 const UChar *sourceLimit = args->sourceLimit; | 468 const UChar *sourceLimit = args->sourceLimit; |
478 uint8_t *myTarget = (uint8_t *) args->target; | 469 uint8_t *myTarget = (uint8_t *) args->target; |
479 const uint8_t *targetLimit = (uint8_t *) args->targetLimit; | 470 const uint8_t *targetLimit = (uint8_t *) args->targetLimit; |
480 uint8_t *tempPtr; | 471 uint8_t *tempPtr; |
481 UChar32 ch; | 472 UChar32 ch; |
482 int32_t offsetNum, nextSourceIndex; | 473 int32_t offsetNum, nextSourceIndex; |
483 int32_t indexToWrite; | 474 int32_t indexToWrite; |
484 uint8_t tempBuf[4]; | 475 uint8_t tempBuf[4]; |
485 UBool isNotCESU8 = !hasCESU8Data(cnv); | 476 UBool isNotCESU8 = (UBool)(cnv->sharedData != &_CESU8Data); |
486 | 477 |
487 if (cnv->fromUChar32 && myTarget < targetLimit) | 478 if (cnv->fromUChar32 && myTarget < targetLimit) |
488 { | 479 { |
489 ch = cnv->fromUChar32; | 480 ch = cnv->fromUChar32; |
490 cnv->fromUChar32 = 0; | 481 cnv->fromUChar32 = 0; |
491 offsetNum = -1; | 482 offsetNum = -1; |
492 nextSourceIndex = 0; | 483 nextSourceIndex = 0; |
493 goto lowsurrogate; | 484 goto lowsurrogate; |
494 } else { | 485 } else { |
495 offsetNum = 0; | 486 offsetNum = 0; |
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1086 }; | 1077 }; |
1087 | 1078 |
1088 | 1079 |
1089 const UConverterSharedData _CESU8Data={ | 1080 const UConverterSharedData _CESU8Data={ |
1090 sizeof(UConverterSharedData), ~((uint32_t) 0), | 1081 sizeof(UConverterSharedData), ~((uint32_t) 0), |
1091 NULL, NULL, &_CESU8StaticData, FALSE, &_CESU8Impl, | 1082 NULL, NULL, &_CESU8StaticData, FALSE, &_CESU8Impl, |
1092 0 | 1083 0 |
1093 }; | 1084 }; |
1094 | 1085 |
1095 #endif | 1086 #endif |
OLD | NEW |