Re: [RFC/PATCH] Documentation/technical: document quoting API

Previous thread: gitattributes don't work by Marcin =?iso-8859-2?q?Wi=B6nicki?= on Sunday, January 2, 2011 - 5:42 pm. (5 messages)

Next thread: Stashing subset of changed file plus a new file by Zivkov, Sasa on Monday, January 3, 2011 - 7:05 am. (1 message)
From: Jonathan Nieder
Date: Sunday, January 2, 2011 - 11:35 pm

Briefly explain the zoo of quoting functions.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
This is just a starting point, I fear.  Not even compile-tested.
Problems:

 - not very brief
 - not a great overview

But I was happy to have the chance to read through the available
functions.

Suggestions and other improvements welcome.

 Documentation/technical/api-quote.txt |  124 ++++++++++++++++++++++++++++++---
 quote.h                               |   14 ++--
 2 files changed, 121 insertions(+), 17 deletions(-)
 rewrite Documentation/technical/api-quote.txt (84%)

diff --git a/Documentation/technical/api-quote.txt b/Documentation/technical/api-quote.txt
dissimilarity index 84%
index e8a1bce..18da370 100644
--- a/Documentation/technical/api-quote.txt
+++ b/Documentation/technical/api-quote.txt
@@ -1,10 +1,114 @@
-quote API
-=========
-
-Talk about <quote.h>, things like
-
-* sq_quote and unquote
-* c_style quote and unquote
-* quoting for foreign languages
-
-(JC)
+quote API
+=========
+
+The quoting API can be used to replace unusual characters for
+shell safety or for output readability and parseability.
+It also can be used to perform the inverse operation and recover
+the unusual characters again.
+
+C-style quoting
+---------------
+
+`quote_c_style` quotes a string in a manner that might be familiar
+to C programmers.  This can be used to quote newlines and tabs in
+filenames for patches, for example.
+
+. if sb and fp are both NULL, it returns the number of bytes needed
+  to hold the quoted version of "name", counting the double quotes
+  around it but not terminating NUL.  If "name" does not need quoting,
+  it returns 0.
+
+. otherwise, it emits the quoted version of "name" to a stream,
+  strbuf, or both.  Output will have enclosing double quotes
+  suppressed if requested with the "no_dq" parameter.
+
+`quote_two_c_style`::
+	Quote two paths (prefix + path) in C-style and concatenate them.
+	One should use this instead of ...
From: Nguyen Thai Ngoc Duy
Date: Monday, January 3, 2011 - 12:39 am

I rarely read these documents. One of the reasons is sometimes I don't
know such document exists. Can we put a pointer to the document in
quote.h? I assume that anyone who wants to use these will at least
look at quote.h first.
-- 
Duy
--

From: Junio C Hamano
Date: Tuesday, January 4, 2011 - 12:21 pm

Heh, I didn't know about the "both" case.  That is probably unintended
misfeature that would not hurt but would not be useful in practice either

Just for the record, "Avoid dqdq in the middle" was never the motivation;
you can run two no_dq invocations and put dq around the result yourself.
The main motivation for using this, before the strbuf was widely used, was
to avoid having to allocate memory only to call quote_c_style, because it


"... if you are preparing a command line to give to `system(3)`"?

I first misread the above and thought you were doing some operation on the
result coming back from "system()", which of course is nonsensical and not
what you meant.

Thanks.
--

Previous thread: gitattributes don't work by Marcin =?iso-8859-2?q?Wi=B6nicki?= on Sunday, January 2, 2011 - 5:42 pm. (5 messages)

Next thread: Stashing subset of changed file plus a new file by Zivkov, Sasa on Monday, January 3, 2011 - 7:05 am. (1 message)