Skip to content

Replace usage of StringReader.ReadLine() with something else #781

Closed
@rjmholt

Description

@rjmholt

We use StringReader.ReadLine() to read in a file for the first time here:

using (var reader = new StringReader(text))
{
// 50 is a rough guess for typical average line length, this saves some list
// resizes in the common case and does not hurt meaningfully if we're wrong.
var list = new List<string>(text.Length / 50);
string line;
while ((line = reader.ReadLine()) != null)
{
list.Add(line);
}
return list;
}

However, this has the nasty habit of dropping newlines at the ends of files. See https://github.com/dotnet/corefx/issues/32990.

This causes off-by-one errors in all these files for us. But since this behaviour is in both .NET Framework and Core, it's probably permanent. So we just need to use something else.

In the above corefx issue, I summarised different string split methods, and think we should either use String.Split() or do it ourselves, depending on what we think is best suited to our needs.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions