/* need to update the offsets when the target moves. */ /* Note: Recursion may occur in the cb functions, be sure to update the offsets correctly if you don't use ucnv_cbXXX functions. Make sure you don't use the same callback within
the same call stack if the complexity arises. */
U_CAPI void U_EXPORT2
ucnv_cbFromUWriteBytes (UConverterFromUnicodeArgs *args, constchar* source,
int32_t length,
int32_t offsetIndex,
UErrorCode * err)
{ if(U_FAILURE(*err)) { return;
}
U_CAPI void U_EXPORT2
ucnv_cbFromUWriteUChars(UConverterFromUnicodeArgs *args, const char16_t** source, const char16_t* sourceLimit,
int32_t offsetIndex,
UErrorCode * err)
{ /* This is a fun one. Recursion can occur - we're basically going to just retry shoving data through the same converter. Note, if you got here through some kind of invalid sequence, you maybe should emit a reset sequence of some kind and/or call ucnv_reset(). Since this IS an actual conversion, take care that you've changed the callback or the data, or you'll get an infinite loop.
Please set the err value to something reasonable before calling into this.
*/
char *oldTarget;
if(U_FAILURE(*err))
{ return;
}
oldTarget = args->target;
ucnv_fromUnicode(args->converter,
&args->target,
args->targetLimit,
source,
sourceLimit,
nullptr, /* no offsets */ false, /* no flush */
err);
if(args->offsets)
{ while (args->target != oldTarget) /* if it moved at all.. */
{
*(args->offsets)++ = offsetIndex;
oldTarget++;
}
}
/* Note, if you did something like used a Stop subcallback, things would get interesting. In fact, here's where we want to return the partially consumed in-source!
*/ if(*err == U_BUFFER_OVERFLOW_ERROR) /* && (*source < sourceLimit && args->target >= args->targetLimit)
-- S. Hrcek */
{ /* Overflowed the target. Now, we'll write into the charErrorBuffer.
It's a fixed size. If we overflow it... Hmm */ char *newTarget; constchar *newTargetLimit;
UErrorCode err2 = U_ZERO_ERROR;
/* We're going to tell the converter that the errbuff len is empty. This prevents the existing errbuff from being 'flushed' out onto itself. If the errbuff is needed by the converter this time,
we're hosed - we're out of space! */
if((newTarget >= newTargetLimit) || (err2 == U_BUFFER_OVERFLOW_ERROR))
{ /* now we're REALLY in trouble. Internal program error - callback shouldn't have written this much data!
*/
*err = U_INTERNAL_PROGRAM_ERROR; return;
} /*else {*/ /* sub errs could be invalid/truncated/illegal chars or w/e. These might want to be passed on up.. But the problem is, we already need to pass U_BUFFER_OVERFLOW_ERROR. That has to override these
other errs.. */
if(length < 0) { /* * Write/convert the substitution string. Its real length is -length. * Unlike the escape callback, we need not change the converter's * callback function because ucnv_setSubstString() verified that * the string can be converted, so we will not get a conversion error * and will not recurse. * At worst we should get a U_BUFFER_OVERFLOW_ERROR.
*/ const char16_t *source = (const char16_t *)converter->subChars;
ucnv_cbFromUWriteUChars(args, &source, source - length, offsetIndex, err); return;
}
if(converter->sharedData->impl->writeSub!=nullptr) {
converter->sharedData->impl->writeSub(args, offsetIndex, err);
} elseif(converter->subChar1!=0 && (uint16_t)converter->invalidUCharBuffer[0]<=(uint16_t)0xffu) { /* TODO: Is this untestable because the MBCS converter has a writeSub function to call and the other converters don't use subChar1?
*/
ucnv_cbFromUWriteBytes(args,
(constchar *)&converter->subChar1, 1,
offsetIndex, err);
} else {
ucnv_cbFromUWriteBytes(args,
(constchar *)converter->subChars, length,
offsetIndex, err);
}
}
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.