bugGNU Octave - Bugs: bug #42979, textscan.m, strread.m: parsing of...

 
 

bug #42979: textscan.m, strread.m: parsing of format conversion specifiers and % literals

Submitter:  Philip Nienhuis <philipnienhuis>
Submitted:  Wed 13 Aug 2014 07:50:16 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  philipnienhuis
Originator Name:  Philip Nienhuis Open/Closed:  * Closed
Release:  * 3.8.0 Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 25 Aug 2014 07:43:10 PM UTC, comment #1: 
Philip Nienhuis <philipnienhuis>
Group Member
Wed 13 Aug 2014 07:50:16 PM UTC, original submission:  

Consider calls to strread.m and textscan.m of the form:


>> strread ("Total: 32.5 % (of cm values)", "Total: %f % (of cm values)")
error: strread: the number of output variables must match that specified by FORMAT
error: called from:
error:   /usr/local/share/octave/3.9.0+/m/io/strread.m at line 200, column 5
>> textscan ("Total: 32.5 % (of cm values)", "Total: %f % (of cm values)")
error: strread: unknown format specifier #2 ('%')
>>


For a start, both functions should yield identical error messages for this case.

As to the first case, strread.m incorrectly assesses the number of format conversion specifiers; it is fooled by the lone "%" appearing as a literal.
In the second case, textscan.m assesses a wrong number of (valid) format conversion specifiers, hands them to strread.m (and on the way prepares strread.m to return two output args), upon which strread.m only then incorrectly concludes it is given an invalid format specifier #2.

Attached is a fix for both functions invoking a regexp for assessing the number of valid format conversion specifiers, and it also improves the error messages returned by strread and adds some tests.

Note that Matlab doesn't seem to accept a lone "%" as a literal. Of course a literal "%" can be read away with a %*1s format conversion specifier. So in a way I've made a somewhat arbitrary choice to make strread.m & textscan.m accept a single "%" as a literal.

If no one has any objections I'll push it in a few days.

Philip Nienhuis <philipnienhuis>
Group Member

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #31899:  fmtconvspec.cs added by philipnienhuis (3KiB - text/x-csharp)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by philipnienhuis (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2014-08-25 philipnienhuis StatusPatch Submitted Fixed
        Open/ClosedOpen Closed
    2014-08-13 philipnienhuis Attached File- Added fmtconvspec.cs, #31899

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code