Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
StringReader.cs
Go to the documentation of this file.
3
4namespace System.IO;
5
6public class StringReader : TextReader
7{
8 private string _s;
9
10 private int _pos;
11
12 private int _length;
13
14 public StringReader(string s)
15 {
16 if (s == null)
17 {
19 }
20 _s = s;
21 _length = s.Length;
22 }
23
24 public override void Close()
25 {
26 Dispose(disposing: true);
27 }
28
29 protected override void Dispose(bool disposing)
30 {
31 _s = null;
32 _pos = 0;
33 _length = 0;
34 base.Dispose(disposing);
35 }
36
37 public override int Peek()
38 {
39 if (_s == null)
40 {
42 }
43 if (_pos == _length)
44 {
45 return -1;
46 }
47 return _s[_pos];
48 }
49
50 public override int Read()
51 {
52 if (_s == null)
53 {
55 }
56 if (_pos == _length)
57 {
58 return -1;
59 }
60 return _s[_pos++];
61 }
62
63 public override int Read(char[] buffer, int index, int count)
64 {
65 if (buffer == null)
66 {
67 throw new ArgumentNullException("buffer", SR.ArgumentNull_Buffer);
68 }
69 if (index < 0)
70 {
72 }
73 if (count < 0)
74 {
76 }
77 if (buffer.Length - index < count)
78 {
80 }
81 if (_s == null)
82 {
84 }
85 int num = _length - _pos;
86 if (num > 0)
87 {
88 if (num > count)
89 {
90 num = count;
91 }
92 _s.CopyTo(_pos, buffer, index, num);
93 _pos += num;
94 }
95 return num;
96 }
97
98 public override int Read(Span<char> buffer)
99 {
100 if (GetType() != typeof(StringReader))
101 {
102 return base.Read(buffer);
103 }
104 if (_s == null)
105 {
107 }
108 int num = _length - _pos;
109 if (num > 0)
110 {
111 if (num > buffer.Length)
112 {
113 num = buffer.Length;
114 }
115 _s.AsSpan(_pos, num).CopyTo(buffer);
116 _pos += num;
117 }
118 return num;
119 }
120
121 public override int ReadBlock(Span<char> buffer)
122 {
123 return Read(buffer);
124 }
125
126 public override string ReadToEnd()
127 {
128 if (_s == null)
129 {
131 }
132 string result = ((_pos != 0) ? _s.Substring(_pos, _length - _pos) : _s);
133 _pos = _length;
134 return result;
135 }
136
137 public override string? ReadLine()
138 {
139 if (_s == null)
140 {
142 }
143 int i;
144 for (i = _pos; i < _length; i++)
145 {
146 char c = _s[i];
147 if (c == '\r' || c == '\n')
148 {
149 string result = _s.Substring(_pos, i - _pos);
150 _pos = i + 1;
151 if (c == '\r' && _pos < _length && _s[_pos] == '\n')
152 {
153 _pos++;
154 }
155 return result;
156 }
157 }
158 if (i > _pos)
159 {
160 string result2 = _s.Substring(_pos, i - _pos);
161 _pos = i;
162 return result2;
163 }
164 return null;
165 }
166
167 public override Task<string?> ReadLineAsync()
168 {
169 return Task.FromResult(ReadLine());
170 }
171
172 public override Task<string> ReadToEndAsync()
173 {
174 return Task.FromResult(ReadToEnd());
175 }
176
177 public override Task<int> ReadBlockAsync(char[] buffer, int index, int count)
178 {
179 if (buffer == null)
180 {
181 throw new ArgumentNullException("buffer", SR.ArgumentNull_Buffer);
182 }
183 if (index < 0 || count < 0)
184 {
185 throw new ArgumentOutOfRangeException((index < 0) ? "index" : "count", SR.ArgumentOutOfRange_NeedNonNegNum);
186 }
187 if (buffer.Length - index < count)
188 {
190 }
191 return Task.FromResult(ReadBlock(buffer, index, count));
192 }
193
195 {
196 if (!cancellationToken.IsCancellationRequested)
197 {
198 return new ValueTask<int>(ReadBlock(buffer.Span));
199 }
201 }
202
203 public override Task<int> ReadAsync(char[] buffer, int index, int count)
204 {
205 if (buffer == null)
206 {
207 throw new ArgumentNullException("buffer", SR.ArgumentNull_Buffer);
208 }
209 if (index < 0 || count < 0)
210 {
211 throw new ArgumentOutOfRangeException((index < 0) ? "index" : "count", SR.ArgumentOutOfRange_NeedNonNegNum);
212 }
213 if (buffer.Length - index < count)
214 {
216 }
217 return Task.FromResult(Read(buffer, index, count));
218 }
219
221 {
222 if (!cancellationToken.IsCancellationRequested)
223 {
224 return new ValueTask<int>(Read(buffer.Span));
225 }
227 }
228}
override int ReadBlock(Span< char > buffer)
override int Read()
override Task< int > ReadBlockAsync(char[] buffer, int index, int count)
override? string ReadLine()
override void Dispose(bool disposing)
override void Close()
override Task< string > ReadToEndAsync()
override Task< string?> ReadLineAsync()
override int Peek()
override ValueTask< int > ReadAsync(Memory< char > buffer, CancellationToken cancellationToken=default(CancellationToken))
override int Read(Span< char > buffer)
override Task< int > ReadAsync(char[] buffer, int index, int count)
override string ReadToEnd()
override ValueTask< int > ReadBlockAsync(Memory< char > buffer, CancellationToken cancellationToken=default(CancellationToken))
override int Read(char[] buffer, int index, int count)
static string ObjectDisposed_ReaderClosed
Definition SR.cs:1748
static string ArgumentNull_Buffer
Definition SR.cs:22
static string Argument_InvalidOffLen
Definition SR.cs:22
static string ArgumentOutOfRange_NeedNonNegNum
Definition SR.cs:32
Definition SR.cs:7
static void ThrowArgumentNullException(string name)
static ValueTask FromCanceled(CancellationToken cancellationToken)
Definition ValueTask.cs:180