MCPcopy Create free account
hub / github.com/dillo-browser/dillo / dStr_printable

Function dStr_printable

dlib/dlib.c:513–539  ·  view source on GitHub ↗

* Return a printable representation of the provided Dstr, limited to a length * of roughly maxlen. * * This is NOT threadsafe. */

Source from the content-addressed store, hash-verified

511 * This is NOT threadsafe.
512 */
513const char *dStr_printable(Dstr *in, int maxlen)
514{
515 int i;
516 static const char *const HEX = "0123456789ABCDEF";
517 static Dstr *out = NULL;
518
519 if (in == NULL)
520 return NULL;
521
522 if (out)
523 dStr_truncate(out, 0);
524 else
525 out = dStr_sized_new(in->len);
526
527 for (i = 0; (i < in->len) && (out->len < maxlen); ++i) {
528 if (isprint(in->str[i]) || (in->str[i] == '\n')) {
529 dStr_append_c(out, in->str[i]);
530 } else {
531 dStr_append_l(out, "\\x", 2);
532 dStr_append_c(out, HEX[(in->str[i] >> 4) & 15]);
533 dStr_append_c(out, HEX[in->str[i] & 15]);
534 }
535 }
536 if (out->len >= maxlen)
537 dStr_append(out, "...");
538 return out->str;
539}
540
541/*
542 *- dList ---------------------------------------------------------------------

Callers 3

a_IO_cccFunction · 0.85
Http_make_query_strFunction · 0.85

Calls 5

dStr_truncateFunction · 0.85
dStr_sized_newFunction · 0.85
dStr_append_cFunction · 0.85
dStr_append_lFunction · 0.85
dStr_appendFunction · 0.85

Tested by

no test coverage detected