summaryrefslogtreecommitdiff
path: root/quote.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2006-09-15 20:30:02 (GMT)
committerJunio C Hamano <junkio@cox.net>2006-09-16 17:22:02 (GMT)
commit9f613ddd21cbd05bfc139d9b1551b5780aa171f6 (patch)
tree047f4e4562a81d7719c5c33b56aefb1a22f9ec70 /quote.c
parente7676d2f6454c9c99e600ee2ce3c7205a9fcfb5f (diff)
downloadgit-9f613ddd21cbd05bfc139d9b1551b5780aa171f6.zip
git-9f613ddd21cbd05bfc139d9b1551b5780aa171f6.tar.gz
git-9f613ddd21cbd05bfc139d9b1551b5780aa171f6.tar.bz2
Add git-for-each-ref: helper for language bindings
This adds a new command, git-for-each-ref. You can have it iterate over refs and have it output various aspects of the objects they refer to. Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'quote.c')
-rw-r--r--quote.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/quote.c b/quote.c
index e3a4d4a..ee7d62c 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);
+}