Imported Upstream version 3.10.0

Former-commit-id: 172c8e3c300b39d5785c7a3e8dfb08ebdbc1a99b
This commit is contained in:
Jo Shields
2014-10-04 11:27:48 +01:00
parent fe777c5c82
commit 8b9b85e7f5
970 changed files with 20242 additions and 31308 deletions

View File

@ -1040,17 +1040,12 @@ public abstract class Encoding : ICloneable
}
// Forwarding decoder implementation.
private sealed class ForwardingDecoder : Decoder
private sealed class ForwardingDecoder : EncodingDecoder
{
private Encoding encoding;
// Constructor.
public ForwardingDecoder (Encoding enc)
: base (enc)
{
encoding = enc;
DecoderFallback fallback = encoding.DecoderFallback;
if (fallback != null)
Fallback = fallback;
}
// Override inherited methods.
@ -1068,17 +1063,12 @@ public abstract class Encoding : ICloneable
} // class ForwardingDecoder
// Forwarding encoder implementation.
private sealed class ForwardingEncoder : Encoder
private sealed class ForwardingEncoder : EncodingEncoder
{
private Encoding encoding;
// Constructor.
public ForwardingEncoder (Encoding enc)
: base (enc)
{
encoding = enc;
EncoderFallback fallback = encoding.EncoderFallback;
if (fallback != null)
Fallback = fallback;
}
// Override inherited methods.

View File

@ -0,0 +1,102 @@
//
// System.Text.EncodingDecoder.cs
//
// Authors:
// Marcos Henrich (marcos.henrich@xamarin.com)
//
// Copyright (C) 2014 Xamarin Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Runtime.InteropServices;
namespace System.Text {
abstract class EncodingDecoder : Decoder {
protected readonly Encoding encoding;
// Constructor.
protected EncodingDecoder (Encoding encoding)
{
this.encoding = encoding;
var fallback = encoding.DecoderFallback;
if (fallback != null)
Fallback = fallback;
}
public unsafe override void Convert (
byte* bytes, int byteCount,
char* chars, int charCount, bool flush,
out int bytesUsed, out int charsUsed, out bool completed)
{
if (chars == null)
throw new ArgumentNullException ("chars");
if (bytes == null)
throw new ArgumentNullException ("bytes");
if (charCount < 0)
throw new ArgumentOutOfRangeException ("charCount");
if (byteCount < 0)
throw new ArgumentOutOfRangeException ("byteCount");
bytesUsed = encoding.GetByteCount(chars, charCount);
if (bytesUsed > byteCount) {
charsUsed = encoding.GetChars (bytes, byteCount, chars, charCount);
bytesUsed = encoding.GetByteCount (chars, charsUsed);
} else
charsUsed = encoding.GetChars (bytes, bytesUsed, chars, charCount);
completed = bytesUsed == byteCount;
}
public override void Convert (
byte [] bytes, int byteIndex, int byteCount,
char [] chars, int charIndex, int charCount, bool flush,
out int bytesUsed, out int charsUsed, out bool completed)
{
if (chars == null)
throw new ArgumentNullException ("chars");
if (bytes == null)
throw new ArgumentNullException ("bytes");
if (charIndex < 0)
throw new ArgumentOutOfRangeException ("charIndex");
if (charCount < 0 || chars.Length < charIndex + charCount)
throw new ArgumentOutOfRangeException ("charCount");
if (byteIndex < 0)
throw new ArgumentOutOfRangeException ("byteIndex");
if (byteCount < 0 || bytes.Length < byteIndex + byteCount)
throw new ArgumentOutOfRangeException ("byteCount");
bytesUsed = encoding.GetByteCount(chars, charIndex, charCount);
if (bytesUsed > byteCount) {
charsUsed = encoding.GetChars (bytes, byteIndex, byteCount, chars, charIndex);
bytesUsed = encoding.GetByteCount (chars, charIndex, charsUsed);
} else
charsUsed = encoding.GetChars (bytes, byteIndex, bytesUsed, chars, charIndex);
completed = bytesUsed == byteCount;
}
}; // class EncodingDecoder
}; // namespace System.Text

View File

@ -0,0 +1,99 @@
//
// System.Text.EncodingEncoder.cs
//
// Authors:
// Marcos Henrich (marcos.henrich@xamarin.com)
//
// Copyright (C) 2014 Xamarin Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Runtime.InteropServices;
namespace System.Text {
abstract class EncodingEncoder : Encoder {
protected readonly Encoding encoding;
// Constructor.
protected EncodingEncoder (Encoding encoding)
{
this.encoding = encoding;
var fallback = encoding.EncoderFallback;
if (fallback != null)
Fallback = fallback;
}
public unsafe override void Convert (
char* chars, int charCount,
byte* bytes, int byteCount, bool flush,
out int charsUsed, out int bytesUsed, out bool completed)
{
if (chars == null)
throw new ArgumentNullException ("chars");
if (bytes == null)
throw new ArgumentNullException ("bytes");
if (charCount < 0)
throw new ArgumentOutOfRangeException ("charCount");
if (byteCount < 0)
throw new ArgumentOutOfRangeException ("byteCount");
charsUsed = encoding.GetCharCount (bytes, byteCount);
if (charsUsed > charCount)
charsUsed = charCount;
bytesUsed = encoding.GetBytes (chars, charsUsed, bytes, byteCount);
completed = charsUsed == charCount;
}
public override void Convert (
char [] chars, int charIndex, int charCount,
byte [] bytes, int byteIndex, int byteCount, bool flush,
out int charsUsed, out int bytesUsed, out bool completed)
{
if (chars == null)
throw new ArgumentNullException ("chars");
if (bytes == null)
throw new ArgumentNullException ("bytes");
if (charIndex < 0)
throw new ArgumentOutOfRangeException ("charIndex");
if (charCount < 0 || chars.Length < charIndex + charCount)
throw new ArgumentOutOfRangeException ("charCount");
if (byteIndex < 0)
throw new ArgumentOutOfRangeException ("byteIndex");
if (byteCount < 0 || bytes.Length < byteIndex + byteCount)
throw new ArgumentOutOfRangeException ("byteCount");
charsUsed = encoding.GetCharCount (bytes, byteIndex, byteCount);
if (charsUsed > charCount)
charsUsed = charCount;
bytesUsed = encoding.GetBytes (chars, charIndex, charsUsed, bytes, byteIndex);
completed = charsUsed == charCount;
}
}; // class EncodingEncoder
}; // namespace System.Text

View File

@ -604,23 +604,24 @@ class UTF7Encoding : Encoding
// Get a UTF7-specific decoder that is attached to this instance.
public override Decoder GetDecoder ()
{
return new UTF7Decoder ();
return new UTF7Decoder (this);
}
// Get a UTF7-specific encoder that is attached to this instance.
public override Encoder GetEncoder ()
{
return new UTF7Encoder (allowOptionals);
return new UTF7Encoder (allowOptionals, this);
}
// UTF-7 decoder implementation.
private sealed class UTF7Decoder : Decoder
private sealed class UTF7Decoder : EncodingDecoder
{
// Internal state.
private int leftOver;
// Constructor.
public UTF7Decoder ()
public UTF7Decoder (Encoding encoding)
: base (encoding)
{
leftOver = 0;
}
@ -640,14 +641,15 @@ class UTF7Encoding : Encoding
} // class UTF7Decoder
// UTF-7 encoder implementation.
private sealed class UTF7Encoder : Encoder
private sealed class UTF7Encoder : EncodingEncoder
{
private bool allowOptionals;
private int leftOver = 0;
private bool isInShifted = false;
// Constructor.
public UTF7Encoder (bool allowOptionals)
public UTF7Encoder (bool allowOptionals, UTF7Encoding encoding)
: base (encoding)
{
this.allowOptionals = allowOptionals;
}

View File

@ -882,13 +882,13 @@ fail_no_space:
// Get a UTF8-specific decoder that is attached to this instance.
public override Decoder GetDecoder ()
{
return new UTF8Decoder (DecoderFallback);
return new UTF8Decoder (this);
}
// Get a UTF8-specific encoder that is attached to this instance.
public override Encoder GetEncoder ()
{
return new UTF8Encoder (EncoderFallback, emitIdentifier);
return new UTF8Encoder (this);
}
// Get the UTF8 preamble.
@ -935,15 +935,15 @@ fail_no_space:
// UTF-8 decoder implementation.
[Serializable]
private class UTF8Decoder : Decoder
private class UTF8Decoder : EncodingDecoder
{
private uint leftOverBits;
private uint leftOverCount;
// Constructor.
public UTF8Decoder (DecoderFallback fallback)
public UTF8Decoder (Encoding encoding)
: base (encoding)
{
Fallback = fallback;
leftOverBits = 0;
leftOverCount = 0;
}
@ -969,17 +969,16 @@ fail_no_space:
// UTF-8 encoder implementation.
[Serializable]
private class UTF8Encoder : Encoder
private class UTF8Encoder : EncodingEncoder
{
// private bool emitIdentifier;
private char leftOverForCount;
private char leftOverForConv;
// Constructor.
public UTF8Encoder (EncoderFallback fallback, bool emitIdentifier)
public UTF8Encoder (UTF8Encoding encoding)
: base (encoding)
{
Fallback = fallback;
// this.emitIdentifier = emitIdentifier;
leftOverForCount = '\0';
leftOverForConv = '\0';
}

View File

@ -362,7 +362,7 @@ public class UnicodeEncoding : Encoding
// Get a Unicode-specific decoder that is attached to this instance.
public override Decoder GetDecoder ()
{
return new UnicodeDecoder (bigEndian);
return new UnicodeDecoder (bigEndian, this);
}
// Get the Unicode preamble.
@ -516,13 +516,14 @@ public class UnicodeEncoding : Encoding
}
// Unicode decoder implementation.
private sealed class UnicodeDecoder : Decoder
private sealed class UnicodeDecoder : EncodingDecoder
{
private bool bigEndian;
private int leftOverByte;
// Constructor.
public UnicodeDecoder (bool bigEndian)
public UnicodeDecoder (bool bigEndian, UnicodeEncoding encoding)
: base (encoding)
{
this.bigEndian = bigEndian;
leftOverByte = -1;