parse_start = 0;
} while (decoded_count == 0);
return decoded_count;
}
public override int Peek ()
{
if (base_stream == null)
throw new ObjectDisposedException ("StreamReader", "Cannot read from a closed StreamReader");
if (pos >= decoded_count && (mayBlock || ReadBuffer () == 0))
return -1;
return decoded_buffer [pos];
}
public override int Read ()
{
throw new Exception("Dynamic Reader could not read!");
}
public override int Read ([In, Out] char[] dest_buffer, int index, int count)
{
throw new Exception("Dynamic Reader could not read!");
}
bool foundCR_input;
int FindNextInputEOL()
{
char c = '\0';
for (; pos_input < cbEncoded; pos_input )
{
c = (char)input_buffer [pos_input];
if (c == '\n')
{
pos_input ;
int res = (foundCR_input) ? (pos_input - 2) : (pos_input - 1);
if (res < 0)
res = 0; // if a new buffer starts with a \n and there was a \r at
// the end of the previous one, we get here.
foundCR_input = false;
return res;
}
else if (foundCR_input)
{
foundCR_input = false;
return pos - 1;
}
foundCR_input = (c == '\r');
}
return -1;
}
bool foundCR;
int FindNextEOL ()
{
FindNextInputEOL();
char c = '\0';
for (; pos < decoded_count; pos )
{
c = decoded_buffer [pos];
if (c == '\n')
{
pos ;
int res = (foundCR) ? (pos - 2) : (pos - 1);
if (res < 0)
res = 0; // if a new buffer starts with a \n and there was a \r at
// the end of the previous one, we get here.
foundCR = false;
return res;
}
else if (foundCR)
{
foundCR = false;
return pos - 1;
}
foundCR = (c == '\r');
}
return -1;
}
public override string ReadLine()
{
if (base_stream == null)
throw new ObjectDisposedException ("StreamReader", "Cannot read from a closed StreamReader");
if (pos >= decoded_count && ReadBuffer () == 0)
return null;
int begin = pos;
int end = FindNextEOL ();
if (end < decoded_count && end >= begin)
return new string (decoded_buffer, begin, end - begin);
if (line_builder == null)
line_builder = new StringBuilder ();
else
line_builder.Length = 0;
while (true)
{
if (foundCR) // don't include the trailing CR if present
decoded_count--;
line_builder.Append (new string (decoded_buffer, begin, decoded_count - begin));
if (ReadBuffer () == 0)
{
if (line_builder.Capacity > 32768)
{
StringBuilder sb = line_builder;
line_builder = null;
return sb.ToString (0, sb.Length);
}
return line_builder.ToString (0, line_builder.Length);
}
begin = pos;
end = FindNextEOL ();
if (end < decoded_count && end >= begin)
{
line_builder.Append (new string (decoded_buffer, begin, end - begin));
if (line_builder.Capacity > 32768)
{
StringBuilder sb = line_builder;
line_builder = null;
return sb.ToString (0, sb.Length);
}
return line_builder.ToString (0, line_builder.Length);
}
}
}
public override string ReadToEnd()
{
if (base_stream == null)
throw new ObjectDisposedException ("StreamReader", "Cannot read from a closed StreamReader");
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!



