|
From: Juergen W. <wie...@fr...> - 2005-11-15 19:27:07
|
On Monday 14 November 2005 20:05 Ethan Merritt wrote:
> On Monday 14 November 2005 10:00 am, Juergen Wieferink wrote:
> > As a small excuse for the mostly pointless discussion I've caused,
> > I've prepared a small patch which should switch to a more intuitive
> > behaviour. Maybe the docs could be clarified accordingly.
>
> But this breaks the ability to embed quotes:
>
> gnuplot> a = "foo\"bar"
> gnuplot> print a
> foo"bar
> gnuplot> b = 'foo\'bar'
> ^
> ';' expected
>
>
> This is particularly a problem is you are constructing, say,
> unix shell command lines to pass to a system() call.
> There really needs to be a way to escape quote characters.
I tend to disagree. The main advantage of 'these strings' (like
they are understood by the majority) compared to "these" is that
backslashes don't have a special meaning and can be easily used.
The drawback is the unavailability of certain characters ('\n', '\t'
'\r', octal codes, and '\''). With your approach, you have to
resort to double quoted strings just to be able to have a trailing
backslash. And this is what is meant to be especially easy using
single quotes.
> The other common convention is to repeat the quote character:
>
> c = 'foo''bar'
>
> but that convention is not so far used anywhere in gnuplot.
FYI: The *bash* implements the single quotes much the same way as my
yesterday patch does: no special meaning of backslashes at all.
"man bash":
Enclosing characters in single quotes preserves the literal value of
each character within the quotes. A single quote may not occur between
single quotes, even when preceded by a backslash.
*Perl* seems to work very much like you suggested. "man perldata":
String literals are usually delimited by either single or double
quotes. They work much like quotes in the standard Unix shells: dou-
ble-quoted string literals are subject to backslash and variable sub-
stitution; single-quoted strings are not (except for "\'" and "\\").
In *Python* it does not make any difference which type of quotes are
used (apart from the correct closing). But if the string is
prefixed with the letter 'r', it is a so called "raw string",
working exactly (except auto closing) like it used to in gnuplot.
"Python Reference Manual, Sec 2.4.1":
When an "r" or "R" prefix is present, a character following a
backslash is included in the string without change, and all
backslashes are left in the string. For example, the string
literal r"\n" consists of two characters: a backslash and a
lowercase "n". String quotes can be escaped with a backslash,
but the backslash remains in the string; for example, r"\""
is a valid string literal consisting of two characters: a
backslash and a double quote; r"\" is not a valid string
literal (even a raw string cannot end in an odd number of
backslashes). Specifically, a raw string cannot end in a
single backslash (since the backslash would escape the
following quote character). Note also that a single backslash
followed by a newline is interpreted as those two characters
as part of the string, not as a line continuation.
*Fortran* also makes no difference between single and double quoted
strings. There is no special meaning to backslashes at all. I'm
not even sure if a backslash in Fortran source code is strictly
speaking legal. The quote character can be inserted by doubling
it---just as your last suggestion.
I'd vote for the Fortran syntax. There are no compatibility issues
(AFAICS). Single quotes have a special meaning anyway and the
sequence of two consequent single quotes within a 'string' would
otherwise be illegal. I've attached a patch implenting this to test
this out and get a feeling for it.
Juergen
|