octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Single vs. Double Quotes


From: John W. Eaton
Subject: Re: Single vs. Double Quotes
Date: Sat, 15 Oct 2011 14:03:14 -0400

On 15-Oct-2011, Rik wrote:

| It appears that Matlab always uses interpreting quotes even though they
| have used the character that every other interpreter has chosen to mean
| non-interpreting quote.

Just to be sure I understand, by "interpreting quotes" you mean that
inside a character string constant, sequences like \n, \r, \f, \t,
etc., are translated to single ASCII characters NL, CR, FF, TAB, etc.,
correct?

If so, then no, that's not how Matlab works.  I think its behavior is
actually worse.  These escape sequences are not treated specially when
defining a character string constant.  So size('\n') is 2, and
abs('\n') is [92,110].  Octave's behavior for single quote strings
should be the same.

In some contexts, however, character strings are scanned for these
backslash-escaped sequences and they are treated specially.  The
places I know about are inside format strings for the *printf and
*scanf functions.  Octave handles these cases now.  I wasn't aware
that strread would also treat the delimiter option specially.   I
think the right fix for Octave would be to first check whether the
delimiter string is of the single or double quote variety and if it is
a single-quoted string, pass it through sprintf after doubling any %
characters.  Something like

  if (typeinfo (delim, "sq_string"))
    delim = sprintf (strrep (delim, "%", "%%"));
  endif

should do it, but we might want to provide is_sq_string and
is_dq_string functions for convenience.

jwe


reply via email to

[Prev in Thread] Current Thread [Next in Thread]