octave-maintainers
[Top][All Lists]
Advanced

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

Re: Single vs. Double Quotes


From: PhilipNienhuis
Subject: Re: Single vs. Double Quotes
Date: Sat, 15 Oct 2011 13:08:00 -0700 (PDT)

Søren Hauberg wrote:
> 
> lør, 15 10 2011 kl. 10:36 -0700, skrev Rik:
>> > While testing mirone with QtHandles, I found an issue with strread and
>> > \n delimiter,
>> > when the delimiter is double-quoted or single-quoted. It boils down to
>> > the following:
>> >
>> > octave-qt.exe:5> strread(sprintf('1\n2\n3'), '%d', 'delimiter', '\n')
>> > ans = 123
>> > octave-qt.exe:6> strread(sprintf('1\n2\n3'), '%d', 'delimiter', "\n")
>> > ans =
>> >
>> >   1
>> >   2
>> >   3
> <snip>
> I think most people agree that "\n" should be interpreted as a newline
> and that '\n' should be a '\' and a '\n' in general.
> 
> The question here is if the 'delimiter' option to 'strread' should
> deviate from this rule just as the '*printf' functions do. 
> 

PMFJI

In strread, this behaviour would not only affect the 'delimiter' option.

To be consistent, 'whitespace', 'endofline', 'emptyvalue' and perhaps even
literals in format strings would have to be treated as well.
I think coding this bears a risk of turning into a bit of a mess. At the
minimum this would require careful thinking over. 

In practice, I'm having a hard time trying to think up why anyone would need
"\" and "\n" as separate delimiter characters (which is how strread
currently interprets '\n' (single quotes)). 
It is obvious that in the vast majority of cases char(10) is meant if '\n'
was entered as delimiter (or whitespace, or endofline, or .... ) value. But
OK, perhaps not in all cases.

There is a related issue:

At my dev & work machines I have (and use) a strread.m version that allows
delimiters comprising multiple characters (the value of the delimiter option
is to be entered as a cell array then, one cellstring value for every
delimiter). This would leave the option for literal '\n' sequences.
I haven't committed this yet, probably because after all the fixes for the
textscan/textread/strread trio I think Rik and I might have become a bit
tired of it. Moreover jwe made a start of a compiled textscan so the point
of further development of the m-file versions became a bit moot.
 
But if other developers think multiple-char delimiters are a good idea, I
can try to pick up again and prepare a patch.

Philip


--
View this message in context: 
http://octave.1599824.n4.nabble.com/Re-Single-vs-Double-Quotes-tp3907882p3908158.html
Sent from the Octave - Maintainers mailing list archive at Nabble.com.


reply via email to

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