Jonathan Nieder <jrnieder@xxxxxxxxx> writes: > +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. 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 ;-) > +`quote_two_c_style`:: > + Quote two paths (prefix + path) in C-style and concatenate them. > + One should use this instead of calling `quote_c_style` twice > + to avoid unsightly quotation marks in the middle. 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 happens so often that we have prefix and path as separate strings. > +`unquote_c_style`:: > + This unwraps what quote_c_style() produces in place, > + but returns -1 and doesn't touch if the input does not start with > + a double-quote or otherwise differs from what quote_c_style > + would have produced. Though note that this function will > + allocate memory in the strbuf, so calling `strbuf_release` > + is mandatory regardless of the result `unquote_c_style` returns. s/Though note/Note/ perhaps? > +Quoting for the shell > +--------------------- > + > +`sq_quote` copies its argument quoted for the shell safety. > +Any single quote is replaced with '\'', any exclamation point > +is replaced with '\!', and the whole thing is enclosed in a > +single-quote pair. > + > +For example, if you are passing the result to `system()` as an > +argument: "... 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. -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html