[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/IO StreamReader.cs,1.
From: |
Thong Nguyen <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/IO StreamReader.cs,1.8,1.9 |
Date: |
Fri, 04 Jul 2003 22:04:21 -0400 |
Update of /cvsroot/dotgnu-pnet/pnetlib/runtime/System/IO
In directory subversions:/tmp/cvs-serv401
Modified Files:
StreamReader.cs
Log Message:
Changed so encoding detection occurs on the first call to Read() rather
than in the constructor.
Index: StreamReader.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/runtime/System/IO/StreamReader.cs,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -r1.8 -r1.9
*** StreamReader.cs 10 May 2003 17:27:11 -0000 1.8
--- StreamReader.cs 5 Jul 2003 02:04:19 -0000 1.9
***************
*** 52,55 ****
--- 52,56 ----
private bool sawEOF;
private bool streamOwner;
+ private bool encodingDetected;
// Constructors that are based on a stream.
***************
*** 104,113 ****
this.sawEOF = false;
this.streamOwner = false;
!
! // Should we change encodings based on a byte
order mark?
! if(detectEncodingFromByteOrderMarks)
! {
! DetectByteOrder();
! }
// Get a decoder for the encoding.
--- 105,109 ----
this.sawEOF = false;
this.streamOwner = false;
! this.encodingDetected =
!detectEncodingFromByteOrderMarks;
// Get a decoder for the encoding.
***************
*** 168,177 ****
this.sawEOF = false;
this.streamOwner = true;
!
! // Should we change encodings based on a byte
order mark?
! if(detectEncodingFromByteOrderMarks)
! {
! DetectByteOrder();
! }
// Get a decoder for the encoding.
--- 164,168 ----
this.sawEOF = false;
this.streamOwner = true;
! this.encodingDetected =
!detectEncodingFromByteOrderMarks;
// Get a decoder for the encoding.
***************
*** 182,218 ****
private void DetectByteOrder()
{
! // Pre-read the first full buffer of input data.
! inBufferLen = stream.Read(inBuffer, 0,
bufferSize);
! if(inBufferLen <= 0)
{
! sawEOF = true;
! inBufferLen = 0;
}
// Check for recognized byte order marks.
if(inBufferLen >= 2 &&
! inBuffer[0] == 0xFF &&
! inBuffer[1] == 0xFE)
{
// Little-endian UTF-16.
encoding = Encoding.Unicode;
inBufferPosn = 2;
}
else if(inBufferLen >= 2 &&
! inBuffer[0] == 0xFE &&
! inBuffer[1] == 0xFF)
{
// Big-endian UTF-16.
encoding = Encoding.BigEndianUnicode;
inBufferPosn = 2;
}
else if(inBufferLen >= 3 &&
! inBuffer[0] == 0xEF &&
! inBuffer[1] == 0xBB &&
! inBuffer[2] == 0xBF)
{
// UTF-8.
encoding = Encoding.UTF8;
! inBufferPosn = 3;
}
}
--- 173,245 ----
private void DetectByteOrder()
{
! if(inBufferLen < 1)
{
! return;
}
// Check for recognized byte order marks.
if(inBufferLen >= 2 &&
! inBuffer[0] == 0xFF &&
! inBuffer[1] == 0xFE)
{
// Little-endian UTF-16.
encoding = Encoding.Unicode;
inBufferPosn = 2;
+ decoder = encoding.GetDecoder();
+ encodingDetected = true;
}
else if(inBufferLen >= 2 &&
! inBuffer[0] == 0xFE &&
! inBuffer[1] == 0xFF)
{
// Big-endian UTF-16.
encoding = Encoding.BigEndianUnicode;
inBufferPosn = 2;
+ decoder = encoding.GetDecoder();
+ encodingDetected = true;
}
else if(inBufferLen >= 3 &&
! inBuffer[0] == 0xEF &&
! inBuffer[1] == 0xBB &&
! inBuffer[2] == 0xBF)
{
// UTF-8.
encoding = Encoding.UTF8;
! inBufferPosn = 3;
! decoder = encoding.GetDecoder();
! encodingDetected = true;
! }
! else
! {
! // Here we cancel the encoding
detection if the marker bytes aren't recognised
!
! if(inBufferLen >= 1)
! {
! if(!(inBuffer[0] == 0xFF ||
inBuffer[0] == 0xFE
! || inBuffer[0] == 0xEF))
! {
! /* Cancel encoding
detection. Go with default. */
!
! encodingDetected = true;
! }
! else if(inBufferLen >= 2)
! {
! if(!(inBuffer[1] ==
0xFE || inBuffer[1] == 0xFF || inBuffer[1] == 0xBB))
! {
! /* Cancel
encoding detection. Go with default. */
!
!
encodingDetected = true;
! }
! else if(inBufferLen >=
3)
! {
!
if(!(inBuffer[3] == 0xBF))
! {
! /*
Cancel encoding detection. Go with default. */
!
!
encodingDetected = true;
! }
! }
! }
! }
}
}
***************
*** 273,306 ****
while(outBufferPosn >= outBufferLen && !sawEOF)
{
! // Move the previous left-over buffer
contents down.
! if((inBufferLen - inBufferPosn) <
bufferSize)
{
! if(inBufferPosn < inBufferLen)
! {
! Array.Copy
! (inBuffer,
inBufferPosn,
! inBuffer, 0,
inBufferLen - inBufferPosn);
! inBufferLen -=
inBufferPosn;
! }
! else
{
! inBufferLen = 0;
! }
! inBufferPosn = 0;
! // Read new bytes into the
buffer.
! if(stream == null)
! {
! throw new
IOException(_("IO_StreamClosed"));
! }
! len = stream.Read(inBuffer,
inBufferLen,
!
bufferSize - inBufferLen);
! if(len <= 0)
{
! sawEOF = true;
! }
! else
! {
! inBufferLen += len;
}
}
--- 300,368 ----
while(outBufferPosn >= outBufferLen && !sawEOF)
{
! // This loop exits when there is an EOF
or some bytes have been read and
! // the encoding has been detected.
!
! while(true)
{
! // Move the previous left-over
buffer contents down.
! if((inBufferLen - inBufferPosn)
< bufferSize)
{
! if(inBufferPosn <
inBufferLen)
! {
! Array.Copy
!
(inBuffer, inBufferPosn,
!
inBuffer, 0, inBufferLen - inBufferPosn);
! inBufferLen -=
inBufferPosn;
! }
! else
! {
! inBufferLen = 0;
! }
!
! inBufferPosn = 0;
!
! // Read new bytes into
the buffer.
! if(stream == null)
! {
! throw new
IOException(_("IO_StreamClosed"));
! }
!
! len =
stream.Read(inBuffer, inBufferLen,
! bufferSize -
inBufferLen);
!
! if(len <= 0)
! {
!
if(!encodingDetected)
! {
!
inBufferLen = 0;
!
inBufferPosn = 0;
! }
!
! sawEOF = true;
!
! break;
! }
! else
! {
! inBufferLen +=
len;
! }
! }
! if(inBufferLen > 0)
{
! if(!encodingDetected)
! {
! // Try to
detect the encoding
!
!
DetectByteOrder();
! }
!
! if(encodingDetected &&
(inBufferLen - inBufferPosn > 0))
! {
! // Only exit if
the encoding has been detected and some bytes
! // have been
read.
!
! break;
! }
}
}
***************
*** 315,320 ****
// Convert the bytes into characters.
! outLen = decoder.GetChars(inBuffer,
inBufferPosn, len,
!
outBuffer, 0);
outBufferPosn = 0;
outBufferLen = outLen;
--- 377,381 ----
// Convert the bytes into characters.
! outLen = decoder.GetChars(inBuffer,
inBufferPosn, len, outBuffer, 0);
outBufferPosn = 0;
outBufferLen = outLen;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/IO StreamReader.cs,1.8,1.9,
Thong Nguyen <address@hidden> <=