Mercurial > hg > sidinfo
diff sidinfo.c @ 316:b0c844b39516
Move and rename siEscapeString() to sidutil_escape_string() and
siPrintStrEscapes() to sidutil_print_string_escaped().
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 11 Jan 2020 18:34:34 +0200 |
parents | 67392d7ef391 |
children | f3ba2ba894b1 |
line wrap: on
line diff
--- a/sidinfo.c Sat Jan 11 18:31:15 2020 +0200 +++ b/sidinfo.c Sat Jan 11 18:34:34 2020 +0200 @@ -699,65 +699,6 @@ } -static char * siEscapeString(const char *str, const char *esc) -{ - size_t len, size; - char *buf; - - if (str == NULL) - return NULL; - - if (esc == NULL) - return th_strdup(str); - - size = strlen(str) + 1; - if ((buf = th_malloc(size)) == NULL) - return NULL; - - for (len = 0; *str; str++) - { - if (strchr(esc, *str) != NULL || *str == '\\') - { - if (!th_strbuf_putch(&buf, &size, &len, '\\')) - goto err; - } - - if (!th_strbuf_putch(&buf, &size, &len, *str)) - goto err; - } - - if (!th_strbuf_putch(&buf, &size, &len, 0)) - goto err; - - return buf; - -err: - th_free(buf); - return NULL; -} - - -static void siPrintStrEscapes(FILE *outFile, const char *str) -{ - while (*str) - { - if (*str == '\\') - switch (*(++str)) - { - case 'n': fputc('\n', outFile); break; - case 'r': fputc('\r', outFile); break; - case 't': fputc('\r', outFile); break; - case '\\': fputc('\\', outFile); break; - default: fputc(*str, outFile); break; - } - else - fputc(*str, outFile); - - str++; - } -} - - static void siPrintFieldPrefixName(FILE *outFile, const char *name, const BOOL multifield) { if (optFieldNamePrefix) @@ -821,11 +762,11 @@ if (d_str != NULL && setChConv.enabled && convert) { char *tmp2 = sidutil_chconv_convert(&setChConv, d_str); - tmp = siEscapeString(tmp2, optEscapeChars); + tmp = sidutil_escape_string(tmp2, optEscapeChars); th_free(tmp2); } else - tmp = siEscapeString(d_str, optEscapeChars); + tmp = sidutil_escape_string(d_str, optEscapeChars); if ((str = siItemFormatStrPrint(fmt, otype, tmp, d_int)) != NULL) fputs(str, outFile); @@ -1074,7 +1015,7 @@ switch (item->cmd) { case -1: - siPrintStrEscapes(outFile, item->str); + sidutil_print_string_escaped(outFile, item->str); break; case -2: