bugGNU Octave - Bugs: bug #39774, Support octal and hexadecimal...


bug #39774: Support octal and hexadecimal sprintf escape sequences

Submitted by:  Mike Miller <mtmiller>
Submitted on:  Mon 12 Aug 2013 06:11:24 PM UTC  
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  Closed
Release:  dev Operating System:  Any

Add a New Comment(Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


Thu 21 May 2015 12:19:44 AM UTC, comment #4:

I modified do_string_escapes to add support for octal and hexadecimal sequences (http://hg.savannah.gnu.org/hgweb/octave/rev/29eb47fe8e8c).

Rik <rik5>
Project Administrator
Thu 15 Aug 2013 03:53:14 AM UTC, comment #3:

Yeah, after I reported this I traced it to do_string_escapes. This function is already called for the printf and scanf family of functions with single-quoted strings, but it's done in oct-stream.cc instead of file-io.cc.

Thanks for pointing out the similar functions in regexp.cc, though. Some similarity, the fix for this could be adapted to the FIXME in that file.

Mike Miller <mtmiller>
Project Administrator
Wed 14 Aug 2013 08:24:55 PM UTC, comment #2:

We already do this for single-quoted strings in regular expressions. Take a look at regexp.cc

The function do_regexp_ptn_string_escapes is special because the escape sequences are not qute the same as the ordinary *printf family. However, we already have do_string_escapes in util.cc which does escape sequence processing. You could code the same thing in file-io.cc for printf and check is_sq_string() before calling do_string_escapes.

do_string_escapes() would need to be modified to support hexadecimal and octal though. Right now it just does the basics like "\n" -> NEWLINE.

Incidentally, I hate Matlab's single option for a character string delimiter. It makes everything totally confusing in Octave because we do have non-interpreted single-quoted strings, except where they interact with a Matlab function in which case they are treated as double-quoted strings.

Rik <rik5>
Project Administrator
Tue 13 Aug 2013 08:12:26 PM UTC, comment #1:

What, you don't trust the Matlab documentation to accurately reflect Matlab's actual behavior?

If it is documented to behave this way, then I guess that's what we should do for Octave as well.

John W. Eaton <jwe>
Project Administrator
Mon 12 Aug 2013 06:11:24 PM UTC, original submission:

According to the Matlab documentation for fprintf and sprintf, the standard C escape sequences for octal and hexadecimal literal characters are supported.


For Octave, note that this is about handling the escape sequences in the printf/fprintf/sprintf functions when the format string argument is given as a single-quoted string.

The following three sprintf commands should all return the same string. This is based on the Matlab documentation only, I would appreciate it if someone were able to confirm these in Matlab.

Instead, Octave does the following:

Mike Miller <mtmiller>
Project Administrator


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by mtmiller (Submitted the item)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.




    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2015-05-21 rik5 StatusNone => Fixed
        Open/ClosedOpen => Closed

    Back to the top

    Powered by Savane 3.3