X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=quote.c;h=ee7d62c751272f511d46894e5c5cd32e4403c721;hb=ba7545adab83e6bea43353937eabb467bcb7d4f7;hp=e3a4d4aef3478148ff89aebeba23e1cbf4202ba1;hpb=4405fb77f466ddd223b999d009a705601a90b0e6;p=git.git diff --git a/quote.c b/quote.c index e3a4d4aef..ee7d62c75 100644 --- a/quote.c +++ b/quote.c @@ -349,3 +349,41 @@ void write_name_quoted(const char *prefix, int prefix_len, else goto no_quote; } + +/* quoting as a string literal for other languages */ + +void perl_quote_print(FILE *stream, const char *src) +{ + const char sq = '\''; + const char bq = '\\'; + char c; + + fputc(sq, stream); + while ((c = *src++)) { + if (c == sq || c == bq) + fputc(bq, stream); + fputc(c, stream); + } + fputc(sq, stream); +} + +void python_quote_print(FILE *stream, const char *src) +{ + const char sq = '\''; + const char bq = '\\'; + const char nl = '\n'; + char c; + + fputc(sq, stream); + while ((c = *src++)) { + if (c == nl) { + fputc(bq, stream); + fputc('n', stream); + continue; + } + if (c == sq || c == bq) + fputc(bq, stream); + fputc(c, stream); + } + fputc(sq, stream); +}