mirror of
https://github.com/osukey/osukey.git
synced 2025-05-16 11:07:35 +09:00
Revert old behaviour of ReadToEnd
This commit is contained in:
parent
12d396a513
commit
01bc6e5cb7
@ -108,13 +108,19 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestReadToEndAfterReadsAndPeeks()
|
public void TestReadToEndAfterReadsAndPeeks()
|
||||||
{
|
{
|
||||||
const string contents = "first line\r\nsecond line";
|
const string contents = "this line is gone\rthis one shouldn't be\r\nthese ones\ndefinitely not";
|
||||||
|
|
||||||
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(contents)))
|
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(contents)))
|
||||||
using (var bufferedReader = new LineBufferedReader(stream))
|
using (var bufferedReader = new LineBufferedReader(stream))
|
||||||
{
|
{
|
||||||
bufferedReader.PeekLine();
|
Assert.AreEqual("this line is gone", bufferedReader.ReadLine());
|
||||||
Assert.Throws<InvalidOperationException>(() => bufferedReader.ReadToEnd());
|
Assert.AreEqual("this one shouldn't be", bufferedReader.PeekLine());
|
||||||
|
|
||||||
|
string[] endingLines = bufferedReader.ReadToEnd().Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
Assert.AreEqual(3, endingLines.Length);
|
||||||
|
Assert.AreEqual("this one shouldn't be", endingLines[0]);
|
||||||
|
Assert.AreEqual("these ones", endingLines[1]);
|
||||||
|
Assert.AreEqual("definitely not", endingLines[2]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,14 +46,21 @@ namespace osu.Game.IO
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reads the stream to its end and returns the text read.
|
/// Reads the stream to its end and returns the text read.
|
||||||
/// Not compatible with calls to <see cref="PeekLine"/>.
|
/// This includes any peeked but unconsumed lines.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string ReadToEnd()
|
public string ReadToEnd()
|
||||||
{
|
{
|
||||||
if (peekedLine != null)
|
string remainingText = streamReader.ReadToEnd();
|
||||||
throw new InvalidOperationException($"Do not use {nameof(ReadToEnd)} when also peeking for lines.");
|
if (peekedLine == null)
|
||||||
|
return remainingText;
|
||||||
|
|
||||||
return streamReader.ReadToEnd();
|
var builder = new StringBuilder();
|
||||||
|
|
||||||
|
// this might not be completely correct due to varying platform line endings
|
||||||
|
builder.AppendLine(peekedLine);
|
||||||
|
builder.Append(remainingText);
|
||||||
|
|
||||||
|
return builder.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user