Index: UnicodeEncoding.cs =================================================================== RCS file: /cvs/public/mcs/class/corlib/System.Text/UnicodeEncoding.cs,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- UnicodeEncoding.cs 26 Aug 2002 14:46:37 -0000 1.10 +++ UnicodeEncoding.cs 19 Nov 2002 11:18:36 -0000 1.11 @@ -69,7 +69,7 @@ if (count < 0 || count > (chars.Length - index)) { throw new ArgumentOutOfRangeException ("count", _("ArgRange_Array")); } - return count * 2 + (byteOrderMark ? 2 : 0); + return count * 2; } // Convenience wrappers for "GetByteCount". @@ -78,7 +78,7 @@ if (s == null) { throw new ArgumentNullException ("s"); } - return s.Length * 2 + (byteOrderMark ? 2 : 0); + return s.Length * 2; } // Get the bytes that result from encoding a character buffer. @@ -100,26 +100,18 @@ if (byteIndex < 0 || byteIndex > bytes.Length) { throw new ArgumentOutOfRangeException ("byteIndex", _("ArgRange_Array")); } - if ((bytes.Length - byteIndex) < (charCount * 2 + (byteOrderMark ? 2 : 0))) { + if ((bytes.Length - byteIndex) < (charCount * 2)) { throw new ArgumentException (_("Arg_InsufficientSpace")); } int posn = byteIndex; char ch; if (bigEndian) { - if (byteOrderMark) { - bytes[posn++] = (byte)0xFE; - bytes[posn++] = (byte)0xFF; - } while (charCount-- > 0) { ch = chars[charIndex++]; bytes[posn++] = (byte)(ch >> 8); bytes[posn++] = (byte)ch; } } else { - if (byteOrderMark) { - bytes[posn++] = (byte)0xFF; - bytes[posn++] = (byte)0xFE; - } while (charCount-- > 0) { ch = chars[charIndex++]; bytes[posn++] = (byte)ch; @@ -148,26 +140,18 @@ if (byteIndex < 0 || byteIndex > bytes.Length) { throw new ArgumentOutOfRangeException ("byteIndex", _("ArgRange_Array")); } - if ((bytes.Length - byteIndex) < (charCount * 2 + (byteOrderMark ? 2 : 0))) { + if ((bytes.Length - byteIndex) < (charCount * 2)) { throw new ArgumentException (_("Arg_InsufficientSpace")); } int posn = byteIndex; char ch; if (bigEndian) { - if (byteOrderMark) { - bytes[posn++] = (byte)0xFE; - bytes[posn++] = (byte)0xFF; - } while (charCount-- > 0) { ch = s[charIndex++]; bytes[posn++] = (byte)(ch >> 8); bytes[posn++] = (byte)ch; } } else { - if (byteOrderMark) { - bytes[posn++] = (byte)0xFF; - bytes[posn++] = (byte)0xFE; - } while (charCount-- > 0) { ch = s[charIndex++]; bytes[posn++] = (byte)ch; @@ -270,7 +254,7 @@ if (charCount < 0) { throw new ArgumentOutOfRangeException ("charCount", _("ArgRange_NonNegative")); } - return charCount * 2 + (byteOrderMark ? 2 : 0); + return charCount * 2; } // Get the maximum number of characters needed to decode a Index: UTF8Encoding.cs =================================================================== RCS file: /cvs/public/mcs/class/corlib/System.Text/UTF8Encoding.cs,v retrieving revision 1.10 retrieving revision 1.12 diff -u -r1.10 -r1.12 --- UTF8Encoding.cs 6 Sep 2002 23:57:02 -0000 1.10 +++ UTF8Encoding.cs 19 Nov 2002 12:07:19 -0000 1.12 @@ -50,8 +50,7 @@ // Internal version of "GetByteCount" which can handle a rolling // state between multiple calls to this method. - private static int InternalGetByteCount (char[] chars, int index, int count, uint leftOver, - bool emitIdentifier, bool flush) + private static int InternalGetByteCount (char[] chars, int index, int count, uint leftOver, bool flush) { // Validate the parameters. if (chars == null) { @@ -104,13 +103,13 @@ } // Return the final length to the caller. - return length + (emitIdentifier ? 3 : 0); + return length; } // Get the number of bytes needed to encode a character buffer. public override int GetByteCount (char[] chars, int index, int count) { - return InternalGetByteCount (chars, index, count, 0, emitIdentifier, true); + return InternalGetByteCount (chars, index, count, 0, true); } // Convenience wrappers for "GetByteCount". @@ -150,15 +149,15 @@ } // Return the final length to the caller. - return length + (emitIdentifier ? 3 : 0); + return length; } // Internal version of "GetBytes" which can handle a rolling // state between multiple calls to this method. private static int InternalGetBytes (char[] chars, int charIndex, - int charCount, byte[] bytes, - int byteIndex, ref uint leftOver, - bool emitIdentifier, bool flush) + int charCount, byte[] bytes, + int byteIndex, ref uint leftOver, + bool flush) { // Validate the parameters. if (chars == null) { @@ -183,14 +182,6 @@ uint pair; uint left = leftOver; int posn = byteIndex; - if (emitIdentifier) { - if ((posn + 3) > length) { - throw new ArgumentException (_("Arg_InsufficientSpace"), "bytes"); - } - bytes[posn++] = (byte)0xEF; - bytes[posn++] = (byte)0xBB; - bytes[posn++] = (byte)0xBF; - } while (charCount > 0) { // Fetch the next UTF-16 character pair value. ch = chars[charIndex++]; @@ -272,8 +263,7 @@ byte[] bytes, int byteIndex) { uint leftOver = 0; - return InternalGetBytes (chars, charIndex, charCount, bytes, byteIndex, - ref leftOver, emitIdentifier, true); + return InternalGetBytes (chars, charIndex, charCount, bytes, byteIndex, ref leftOver, true); } // Convenience wrappers for "GetBytes". @@ -302,14 +292,6 @@ int length = bytes.Length; uint pair; int posn = byteIndex; - if (emitIdentifier) { - if ((posn + 3) > length) { - throw new ArgumentException (_("Arg_InsufficientSpace"), "bytes"); - } - bytes[posn++] = (byte)0xEF; - bytes[posn++] = (byte)0xBB; - bytes[posn++] = (byte)0xBF; - } while (charCount > 0) { // Fetch the next UTF-16 character pair value. ch = s[charIndex++]; @@ -614,7 +596,7 @@ if (charCount < 0) { throw new ArgumentOutOfRangeException ("charCount", _("ArgRange_NonNegative")); } - return charCount * 4 + (emitIdentifier ? 3 : 0); + return charCount * 4; } // Get the maximum number of characters needed to decode a @@ -797,14 +779,13 @@ public override int GetByteCount (char[] chars, int index, int count, bool flush) { - return InternalGetByteCount (chars, index, count, leftOver, emitIdentifier, flush); + return InternalGetByteCount (chars, index, count, leftOver, flush); } public override int GetBytes (char[] chars, int charIndex, int charCount, byte[] bytes, int byteCount, bool flush) { int result; - result = InternalGetBytes (chars, charIndex, charCount, bytes, byteCount, - ref leftOver, emitIdentifier, flush); + result = InternalGetBytes (chars, charIndex, charCount, bytes, byteCount, ref leftOver, flush); emitIdentifier = false; return result; } Index: ChangeLog =================================================================== RCS file: /cvs/public/mcs/class/corlib/System.Text/ChangeLog,v retrieving revision 1.32 retrieving revision 1.34 diff -u -r1.32 -r1.34 --- ChangeLog 13 Nov 2002 18:46:19 -0000 1.32 +++ ChangeLog 19 Nov 2002 12:07:19 -0000 1.34 @@ -1,3 +1,16 @@ + +Tue Nov 19 13:03:27 CET 2002 Paolo Molaro + + * UTF8Encoding.cs: fix GetByteCount (), too. + +2002-11-19 Miguel de Icaza + + * UnicodeEncoding.cs: the bytemark should only be used to return + information in GetPreamble, not to actually encode the information + on the stream. That is taken care of by the Stream classes. + + * UTF8Encoding.cs: ditto. + 2002-11-13 Gonzalo Paniagua Javier * StringBuilder.cs: only move the remaining chars in Remove.