/* Restore state of current sequence */ if (args->converter->toULength > 0 && myTarget < targetLimit) {
i = args->converter->toULength; /* restore # of bytes consumed */
args->converter->toULength = 0;
ch = args->converter->toUnicodeStatus - 1;/*Stores the previously calculated ch from a previous call*/
args->converter->toUnicodeStatus = 0; goto morebytes;
}
while (mySource < sourceLimit && myTarget < targetLimit) {
i = 0;
ch = 0;
morebytes: while (i < sizeof(uint32_t)) { if (mySource < sourceLimit) {
ch = (ch << 8) | (uint8_t)(*mySource);
toUBytes[i++] = (char) *(mySource++);
} else { /* stores a partially calculated target*/ /* + 1 to make 0 a valid character */
args->converter->toUnicodeStatus = ch + 1;
args->converter->toULength = (int8_t) i; goto donefornow;
}
}
if (ch <= MAXIMUM_UTF && !U_IS_SURROGATE(ch)) { /* Normal valid byte when the loop has not prematurely terminated (i < inBytes) */ if (ch <= MAXIMUM_UCS2)
{ /* fits in 16 bits */
*(myTarget++) = (char16_t) ch;
} else { /* write out the surrogates */
*(myTarget++) = U16_LEAD(ch);
ch = U16_TRAIL(ch); if (myTarget < targetLimit) {
*(myTarget++) = (char16_t)ch;
} else { /* Put in overflow buffer (not handled here) */
args->converter->UCharErrorBuffer[0] = (char16_t) ch;
args->converter->UCharErrorBufferLength = 1;
*err = U_BUFFER_OVERFLOW_ERROR; break;
}
}
} else {
args->converter->toULength = (int8_t)i;
*err = U_ILLEGAL_CHAR_FOUND; break;
}
}
donefornow: if (mySource < sourceLimit && myTarget >= targetLimit && U_SUCCESS(*err)) { /* End of target buffer */
*err = U_BUFFER_OVERFLOW_ERROR;
}
/* Restore state of current sequence */ if (args->converter->toULength > 0 && myTarget < targetLimit) {
i = args->converter->toULength; /* restore # of bytes consumed */
args->converter->toULength = 0;
ch = args->converter->toUnicodeStatus - 1;/*Stores the previously calculated ch from a previous call*/
args->converter->toUnicodeStatus = 0; goto morebytes;
}
while (mySource < sourceLimit && myTarget < targetLimit) {
i = 0;
ch = 0;
morebytes: while (i < sizeof(uint32_t)) { if (mySource < sourceLimit) {
ch = (ch << 8) | (uint8_t)(*mySource);
toUBytes[i++] = (char) *(mySource++);
} else { /* stores a partially calculated target*/ /* + 1 to make 0 a valid character */
args->converter->toUnicodeStatus = ch + 1;
args->converter->toULength = (int8_t) i; goto donefornow;
}
}
if (ch <= MAXIMUM_UTF && !U_IS_SURROGATE(ch)) { /* Normal valid byte when the loop has not prematurely terminated (i < inBytes) */ if (ch <= MAXIMUM_UCS2) { /* fits in 16 bits */
*(myTarget++) = (char16_t) ch;
*(myOffsets++) = offsetNum;
} else { /* write out the surrogates */
*(myTarget++) = U16_LEAD(ch);
*myOffsets++ = offsetNum;
ch = U16_TRAIL(ch); if (myTarget < targetLimit)
{
*(myTarget++) = (char16_t)ch;
*(myOffsets++) = offsetNum;
} else { /* Put in overflow buffer (not handled here) */
args->converter->UCharErrorBuffer[0] = (char16_t) ch;
args->converter->UCharErrorBufferLength = 1;
*err = U_BUFFER_OVERFLOW_ERROR; break;
}
}
} else {
args->converter->toULength = (int8_t)i;
*err = U_ILLEGAL_CHAR_FOUND; break;
}
offsetNum += i;
}
donefornow: if (mySource < sourceLimit && myTarget >= targetLimit && U_SUCCESS(*err))
{ /* End of target buffer */
*err = U_BUFFER_OVERFLOW_ERROR;
}
/* Don't even try to do a direct cast because the value may be on an odd address. */
myUChar = ((UChar32)mySource[0] << 24)
| ((UChar32)mySource[1] << 16)
| ((UChar32)mySource[2] << 8)
| ((UChar32)mySource[3]);
/* Restore state of current sequence */ if (args->converter->toULength > 0 && myTarget < targetLimit)
{
i = args->converter->toULength; /* restore # of bytes consumed */
args->converter->toULength = 0;
/* Stores the previously calculated ch from a previous call*/
ch = args->converter->toUnicodeStatus - 1;
args->converter->toUnicodeStatus = 0; goto morebytes;
}
while (mySource < sourceLimit && myTarget < targetLimit)
{
i = 0;
ch = 0;
morebytes: while (i < sizeof(uint32_t))
{ if (mySource < sourceLimit)
{
ch |= ((uint8_t)(*mySource)) << (i * 8);
toUBytes[i++] = (char) *(mySource++);
} else
{ /* stores a partially calculated target*/ /* + 1 to make 0 a valid character */
args->converter->toUnicodeStatus = ch + 1;
args->converter->toULength = (int8_t) i; goto donefornow;
}
}
if (ch <= MAXIMUM_UTF && !U_IS_SURROGATE(ch)) { /* Normal valid byte when the loop has not prematurely terminated (i < inBytes) */ if (ch <= MAXIMUM_UCS2) { /* fits in 16 bits */
*(myTarget++) = (char16_t) ch;
} else { /* write out the surrogates */
*(myTarget++) = U16_LEAD(ch);
ch = U16_TRAIL(ch); if (myTarget < targetLimit) {
*(myTarget++) = (char16_t)ch;
} else { /* Put in overflow buffer (not handled here) */
args->converter->UCharErrorBuffer[0] = (char16_t) ch;
args->converter->UCharErrorBufferLength = 1;
*err = U_BUFFER_OVERFLOW_ERROR; break;
}
}
} else {
args->converter->toULength = (int8_t)i;
*err = U_ILLEGAL_CHAR_FOUND; break;
}
}
donefornow: if (mySource < sourceLimit && myTarget >= targetLimit && U_SUCCESS(*err))
{ /* End of target buffer */
*err = U_BUFFER_OVERFLOW_ERROR;
}
/* Restore state of current sequence */ if (args->converter->toULength > 0 && myTarget < targetLimit)
{
i = args->converter->toULength; /* restore # of bytes consumed */
args->converter->toULength = 0;
/* Stores the previously calculated ch from a previous call*/
ch = args->converter->toUnicodeStatus - 1;
args->converter->toUnicodeStatus = 0; goto morebytes;
}
while (mySource < sourceLimit && myTarget < targetLimit)
{
i = 0;
ch = 0;
morebytes: while (i < sizeof(uint32_t))
{ if (mySource < sourceLimit)
{
ch |= ((uint8_t)(*mySource)) << (i * 8);
toUBytes[i++] = (char) *(mySource++);
} else
{ /* stores a partially calculated target*/ /* + 1 to make 0 a valid character */
args->converter->toUnicodeStatus = ch + 1;
args->converter->toULength = (int8_t) i; goto donefornow;
}
}
if (ch <= MAXIMUM_UTF && !U_IS_SURROGATE(ch))
{ /* Normal valid byte when the loop has not prematurely terminated (i < inBytes) */ if (ch <= MAXIMUM_UCS2)
{ /* fits in 16 bits */
*(myTarget++) = (char16_t) ch;
*(myOffsets++) = offsetNum;
} else { /* write out the surrogates */
*(myTarget++) = U16_LEAD(ch);
*(myOffsets++) = offsetNum;
ch = U16_TRAIL(ch); if (myTarget < targetLimit)
{
*(myTarget++) = (char16_t)ch;
*(myOffsets++) = offsetNum;
} else
{ /* Put in overflow buffer (not handled here) */
args->converter->UCharErrorBuffer[0] = (char16_t) ch;
args->converter->UCharErrorBufferLength = 1;
*err = U_BUFFER_OVERFLOW_ERROR; break;
}
}
} else
{
args->converter->toULength = (int8_t)i;
*err = U_ILLEGAL_CHAR_FOUND; break;
}
offsetNum += i;
}
donefornow: if (mySource < sourceLimit && myTarget >= targetLimit && U_SUCCESS(*err))
{ /* End of target buffer */
*err = U_BUFFER_OVERFLOW_ERROR;
}
/* Don't even try to do a direct cast because the value may be on an odd address. */
myUChar = ((UChar32)mySource[3] << 24)
| ((UChar32)mySource[2] << 16)
| ((UChar32)mySource[1] << 8)
| ((UChar32)mySource[0]);
/* * If we detect a BOM in this buffer, then we must add the BOM size to the * offsets because the actual converter function will not see and count the BOM. * offsetDelta will have the number of the BOM bytes that are in the current buffer.
*/
offsetDelta=0;
while(source<sourceLimit && U_SUCCESS(*pErrorCode)) { switch(state) { case 0:
b=*source; if(b==0) {
state=1; /* could be 00 00 FE FF */
} elseif(b==(char)0xffu) {
state=5; /* could be FF FE 00 00 */
} else {
state=8; /* default to UTF-32BE */ continue;
}
++source; break; case 1: case 2: case 3: case 5: case 6: case 7: if(*source==utf32BOM[state]) {
++state;
++source; if(state==4) {
state=8; /* detect UTF-32BE */
offsetDelta=(int32_t)(source-pArgs->source);
} elseif(state==8) {
state=9; /* detect UTF-32LE */
offsetDelta=(int32_t)(source-pArgs->source);
}
} else { /* switch to UTF-32BE and pass the previous bytes */
int32_t count=(int32_t)(source-pArgs->source); /* number of bytes from this buffer */
/* reset the source */
source=pArgs->source;
if(count==(state&3)) { /* simple: all in the same buffer, just reset source */
} else {
UBool oldFlush=pArgs->flush;
/* some of the bytes are from a previous buffer, replay those first */
pArgs->source=utf32BOM+(state&4); /* select the correct BOM */
pArgs->sourceLimit=pArgs->source+((state&3)-count); /* replay previous bytes */
pArgs->flush=false; /* this sourceLimit is not the real source stream limit */
/* no offsets: bytes from previous buffer, and not enough for output */
T_UConverter_toUnicode_UTF32_BE(pArgs, pErrorCode);
/* restore real pointers; pArgs->source will be set in case 8/9 */
pArgs->sourceLimit=sourceLimit;
pArgs->flush=oldFlush;
}
state=8; continue;
} break; case 8: /* call UTF-32BE */
pArgs->source=source; if(offsets==nullptr) {
T_UConverter_toUnicode_UTF32_BE(pArgs, pErrorCode);
} else {
T_UConverter_toUnicode_UTF32_BE_OFFSET_LOGIC(pArgs, pErrorCode);
}
source=pArgs->source; break; case 9: /* call UTF-32LE */
pArgs->source=source; if(offsets==nullptr) {
T_UConverter_toUnicode_UTF32_LE(pArgs, pErrorCode);
} else {
T_UConverter_toUnicode_UTF32_LE_OFFSET_LOGIC(pArgs, pErrorCode);
}
source=pArgs->source; break; default: break; /* does not occur */
}
}
/* add BOM size to offsets - see comment at offsetDelta declaration */ if(offsets!=nullptr && offsetDelta!=0) {
int32_t *offsetsLimit=pArgs->offsets; while(offsets<offsetsLimit) {
*offsets++ += offsetDelta;
}
}
pArgs->source=source;
if(source==sourceLimit && pArgs->flush) { /* handle truncated input */ switch(state) { case 0: break; /* no input at all, nothing to do */ case 8:
T_UConverter_toUnicode_UTF32_BE(pArgs, pErrorCode); break; case 9:
T_UConverter_toUnicode_UTF32_LE(pArgs, pErrorCode); break; default: /* handle 0<state<8: call UTF-32BE with too-short input */
pArgs->source=utf32BOM+(state&4); /* select the correct BOM */
pArgs->sourceLimit=pArgs->source+(state&3); /* replay bytes */
/* no offsets: not enough for output */
T_UConverter_toUnicode_UTF32_BE(pArgs, pErrorCode);
pArgs->source=source;
pArgs->sourceLimit=sourceLimit;
state=8; 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.