|
|
|
@ -42,23 +42,6 @@ void sq_quote_buf(struct strbuf *dst, const char *src)
@@ -42,23 +42,6 @@ void sq_quote_buf(struct strbuf *dst, const char *src)
|
|
|
|
|
free(to_free); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void sq_quote_print(FILE *stream, const char *src) |
|
|
|
|
{ |
|
|
|
|
char c; |
|
|
|
|
|
|
|
|
|
fputc('\'', stream); |
|
|
|
|
while ((c = *src++)) { |
|
|
|
|
if (need_bs_quote(c)) { |
|
|
|
|
fputs("'\\", stream); |
|
|
|
|
fputc(c, stream); |
|
|
|
|
fputc('\'', stream); |
|
|
|
|
} else { |
|
|
|
|
fputc(c, stream); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
fputc('\'', stream); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void sq_quote_argv(struct strbuf *dst, const char** argv, size_t maxlen) |
|
|
|
|
{ |
|
|
|
|
int i; |
|
|
|
@ -408,72 +391,72 @@ int unquote_c_style(struct strbuf *sb, const char *quoted, const char **endp)
@@ -408,72 +391,72 @@ int unquote_c_style(struct strbuf *sb, const char *quoted, const char **endp)
|
|
|
|
|
|
|
|
|
|
/* quoting as a string literal for other languages */ |
|
|
|
|
|
|
|
|
|
void perl_quote_print(FILE *stream, const char *src) |
|
|
|
|
void perl_quote_buf(struct strbuf *sb, const char *src) |
|
|
|
|
{ |
|
|
|
|
const char sq = '\''; |
|
|
|
|
const char bq = '\\'; |
|
|
|
|
char c; |
|
|
|
|
|
|
|
|
|
fputc(sq, stream); |
|
|
|
|
strbuf_addch(sb, sq); |
|
|
|
|
while ((c = *src++)) { |
|
|
|
|
if (c == sq || c == bq) |
|
|
|
|
fputc(bq, stream); |
|
|
|
|
fputc(c, stream); |
|
|
|
|
strbuf_addch(sb, bq); |
|
|
|
|
strbuf_addch(sb, c); |
|
|
|
|
} |
|
|
|
|
fputc(sq, stream); |
|
|
|
|
strbuf_addch(sb, sq); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void python_quote_print(FILE *stream, const char *src) |
|
|
|
|
void python_quote_buf(struct strbuf *sb, const char *src) |
|
|
|
|
{ |
|
|
|
|
const char sq = '\''; |
|
|
|
|
const char bq = '\\'; |
|
|
|
|
const char nl = '\n'; |
|
|
|
|
char c; |
|
|
|
|
|
|
|
|
|
fputc(sq, stream); |
|
|
|
|
strbuf_addch(sb, sq); |
|
|
|
|
while ((c = *src++)) { |
|
|
|
|
if (c == nl) { |
|
|
|
|
fputc(bq, stream); |
|
|
|
|
fputc('n', stream); |
|
|
|
|
strbuf_addch(sb, bq); |
|
|
|
|
strbuf_addch(sb, 'n'); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
if (c == sq || c == bq) |
|
|
|
|
fputc(bq, stream); |
|
|
|
|
fputc(c, stream); |
|
|
|
|
strbuf_addch(sb, bq); |
|
|
|
|
strbuf_addch(sb, c); |
|
|
|
|
} |
|
|
|
|
fputc(sq, stream); |
|
|
|
|
strbuf_addch(sb, sq); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void tcl_quote_print(FILE *stream, const char *src) |
|
|
|
|
void tcl_quote_buf(struct strbuf *sb, const char *src) |
|
|
|
|
{ |
|
|
|
|
char c; |
|
|
|
|
|
|
|
|
|
fputc('"', stream); |
|
|
|
|
strbuf_addch(sb, '"'); |
|
|
|
|
while ((c = *src++)) { |
|
|
|
|
switch (c) { |
|
|
|
|
case '[': case ']': |
|
|
|
|
case '{': case '}': |
|
|
|
|
case '$': case '\\': case '"': |
|
|
|
|
fputc('\\', stream); |
|
|
|
|
strbuf_addch(sb, '\\'); |
|
|
|
|
default: |
|
|
|
|
fputc(c, stream); |
|
|
|
|
strbuf_addch(sb, c); |
|
|
|
|
break; |
|
|
|
|
case '\f': |
|
|
|
|
fputs("\\f", stream); |
|
|
|
|
strbuf_addstr(sb, "\\f"); |
|
|
|
|
break; |
|
|
|
|
case '\r': |
|
|
|
|
fputs("\\r", stream); |
|
|
|
|
strbuf_addstr(sb, "\\r"); |
|
|
|
|
break; |
|
|
|
|
case '\n': |
|
|
|
|
fputs("\\n", stream); |
|
|
|
|
strbuf_addstr(sb, "\\n"); |
|
|
|
|
break; |
|
|
|
|
case '\t': |
|
|
|
|
fputs("\\t", stream); |
|
|
|
|
strbuf_addstr(sb, "\\t"); |
|
|
|
|
break; |
|
|
|
|
case '\v': |
|
|
|
|
fputs("\\v", stream); |
|
|
|
|
strbuf_addstr(sb, "\\v"); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
fputc('"', stream); |
|
|
|
|
strbuf_addch(sb, '"'); |
|
|
|
|
} |
|
|
|
|