Files
2026-06-04 11:42:34 +02:00

183 lines
7.4 KiB
C#

using System;
using System.Runtime.InteropServices;
namespace System.IO
{
/// <summary>Implements a <see cref="T:System.IO.TextReader" /> that reads from a string.</summary>
/// <filterpriority>2</filterpriority>
// Token: 0x020001D1 RID: 465
[ComVisible(true)]
[Serializable]
public class StringReader : TextReader
{
/// <summary>Initializes a new instance of the <see cref="T:System.IO.StringReader" /> class that reads from the specified string.</summary>
/// <param name="s">The string to which the <see cref="T:System.IO.StringReader" /> should be initialized. </param>
/// <exception cref="T:System.ArgumentNullException">The <paramref name="s" /> parameter is null. </exception>
// Token: 0x060017DB RID: 6107 RVA: 0x0005BF10 File Offset: 0x0005A110
public StringReader(string s)
{
if (s == null)
{
throw new ArgumentNullException("s");
}
this.source = s;
this.nextChar = 0;
this.sourceLength = s.Length;
}
/// <summary>Closes the <see cref="T:System.IO.StringReader" />.</summary>
/// <filterpriority>2</filterpriority>
// Token: 0x060017DC RID: 6108 RVA: 0x0005BF44 File Offset: 0x0005A144
public override void Close()
{
this.Dispose(true);
}
/// <summary>Releases the unmanaged resources used by the <see cref="T:System.IO.StringReader" /> and optionally releases the managed resources.</summary>
/// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources. </param>
// Token: 0x060017DD RID: 6109 RVA: 0x0005BF50 File Offset: 0x0005A150
protected override void Dispose(bool disposing)
{
this.source = null;
base.Dispose(disposing);
}
/// <summary>Returns the next available character but does not consume it.</summary>
/// <returns>An integer representing the next character to be read, or -1 if no more characters are available or the stream does not support seeking.</returns>
/// <exception cref="T:System.ObjectDisposedException">The current reader is closed. </exception>
/// <filterpriority>2</filterpriority>
// Token: 0x060017DE RID: 6110 RVA: 0x0005BF60 File Offset: 0x0005A160
public override int Peek()
{
this.CheckObjectDisposedException();
if (this.nextChar >= this.sourceLength)
{
return -1;
}
return (int)this.source[this.nextChar];
}
/// <summary>Reads the next character from the input string and advances the character position by one character.</summary>
/// <returns>The next character from the underlying string, or -1 if no more characters are available.</returns>
/// <exception cref="T:System.ObjectDisposedException">The current reader is closed. </exception>
/// <filterpriority>2</filterpriority>
// Token: 0x060017DF RID: 6111 RVA: 0x0005BF98 File Offset: 0x0005A198
public override int Read()
{
this.CheckObjectDisposedException();
if (this.nextChar >= this.sourceLength)
{
return -1;
}
return (int)this.source[this.nextChar++];
}
/// <summary>Reads a block of characters from the input string and advances the character position by <paramref name="count" />.</summary>
/// <returns>The total number of characters read into the buffer. This can be less than the number of characters requested if that many characters are not currently available, or zero if the end of the underlying string has been reached.</returns>
/// <param name="buffer">When this method returns, contains the specified character array with the values between <paramref name="index" /> and (<paramref name="index" /> + <paramref name="count" /> - 1) replaced by the characters read from the current source. </param>
/// <param name="index">The starting index in the buffer. </param>
/// <param name="count">The number of characters to read. </param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="buffer" /> is null. </exception>
/// <exception cref="T:System.ArgumentException">The buffer length minus <paramref name="index" /> is less than <paramref name="count" />. </exception>
/// <exception cref="T:System.ArgumentOutOfRangeException">
/// <paramref name="index" /> or <paramref name="count" /> is negative. </exception>
/// <exception cref="T:System.ObjectDisposedException">The current reader is closed. </exception>
/// <filterpriority>2</filterpriority>
// Token: 0x060017E0 RID: 6112 RVA: 0x0005BFDC File Offset: 0x0005A1DC
public override int Read([In] [Out] char[] buffer, int index, int count)
{
this.CheckObjectDisposedException();
if (buffer == null)
{
throw new ArgumentNullException("buffer");
}
if (buffer.Length - index < count)
{
throw new ArgumentException();
}
if (index < 0 || count < 0)
{
throw new ArgumentOutOfRangeException();
}
int num;
if (this.nextChar > this.sourceLength - count)
{
num = this.sourceLength - this.nextChar;
}
else
{
num = count;
}
this.source.CopyTo(this.nextChar, buffer, index, num);
this.nextChar += num;
return num;
}
/// <summary>Reads a line from the underlying string.</summary>
/// <returns>The next line from the underlying string, or null if the end of the underlying string is reached.</returns>
/// <exception cref="T:System.ObjectDisposedException">The current reader is closed. </exception>
/// <exception cref="T:System.OutOfMemoryException">There is insufficient memory to allocate a buffer for the returned string. </exception>
/// <filterpriority>2</filterpriority>
// Token: 0x060017E1 RID: 6113 RVA: 0x0005C070 File Offset: 0x0005A270
public override string ReadLine()
{
this.CheckObjectDisposedException();
int i;
for (i = this.nextChar; i < this.sourceLength; i++)
{
char c = this.source[i];
if (c == '\r' || c == '\n')
{
string text = this.source.Substring(this.nextChar, i - this.nextChar);
this.nextChar = i + 1;
if (c == '\r' && this.nextChar < this.sourceLength && this.source[this.nextChar] == '\n')
{
this.nextChar++;
}
return text;
}
}
if (i > this.nextChar)
{
string text2 = this.source.Substring(this.nextChar, i - this.nextChar);
this.nextChar = i;
return text2;
}
return null;
}
/// <summary>Reads the stream as a string, either in its entirety or from the current position to the end of the stream.</summary>
/// <returns>The content from the current position to the end of the underlying string.</returns>
/// <exception cref="T:System.OutOfMemoryException">There is insufficient memory to allocate a buffer for the returned string. </exception>
/// <exception cref="T:System.ObjectDisposedException">The current reader is closed. </exception>
/// <filterpriority>2</filterpriority>
// Token: 0x060017E2 RID: 6114 RVA: 0x0005C150 File Offset: 0x0005A350
public override string ReadToEnd()
{
this.CheckObjectDisposedException();
string text = this.source.Substring(this.nextChar, this.sourceLength - this.nextChar);
this.nextChar = this.sourceLength;
return text;
}
// Token: 0x060017E3 RID: 6115 RVA: 0x0005C190 File Offset: 0x0005A390
private void CheckObjectDisposedException()
{
if (this.source == null)
{
throw new ObjectDisposedException("StringReader", Locale.GetText("Cannot read from a closed StringReader"));
}
}
// Token: 0x0400071E RID: 1822
private string source;
// Token: 0x0400071F RID: 1823
private int nextChar;
// Token: 0x04000720 RID: 1824
private int sourceLength;
}
}