octave-maintainers
[Top][All Lists]
Advanced

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

Escape sequences in *printf family of functions


From: John W. Eaton
Subject: Escape sequences in *printf family of functions
Date: Thu, 5 Apr 2012 01:50:35 -0400

On  4-Apr-2012, Rik wrote:

| I'm almost done adding an internal variable to control escape sequence
| processing in single quoted strings.

I don't think we want to add any internal variables that control
things like this.  Can you post your patch to show what you have in
mind?

In Matlab strings, '\n' is two characters, backslash and n.

In Matlab, some functions, like *printf, handle pairs of characters
like this specially.  So, in  x = sprintf ('\n'),  x is a single
character, ASCII 10, LF (new line).

For compatibility with Matlab, Octave also does this for single-quoted
strings.

But Octave also has double-quoted strings that behave like C strings,
so "\n" is one character, LF (new line).  These don't need any special
handling in *printf or any other functions, and for double-quoted
strings, that actually do contain \ followed by some other character,
we don't want any special treatment, so for example, x = sprintf ("\\n")
should result in x containing two characters, backslash and n.

This behavior is intentional, and I think it is the correct way to
handle things.  You get compatibility if you use single-quoted strings
(any code written for Matlab will have to use single quotes for
character strings) and double-quoted strings work as they do in C.

The only problem that I thought there was to fix was that we weren't
giving single-quoted strings this special treatment in the replacement
string in the regexprep function.

jwe


reply via email to

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