staticvoid outputChar(char c, char *outBuf, int32_t *outIx, int32_t capacity, int32_t indent) {
int32_t i; /* Check whether a start of line indenting is needed. Three cases: * 1. At the start of the first line (output index == 0). * 2. At the start of subsequent lines (preceding char in buffer == '\n') * 3. When preflighting buffer len (buffer capacity is exceeded), when * a \n is output. Ideally we wouldn't do the indent until the following char * is received, but that won't work because there's no place to remember that * the preceding char was \n. Meaning that we may overstimate the * buffer size needed. No harm done.
*/ if (*outIx==0 || /* case 1. */
(c!='\n' && c!=0 && *outIx < capacity && outBuf[(*outIx)-1]=='\n') || /* case 2. */
(c=='\n' && *outIx>=capacity)) /* case 3 */
{ /* At the start of a line. Indent. */ for(i=0; i<indent; i++) { if (*outIx < capacity) {
outBuf[*outIx] = ' ';
}
(*outIx)++;
}
}
if (*outIx < capacity) {
outBuf[*outIx] = c;
} if (c != 0) { /* NULs only appear as end-of-string terminators. Move them to the output * buffer, but do not update the length of the buffer, so that any
* following output will overwrite the NUL. */
(*outIx)++;
}
}
/* Output a pointer value in hex. Work with any size of pointer */ staticvoid outputPtrBytes(void *val, char *outBuf, int32_t *outIx, int32_t capacity) {
uint32_t i;
int32_t incVal = 1; /* +1 for big endian, -1 for little endian */ char* p = reinterpret_cast<char*>(&val); /* point to current byte to output in the ptr val */
#if !U_IS_BIG_ENDIAN /* Little Endian. Move p to most significant end of the value */
incVal = -1;
p += sizeof(void *) - 1; #endif
/* Loop through the bytes of the ptr as it sits in memory, from
* most significant to least significant end */ for (i=0; i<sizeof(void *); i++) {
outputHexBytes(*p, 2, outBuf, outIx, capacity);
p += incVal;
}
}
staticvoid outputString(constchar *s, char *outBuf, int32_t *outIx, int32_t capacity, int32_t indent) {
int32_t i = 0; char c; if (s==nullptr) {
s = "*NULL*";
} do {
c = s[i++];
outputChar(c, outBuf, outIx, capacity, indent);
} while (c != 0);
}
/* Loop runs once for each character in the format string.
*/ for (;;) {
fmtC = fmt[fmtIx++]; if (fmtC != '%') { /* Literal character, not part of a %sequence. Just copy it to the output. */
outputChar(fmtC, outBuf, &outIx, capacity, indent); if (fmtC == 0) { /* We hit the NUL that terminates the format string. * This is the normal (and only) exit from the loop that * interprets the format
*/ break;
} continue;
}
/* We encountered a '%'. Pick up the following format char */
fmtC = fmt[fmtIx++];
switch (fmtC) { case'c': /* single 8 bit char */
c = (char)va_arg(args, int32_t);
outputChar(c, outBuf, &outIx, capacity, indent); break;
case 0: /* Single '%' at end of fmt string. Output as literal '%'. * Back up index into format string so that the terminating NUL will be * re-fetched in the outer loop, causing it to terminate.
*/
outputChar('%', outBuf, &outIx, capacity, indent);
fmtIx--; break;
default: /* %. in format string, where . is some character not in the set * of recognized format chars. Just output it as if % wasn't there. * (Covers "%%" outputting a single '%')
*/
outputChar(fmtC, outBuf, &outIx, capacity, indent);
}
}
outputChar(0, outBuf, &outIx, capacity, indent); /* Make sure that output is NUL terminated */ return outIx + 1; /* outIx + 1 because outIx does not increment when outputting final NUL. */
}
¤ 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.0.2Bemerkung:
(vorverarbeitet)
¤
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.