bugGNU Octave - Bugs: bug #50297, csv2cell does not ignore CR in...

 
 

bug #50297: csv2cell does not ignore CR in CRLF files

Submitter:  A.R. Burgers <arb>
Submitted:  Mon 13 Feb 2017 07:02:24 PM UTC
   
 
Category:  Octave Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Inaccurate Result
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * other Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Fri 24 Feb 2017 10:23:34 PM UTC, comment #4: 

yes, this fixes the issue for me.

Thanks!

A.R. Burgers <arb>
Tue 21 Feb 2017 09:12:56 PM UTC, comment #3: 

This turned out not to be that hard. Fixed here:
http://hg.code.sf.net/p/octave/io/rev/1cfd8cf0f58a

I'll attach a csv2cell.cc here.

1. do:
which csv2cell
and note the location where csv2cell.oct lives.

2. Then compile attached csv2cell.cc using (in an octave terminal):

mkoctfile csv2cell.cc

and move the csv2cell.oct into the place you noted in step 1.

Please report back if your issues has been fixed.

(file #39807)

Philip Nienhuis <philipnienhuis>
Group Member
Mon 20 Feb 2017 06:24:28 PM UTC, comment #2: 

On Mageia-5 linux I can confirm this:

>> format compact
>> fid = fopen ('a_CRLF.csv', 'w')
fid =  21
>> fprintf (fid, "a\r\n1\r\n");
>> fclose (fid)
ans = 0
>> fid = fopen ('a_CRLF.csv', 'r')
fid =  21
>> txt = fread (fid, Inf, "char=>char")'
txt = a
1
>> fclose (fid)
ans = 0
>> uint16(txt)
ans =
  97  13  10  49  13  10
>> a = csv2cell ('a_CRLF.csv')
a =
{
  [1,1] = a
  [2,1] = 1
}
>> uint16(a{1})
ans =
  97  13
>> uint16(a{2})
ans =
  49  13


Yet I have no idea how to solve this.

Philip Nienhuis <philipnienhuis>
Group Member
Tue 14 Feb 2017 08:40:12 PM UTC, comment #1: 

What io package release?

On Windows, with this script:

fid = fopen ('a_CRLF.csv', 'w')
fprintf (fid, "a\r\n1\r\n");
fclose (fid)

fid = fopen ('a_CRLF.csv', 'r')
txt = fread (fid, Inf, "char=>char")'
fclose (fid)
uint16(txt)

a = csv2cell ('a_CRLF.csv')
uint16(a{1})
uint16(a{2})


I get:

>> format compact
>> fid = fopen ('a_CRLF.csv', 'w')

fid =  3
>> fprintf (fid, "a\r\n1\r\n");

>> fclose (fid)

ans = 0
>> fid = fopen ('a_CRLF.csv', 'r')

fid =  3
>> txt = fread (fid, Inf, "char=>char")'

txt = a
1

>> fclose (fid)

ans = 0
>> uint16(txt)

ans =
  97  13  10  49  13  10

>> a = csv2cell ('a_CRLF.csv')
a =
{
  [1,1] = a
  [2,1] =  1
}
>> uint16(a{1})

ans = 97
>> uint16(a{2})

ans = 1
>>


... so at least on Windows it appears to work properly.
So I suspect that cv2cell's sensitivity for EOL type could be OS-specific; or more specific, the C++ function getline() that csv2cell invokes might be OS-dependent.
But my C++ proficiency is below par so don't take my idea to seriously.

Philip Nienhuis <philipnienhuis>
Group Member
Mon 13 Feb 2017 07:02:24 PM UTC, original submission:  


csv files with CRLF line endings results strings containing a CR, with can lead to unexpected results.

Consider the file a_CRLF.csv:


csh}127: file a_CRLF.csv
a_CRLF.csv: ASCII text, with CRLF line terminators

csh?128: od -c a_CRLF.csv
0000000   a  \r  \n   1  \r  \n
0000006


and the following script


pkg load io;

a_CRLF = csv2cell('a_CRLF.csv')
double(a_CRLF{1,1})


it produces this output


a_CRLF =
{
  [1,1] = a
  [2,1] = 1
}
ans =
   97   13


note the 13 entry.

A.R. Burgers <arb>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #39807:  csv2cell.cc added by philipnienhuis (10KiB - application/octet-stream)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by arb (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 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-02-28 philipnienhuis StatusReady For Test Fixed
        Operating SystemGNU/Linux Any
    2017-02-21 philipnienhuis Attached File- Added csv2cell.cc, #39807
        StatusConfirmed Ready For Test
        Open/ClosedOpen Closed
    2017-02-20 philipnienhuis StatusNone Confirmed
        Releasedev other

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code