手机站
网通分站
电信主站
密 码:
用户名:
当前位置 : 主页>网络编程>Asp.Net编程>列表

动态修改.Net StreamReader Encoding编码

来源:互联网 作者:west263.com 时间:2008-02-22
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!

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
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!