|
From: Daniel J S. <dan...@ie...> - 2005-11-15 17:48:24
|
Hans-Bernhard Broeker wrote: > I.e. as of version 4.0, the status actually was that \' is *not* an > escape --- both the \ and the ' made it into the string unmodified. > > The actual bug in 4.0 only happens if \' is at the end of the command. > It's a side effect of the auto-closing of strings. The convenience > feature helper that allows people to type > > set label 1 'foo Good point. I've gotten into the conscious (bad) habit of leaving that second apostrophe off the string. Maybe gnuplot shouldn't do that. Dan |
|
From: Petr M. <mi...@ph...> - 2005-11-15 17:54:49
|
>> The actual bug in 4.0 only happens if \' is at the end of the command. It's >> a side effect of the auto-closing of strings. The convenience feature >> helper that allows people to type >> >> set label 1 'foo > > Good point. I've gotten into the conscious (bad) habit of leaving that > second apostrophe off the string. I like this feature for command line work, I don't want this to be removed. --- PM |
|
From: Juergen W. <wie...@fr...> - 2005-11-14 09:00:56
|
Am Montag, 14. November 2005 09:45 schrieb Hans-Bernhard Broeker: > Ethan A Merritt wrote: > > It *would* be ended by the trailing single quote, if there were one. > > But there is no such trailing single quote in your command line > > because the only candidate has been escaped by a backslash. > > No, it's not supposed to be escaped. At least not in any version up to > 4.0 it wasn't. There are no backslash escapes being processed on > single-quoted strings in gnuplot, period. See 'help syntax'. Thus this > behaviour: "help syntax quotes" only says that there is no backslash processing of special characters. It does not state there is no special meaning of backslashes at all. At least, I cannot find it. > > gnuplot> set title 'C:\'; foo' ; show title > > title is "C:\\'; foo", offset at ((character units) 0, 0, 0) > > Is a bug, and has been as long as it was present in the program. > > > The backslash character is always interpreted as an escape during input. > > Not inside single-quoted strings. > > > Single or double quotes make no difference. > > If so, that's a bug, or an incompatible change since version 4.0. Proof > from 4.0 on Win32: > > gnuplot> set label 1 "a\n\t\\\qb" > gnuplot> set label 2 'a\n\t\\\qb' > gnuplot> show lab > > label 1 "a\n\t\\qb" at (0, 0, 0) left not rotated back nopoint > label 2 "a\\n\\t\\\\\\qb" at (0, 0, 0) left not rotated back nopoint > > gnuplot> > > In other words: \-escape sequences in "" can become special characters > like LF, TAB or the backslash itself, whereas \ characters in '' become > literal \ characters, which 'show' doubles up since it uses "" strings. The behaviour you show is exactly the same as raw strings in python. [With the exception that gnuplot silently terminates strings at the end of the line.] Really. Backslashes are used as escape characters and nevertheless taken into the string. It's insane. But strictly speaking, it's not a bug. And it has not changed since 3.7, AFAICS. Juergen |
|
From: Hans-Bernhard B. <br...@ph...> - 2005-11-14 09:38:48
|
Juergen Wieferink wrote: > "help syntax quotes" only says that there is no backslash processing > of special characters. No such thing as 'help syntax quotes' in the 4.0 documentation. And no mention of 'special characters' either. Here's the actual text: --- from 'help syntax', version 4.0: --- Text may be enclosed in single- or double-quotes. Backslash processing of sequences like \n (newline) and \345 (octal character code) is performed for double-quoted strings, but not for single-quoted strings. --- I see no justification here for applying backslash-escaping to \' inside a single-quoted string. If no other sequence is escapable inside '', why should \' be the only exception, and then not even be documented? This is clearly a non-documented, completely surprising feature. If that doesn't qualify it as a bug, I don't see what could. > The behaviour you show is exactly the same as raw strings in > python. [With the exception that gnuplot silently terminates strings > at the end of the line.] Really. Backslashes are used as escape > characters and nevertheless taken into the string. Not at the same time they aren't. It's either-or. Either your in a double-quoted string, then backslashes are used as escape characters, or you're in a single-quoted string, then they're kept as they are. It's as simple as that --- or at least it's supposed to be. |
|
From: Juergen W. <wie...@fr...> - 2005-11-14 10:00:35
|
Hans-Bernhard Broeker wrote: > Juergen Wieferink wrote: > This is clearly a non-documented, completely surprising feature. If > that doesn't qualify it as a bug, I don't see what could. If you define "non-documented, completely surprising feature" as a bug, then it's indeed a bug. > > The behaviour you show is exactly the same as raw strings in > > python. [With the exception that gnuplot silently terminates strings > > at the end of the line.] Really. Backslashes are used as escape > > characters and nevertheless taken into the string. > > Not at the same time they aren't. It's either-or. Either your in a > double-quoted string, then backslashes are used as escape characters, or > you're in a single-quoted string, then they're kept as they are. It's > as simple as that --- or at least it's supposed to be. The latter. But how should one know that. I agree it should be fixed, though. Juergen |
|
From: Juergen W. <wie...@fr...> - 2005-11-14 17:59:36
Attachments:
backslash_in_single_quotes-2005-11-14.patch
|
On Monday 14 November 2005 17:33 Petr Mikulik wrote: > Exactly. Thus, 'C:\tmp' is really C:\tmp and not C:<TAB>tmp, and '\' is > really \ (1 char) and not anything else. 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. Juergen |
|
From: Ethan M. <merritt@u.washington.edu> - 2005-11-14 19:05:41
|
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.
The other common convention is to repeat the quote character:
c = 'foo''bar'
but that convention is not so far used anywhere in gnuplot.
--
Ethan A Merritt merritt@u.washington.edu
Biomolecular Structure Center
Mailstop 357742
University of Washington, Seattle, WA 98195
|
|
From: Juergen W. <wie...@fr...> - 2005-11-15 19:27:07
Attachments:
jw-fortran_sq-2005-11-15.patch
|
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
|
|
From: Ethan M. <merritt@u.washington.edu> - 2005-11-15 19:46:23
|
On Tuesday 15 November 2005 11:27 am, Juergen Wieferink wrote:
> > 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.
Not really. IMHO it should behave as in the perl documentation
you quote below. If you want a trailing backslash, then you have
to escape the backslash:
foo = 'c:\\'
Yes, I know this is not what the current code does and it will
break all the existing backslash uses in single quotes. So we
won't even consider it. But that's what it should have been :-)
I'm dropping out of this discussion.
I truly don't care which way this goes.
> *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 "\\").
--
Ethan A Merritt merritt@u.washington.edu
Biomolecular Structure Center
Mailstop 357742
University of Washington, Seattle, WA 98195
|
|
From: Petr M. <mi...@ph...> - 2005-11-16 08:54:27
|
> 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. Your patch is fine with me. Could you please update it with adding docs (description + examples) into "help quotes", and maybe also to "help cd" (we should replace "DOS users _must_" by "DOS and Windows users _must_"). --- PM |
|
From: Juergen W. <wie...@fr...> - 2005-11-17 18:35:59
Attachments:
jw-fortran_sq-2005-11-17.patch
|
On Wednesday 16 November 2005 09:54 Petr Mikulik wrote: > Your patch is fine with me. > > Could you please update it with adding docs (description + examples) into > "help quotes", and maybe also to "help cd" (we should replace "DOS users > _must_" by "DOS and Windows users _must_"). Patch attached. I have much more trouble writing English than writing C, so I recommend to have close look on what I've written. Juergen |