www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Bug in File.byRecord ?

reply closescreen <close.screen gmail.com> writes:
I have a file with empty lines: 2,3 and 5,6

filename.csv (with linenumbers for better view in this message)
1>Joe,Carpenter,300000
2>
3>
4>Fred,Blacksmith,400000
5>
6>

Now, if I run:
rdmd 
--eval='"filename.csv".File.byRecord!(string,string,int)("%s,%s,%d").writeln'

It prints:

[Tuple!(string, string, int)("Joe", "Carpenter", 300000),
  Tuple!(string, string, int)("Joe", "Carpenter", 300000),
  Tuple!(string, string, int)("Joe", "Carpenter", 300000),
  Tuple!(string, string, int)("Fred", "Blacksmith", 400000),
  Tuple!(string, string, int)("Fred", "Blacksmith", 400000),
  Tuple!(string, string, int)("Fred", "Blacksmith", 400000)]

It happens because code in

https://github.com/dlang/phobos/blob/master/std/stdio.d#L297

not checks return value after call formattedRead.

Is this a bug? Or I not understand something?
Jul 26 2017
parent =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 07/26/2017 04:51 AM, closescreen wrote:
 I have a file with empty lines: 2,3 and 5,6

 filename.csv (with linenumbers for better view in this message)
 1>Joe,Carpenter,300000
 2>
 3>
 4>Fred,Blacksmith,400000
 5>
 6>

 Now, if I run:
 rdmd
 
--eval='"filename.csv".File.byRecord!(string,string,int)("%s,%s,%d").writeln'
 It prints:

 [Tuple!(string, string, int)("Joe", "Carpenter", 300000),
  Tuple!(string, string, int)("Joe", "Carpenter", 300000),
  Tuple!(string, string, int)("Joe", "Carpenter", 300000),
  Tuple!(string, string, int)("Fred", "Blacksmith", 400000),
  Tuple!(string, string, int)("Fred", "Blacksmith", 400000),
  Tuple!(string, string, int)("Fred", "Blacksmith", 400000)]

 It happens because code in

 https://github.com/dlang/phobos/blob/master/std/stdio.d#L297

 not checks return value after call formattedRead.

 Is this a bug?
Yes, I think it's a bug. Ali
Jul 26 2017