vty: Simplify char escaping in asciidoc output

Change-Id: I7df6858bb98abffc1d5bf420f991ae5854b24638
This commit is contained in:
Pau Espin 2019-06-19 14:55:45 +02:00 committed by pespin
parent 28a198f9c0
commit e1e1ec31a3
1 changed files with 4 additions and 9 deletions

View File

@ -515,7 +515,7 @@ char *osmo_asciidoc_escape(const char *inp)
{ {
int _strlen; int _strlen;
char *out, *out_ptr; char *out, *out_ptr;
int len = 0, i, j; int len = 0, i;
if (!inp) if (!inp)
return NULL; return NULL;
@ -538,23 +538,18 @@ char *osmo_asciidoc_escape(const char *inp)
out_ptr = out; out_ptr = out;
#define ADD(out, str) \
for (j = 0; j < strlen(str); ++j) \
*(out++) = str[j];
for (i = 0; i < _strlen; ++i) { for (i = 0; i < _strlen; ++i) {
switch (inp[i]) { switch (inp[i]) {
case '|': case '|':
ADD(out_ptr, "\\|"); /* Prepend escape character "\": */
break; *(out_ptr++) = '\\';
/* fall through */
default: default:
*(out_ptr++) = inp[i]; *(out_ptr++) = inp[i];
break; break;
} }
} }
#undef ADD
out_ptr[0] = '\0'; out_ptr[0] = '\0';
return out; return out;
} }