bugGNU Octave - Bugs: bug #59065, Newline in first argument of...

 
 

bug #59065: Newline in first argument of input() is not processed with single-quoted strings

Submitted by:  Guillaume <gyom>
Submitted on:  Fri 04 Sep 2020 06:07:49 PM UTC  
 
Category:  Octave Function Severity:  3 - Normal
Priority:  1 - Later Item Group:  WTF, Matlab?!?
Status:  Confirmed Assigned to:  None
Originator Name:  Guillaume Open/Closed:  Open
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.

 

Sun 06 Sep 2020 11:42:58 PM UTC, comment #4: 

I marked the bug as "WTF, Matlab?" and lowered the priority.  I don't think many people use the input function anymore (if they ever did).  Maybe someone wants to work on this issue, but I think there are many more pressing bug reports.

Rik <rik5>
Project Administrator
Sat 05 Sep 2020 03:56:52 PM UTC, comment #3: 

Thanks for the feedbacks. input() is probably one of the very old Matlab functions so this might explain its slightly peculiar behavior. It does indeed only handle newlines ('\n' -> "\n", '\\' -> '\', '\?' -> '?').

Using a more generic do_string_escapes might be the solution but it might make this function slower, which might be a problem if it's a widely called one? I therefore wonder if input() could just call the existing do_string_escapes() and process all escape characters - I would see this behavior as an extension rather than a compatibility issue with Matlab, given that it's probably better to process all escape characters than none.

Guillaume <gyom>
Sat 05 Sep 2020 02:24:20 AM UTC, comment #2: 

Matlab doesn't do \n conversion when creating strings when using either single quotes to create char arrays or double quotes to create string objects.  So it always applies some conversion automatically in specific instances, like the format argument for the fprintf or sprintf functions.  The weird thing about this discovery for input is that it appears to only apply to \n, not other escape sequences, not even \t.  Is that correct?!?  If so, maybe this one deserves a "WTF, Matlab?!?" tag?

If we decide to attempt compatibility here, we can't just do the same thing we do with other functions like fprintf when the format is a single-quoted character string.  We'll have to specifically handle only only \n.

For fprintf, for example, string escapes are handled in the
stream::printf (const octave_value&, const octave_value_list&, const std::string&) function by calling do_string_escapes.

If necessary, I guess we could have an optional argument to do_string_escapes that says which escapes to recognize?

The do_string_escapes function is defined in libinterp/corefcn/utils.cc.

John W. Eaton <jwe>
Project Administrator
Fri 04 Sep 2020 09:21:56 PM UTC, comment #1: 

Hmmm, this is wrapped up in the distinction Octave makes between double-quoted strings and single-quoted strings.  Escape characters are processed in double-quoted strings so this works in Octave (and Matlab):

a = input ("line1\nline2\nline3: ")

If you want to process escape characters within single-quoted strings in Octave you need to use something like the sprintf() function.

a = input (sprintf ('line1\nline2\nline3: '))

This probably only gets addressed permanently if we decide to drop support for double-quoted character arrays and then re-use the '"' character to indicate string array as Matlab now does.

Rik <rik5>
Project Administrator
Fri 04 Sep 2020 06:07:49 PM UTC, original submission:  

The 'input' function in Matlab evaluates '\n' in its first argument, see:
https://www.mathworks.com/help/matlab/ref/input.html#btt5u2a-2
while Octave displays it unmodified.

I went as far as:
http://hg.savannah.gnu.org/hgweb/octave/file/d150180e41e0/libinterp/corefcn/input.cc#l599
It seems that Matlab only understands '\n' (e.g. not '\t').

Guillaume <gyom>

 

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

Attach Files:
   
   
Comment:
   

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 jwe (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by gyom (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 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-09-06 rik5 Priority3 - Low => 1 - Later
        Item GroupMatlab Compatibility => WTF, Matlab?!?
    2020-09-04 rik5 StatusNone => Confirmed
    2020-09-04 rik5 SummaryNew line in first argument of 'input' => Newline in first argument of input() is not processed with single-quoted strings
    2020-09-04 rik5 Priority5 - Normal => 3 - Low

    Back to the top


    Powered by Savane 3.5