Skip to content

Commit

Permalink
Merge pull request #6680 from BBasile/issue-11431
Browse files Browse the repository at this point in the history
fix issue 11431 - std.file.slurp fails with Windows newlines
merged-on-behalf-of: Vladimir Panteleev <github@thecybershadow.net>
  • Loading branch information
dlang-bot authored Aug 26, 2018
2 parents f4aec67 + 8ab8b1f commit f4c6d5c
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion std/file.d
Original file line number Diff line number Diff line change
Expand Up @@ -5098,6 +5098,7 @@ 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;
Expand All @@ -5106,7 +5107,7 @@ slurp(Types...)(string filename, scope const(char)[] format)
foreach (line; f.byLine())
{
formattedRead(line, format, &toAdd);
enforce(line.empty,
enforce(line.stripRight("\r").empty,
text("Trailing characters at the end of line: `", line,
"'"));
app.put(toAdd);
Expand Down Expand Up @@ -5135,6 +5136,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 f4c6d5c

Please sign in to comment.