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.Atthestartofthefirstline(outputindex==0). *2.Atthestartofsubsequentlines(precedingcharinbuffer=='\n') *3.Whenpreflightingbufferlen(buffercapacityisexceeded),when *a\nisoutput.Ideallywewouldn'tdotheindentuntilthefollowingchar *isreceived,butthatwon'tworkbecausethere'snoplacetorememberthat *theprecedingcharwas\n.Meaningthatwemayoverstimatethe *buffersizeneeded.Noharmdone.
*/
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,butdonotupdatethelengthofthebuffer,sothatany
* 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(const char *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. *Thisisthenormal(andonly)exitfromtheloopthat *interpretstheformat
*/ 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;
case0: /* Single '%' at end of fmt string. Output as literal '%'. *BackupindexintoformatstringsothattheterminatingNULwillbe *re-fetchedintheouterloop,causingittoterminate.
*/
outputChar('%', outBuf, &outIx, capacity, indent);
fmtIx--; break;
default: /* %. in format string, where . is some character not in the set *ofrecognizedformatchars.Justoutputitasif%wasn'tthere. *(Covers"%%"outputtingasingle'%')
*/
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.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.