Skip to content

Commit

Permalink
fix issue 11431 - std.file.slurp fails with Windows newlines
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars-Kristiansen committed Aug 25, 2018
1 parent a86b123 commit 9ca114d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions std/file.d
Original file line number Diff line number Diff line change
Expand Up @@ -5098,13 +5098,15 @@ slurp(Types...)(string filename, scope const(char)[] format)
import std.exception : enforce;
import std.format : formattedRead;
import std.stdio : File;
import std.string : stripRight;

auto app = appender!(typeof(return))();
ElementType!(typeof(return)) toAdd;
auto f = File(filename);
scope(exit) f.close();
foreach (line; f.byLine())
{
line = stripRight(line, "\r");
formattedRead(line, format, &toAdd);
enforce(line.empty,
text("Trailing characters at the end of line: `", line,
Expand Down Expand Up @@ -5135,6 +5137,19 @@ slurp(Types...)(string filename, scope const(char)[] format)
assert(a[1] == tuple(345, 1.125));
}

@system unittest
{
import std.typecons : tuple;

scope(exit)
{
assert(exists(deleteme));
remove(deleteme);
}
write(deleteme, "10\r\n20");
assert(slurp!(int)(deleteme, "%d") == [10, 20]);
}


/**
Returns the path to a directory for temporary files.
Expand Down

0 comments on commit 9ca114d

Please sign in to comment.