Imported Upstream version 4.0.0~alpha1

Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
This commit is contained in:
Jo Shields
2015-04-07 09:35:12 +01:00
parent 283343f570
commit 3c1f479b9d
22469 changed files with 2931443 additions and 869343 deletions

View File

@@ -1,363 +0,0 @@
/*
* ASCIIEncoding.cs - Implementation of the "System.Text.ASCIIEncoding" class.
*
* Copyright (c) 2001 Southern Storm Software, Pty Ltd
* Copyright (C) 2003 Novell, Inc.
* Copyright (C) 2004 Novell, Inc (http://www.novell.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.
*/
namespace System.Text
{
using System;
using System.Runtime.InteropServices;
[Serializable]
[ComVisible (true)]
[MonoLimitation ("Serialization format not compatible with .NET")]
public class ASCIIEncoding : Encoding
{
// Magic number used by Windows for "ASCII".
internal const int ASCII_CODE_PAGE = 20127;
// Constructor.
public ASCIIEncoding () : base(ASCII_CODE_PAGE) {
body_name = header_name = web_name= "us-ascii";
encoding_name = "US-ASCII";
is_mail_news_display = true;
is_mail_news_save = true;
}
[ComVisible (false)]
public override bool IsSingleByte {
get { return true; }
}
// Get the number of bytes needed to encode a character buffer.
public override int GetByteCount (char[] chars, int index, int count)
{
if (chars == null) {
throw new ArgumentNullException ("chars");
}
if (index < 0 || index > chars.Length) {
throw new ArgumentOutOfRangeException ("index", _("ArgRange_Array"));
}
if (count < 0 || count > (chars.Length - index)) {
throw new ArgumentOutOfRangeException ("count", _("ArgRange_Array"));
}
return count;
}
// Convenience wrappers for "GetByteCount".
public override int GetByteCount (String chars)
{
if (chars == null) {
throw new ArgumentNullException ("chars");
}
return chars.Length;
}
// Get the bytes that result from encoding a character buffer.
public override int GetBytes (char[] chars, int charIndex, int charCount,
byte[] bytes, int byteIndex)
{
EncoderFallbackBuffer buffer = null;
char [] fallback_chars = null;
return GetBytes (chars, charIndex, charCount, bytes, byteIndex,
ref buffer, ref fallback_chars);
}
int GetBytes (char[] chars, int charIndex, int charCount,
byte[] bytes, int byteIndex,
ref EncoderFallbackBuffer buffer,
ref char [] fallback_chars)
{
if (chars == null)
throw new ArgumentNullException ("chars");
unsafe {
fixed (char *cptr = chars) {
return InternalGetBytes (cptr, chars.Length, charIndex, charCount, bytes, byteIndex, ref buffer, ref fallback_chars);
}
}
}
// Convenience wrappers for "GetBytes".
public override int GetBytes (String chars, int charIndex, int charCount, byte[] bytes, int byteIndex)
{
EncoderFallbackBuffer buffer = null;
char [] fallback_chars = null;
return GetBytes (chars, charIndex, charCount, bytes, byteIndex,
ref buffer, ref fallback_chars);
}
int GetBytes (String chars, int charIndex, int charCount,
byte[] bytes, int byteIndex,
ref EncoderFallbackBuffer buffer,
ref char [] fallback_chars)
{
if (chars == null)
throw new ArgumentNullException ("chars");
unsafe {
fixed (char *cptr = chars) {
return InternalGetBytes (cptr, chars.Length, charIndex, charCount, bytes, byteIndex, ref buffer, ref fallback_chars);
}
}
}
unsafe int InternalGetBytes (char *chars, int charLength, int charIndex, int charCount,
byte[] bytes, int byteIndex,
ref EncoderFallbackBuffer buffer,
ref char [] fallback_chars)
{
if (bytes == null)
throw new ArgumentNullException ("bytes");
if (charIndex < 0 || charIndex > charLength)
throw new ArgumentOutOfRangeException ("charIndex", _("ArgRange_StringIndex"));
if (charCount < 0 || charCount > (charLength - charIndex))
throw new ArgumentOutOfRangeException ("charCount", _("ArgRange_StringRange"));
if (byteIndex < 0 || byteIndex > bytes.Length)
throw new ArgumentOutOfRangeException ("byteIndex", _("ArgRange_Array"));
if ((bytes.Length - byteIndex) < charCount)
throw new ArgumentException (_("Arg_InsufficientSpace"));
int count = charCount;
char ch;
while (count-- > 0) {
ch = chars [charIndex++];
if (ch < (char)0x80) {
bytes [byteIndex++] = (byte)ch;
} else {
if (buffer == null)
buffer = EncoderFallback.CreateFallbackBuffer ();
if (Char.IsSurrogate (ch) && count > 1 &&
Char.IsSurrogate (chars [charIndex]))
buffer.Fallback (ch, chars [charIndex], charIndex++ - 1);
else
buffer.Fallback (ch, charIndex - 1);
if (fallback_chars == null || fallback_chars.Length < buffer.Remaining)
fallback_chars = new char [buffer.Remaining];
for (int i = 0; i < fallback_chars.Length; i++)
fallback_chars [i] = buffer.GetNextChar ();
byteIndex += GetBytes (fallback_chars, 0,
fallback_chars.Length, bytes, byteIndex,
ref buffer, ref fallback_chars);
}
}
return charCount;
}
// Get the number of characters needed to decode a byte buffer.
public override int GetCharCount (byte[] bytes, int index, int count)
{
if (bytes == null) {
throw new ArgumentNullException ("bytes");
}
if (index < 0 || index > bytes.Length) {
throw new ArgumentOutOfRangeException ("index", _("ArgRange_Array"));
}
if (count < 0 || count > (bytes.Length - index)) {
throw new ArgumentOutOfRangeException ("count", _("ArgRange_Array"));
}
return count;
}
// Get the characters that result from decoding a byte buffer.
public override int GetChars (byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
{
DecoderFallbackBuffer buffer = null;
return GetChars (bytes, byteIndex, byteCount, chars,
charIndex, ref buffer);
}
int GetChars (byte[] bytes, int byteIndex, int byteCount,
char[] chars, int charIndex,
ref DecoderFallbackBuffer buffer)
{
if (bytes == null)
throw new ArgumentNullException ("bytes");
if (chars == null)
throw new ArgumentNullException ("chars");
if (byteIndex < 0 || byteIndex > bytes.Length)
throw new ArgumentOutOfRangeException ("byteIndex", _("ArgRange_Array"));
if (byteCount < 0 || byteCount > (bytes.Length - byteIndex))
throw new ArgumentOutOfRangeException ("byteCount", _("ArgRange_Array"));
if (charIndex < 0 || charIndex > chars.Length)
throw new ArgumentOutOfRangeException ("charIndex", _("ArgRange_Array"));
if ((chars.Length - charIndex) < byteCount)
throw new ArgumentException (_("Arg_InsufficientSpace"));
int count = byteCount;
while (count-- > 0) {
char c = (char) bytes [byteIndex++];
if (c < '\x80')
chars [charIndex++] = c;
else {
if (buffer == null)
buffer = DecoderFallback.CreateFallbackBuffer ();
var thisByte = new byte[] { bytes [byteIndex-1] };
buffer.Fallback (thisByte, 0);
while (buffer.Remaining > 0) {
if (charIndex < chars.Length) {
chars [charIndex++] = buffer.GetNextChar ();
continue;
}
throw new ArgumentException (
"The output char buffer is too small to contain the " +
"decoded characters.");
}
}
}
return byteCount;
}
// Get the maximum number of bytes needed to encode a
// specified number of characters.
public override int GetMaxByteCount (int charCount)
{
if (charCount < 0) {
throw new ArgumentOutOfRangeException ("charCount", _("ArgRange_NonNegative"));
}
return charCount;
}
// Get the maximum number of characters needed to decode a
// specified number of bytes.
public override int GetMaxCharCount (int byteCount)
{
if (byteCount < 0) {
throw new ArgumentOutOfRangeException ("byteCount", _("ArgRange_NonNegative"));
}
return byteCount;
}
// Decode a buffer of bytes into a string.
public override String GetString (byte[] bytes, int byteIndex, int byteCount)
{
if (bytes == null) {
throw new ArgumentNullException ("bytes");
}
if (byteIndex < 0 || byteIndex > bytes.Length) {
throw new ArgumentOutOfRangeException ("byteIndex", _("ArgRange_Array"));
}
if (byteCount < 0 || byteCount > (bytes.Length - byteIndex)) {
throw new ArgumentOutOfRangeException ("byteCount", _("ArgRange_Array"));
}
if (byteCount == 0)
return String.Empty;
unsafe {
fixed (byte* bytePtr = bytes) {
string s = string.InternalAllocateStr (byteCount);
fixed (char* charPtr = s) {
byte* currByte = bytePtr + byteIndex;
byte* lastByte = currByte + byteCount;
char* currChar = charPtr;
while (currByte < lastByte) {
byte b = currByte++ [0];
currChar++ [0] = b <= 0x7F ? (char) b : (char) '?';
}
}
return s;
}
}
}
[CLSCompliantAttribute (false)]
[ComVisible (false)]
public unsafe override int GetBytes (char *chars, int charCount, byte *bytes, int byteCount)
{
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");
if (byteCount < charCount)
throw new ArgumentException ("bytecount is less than the number of bytes required", "byteCount");
for (int i = 0; i < charCount; i++){
char c = chars [i];
bytes [i] = (byte) ((c < (char) 0x80) ? c : '?');
}
return charCount;
}
[CLSCompliantAttribute(false)]
[ComVisible (false)]
public unsafe override int GetChars (byte *bytes, int byteCount, char *chars, int charCount)
{
if (bytes == null)
throw new ArgumentNullException ("bytes");
if (chars == null)
throw new ArgumentNullException ("chars");
if (charCount < 0)
throw new ArgumentOutOfRangeException ("charCount");
if (byteCount < 0)
throw new ArgumentOutOfRangeException ("byteCount");
if (charCount < byteCount)
throw new ArgumentException ("charcount is less than the number of bytes required", "charCount");
for (int i = 0; i < byteCount; i++){
byte b = bytes [i];
chars [i] = b > 127 ? '?' : (char) b;
}
return byteCount;
}
[CLSCompliantAttribute(false)]
[ComVisible (false)]
public unsafe override int GetCharCount (byte *bytes, int count)
{
return count;
}
[CLSCompliantAttribute(false)]
[ComVisible (false)]
public unsafe override int GetByteCount (char *chars, int count)
{
return count;
}
[ComVisible (false)]
public override Decoder GetDecoder ()
{
return base.GetDecoder ();
}
[ComVisible (false)]
public override Encoder GetEncoder ()
{
return base.GetEncoder ();
}
}; // class ASCIIEncoding
}; // namespace System.Text

View File

@@ -1,137 +0,0 @@
//
// System.Text.CodePageEncoding.cs
//
// Author:
// Kornél Pál <http://www.kornelpal.hu/>
//
// Copyright (C) 2006 Kornél Pál
//
//
// 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.
//
//
// These proxy classes implement IObjectReference.GetRealObject() that returns
// an instance of the appropriate Encoding, Encoder or Decoder class.
// As a result serialized objects of these types will transparently be
// deserialized to instances of the above described classes.
//
// Use SerializationInfo.SetType() in ISerializable.GetObjectData() method of
// serializable classes to serialize their instances using a proxy class.
//
// All of these proxy classes are non-public thus they only have to be
// serialization compatible with .NET Framework.
//
//
// .NET Framework 1.x uses this class for internal encodings and
// .NET Framework 2.0 serializes internal encodings using a proxy.
// This class supports serialization compatibility.
//
using System;
using System.Runtime.Serialization;
namespace System.Text
{
[Serializable]
internal sealed class CodePageEncoding : ISerializable, IObjectReference
{
//
// .NET Framework 1.x uses this class for internal decoders and
// .NET Framework 2.0 can deserialize them using a proxy.
// This class supports serialization compatibility.
//
[Serializable]
private sealed class Decoder : ISerializable, IObjectReference
{
private Encoding encoding;
private System.Text.Decoder realObject;
private Decoder (SerializationInfo info, StreamingContext context)
{
if (info == null)
throw new ArgumentNullException ("info");
this.encoding = (Encoding) info.GetValue ("encoding", typeof (Encoding));
}
public void GetObjectData (SerializationInfo info, StreamingContext context)
{
throw new ArgumentException ("This class cannot be serialized.");
}
public object GetRealObject (StreamingContext context)
{
if (this.realObject == null)
this.realObject = this.encoding.GetDecoder ();
return this.realObject;
}
}
private int codePage;
private bool isReadOnly;
private EncoderFallback encoderFallback;
private DecoderFallback decoderFallback;
private Encoding realObject;
private CodePageEncoding (SerializationInfo info, StreamingContext context)
{
if (info == null)
throw new ArgumentNullException ("info");
this.codePage = (int) info.GetValue ("m_codePage", typeof (int));
try {
this.isReadOnly = (bool) info.GetValue ("m_isReadOnly", typeof (bool));
this.encoderFallback = (EncoderFallback) info.GetValue ("encoderFallback", typeof (EncoderFallback));
this.decoderFallback = (DecoderFallback) info.GetValue ("decoderFallback", typeof (DecoderFallback));
} catch (SerializationException) {
// .NET Framework 1.x has no fallbacks
this.isReadOnly = true;
}
}
public void GetObjectData (SerializationInfo info, StreamingContext context)
{
throw new ArgumentException ("This class cannot be serialized.");
}
public object GetRealObject (StreamingContext context)
{
if (this.realObject == null) {
Encoding encoding = Encoding.GetEncoding (this.codePage);
if (!this.isReadOnly) {
encoding = (Encoding) encoding.Clone ();
encoding.EncoderFallback = this.encoderFallback;
encoding.DecoderFallback = this.decoderFallback;
}
this.realObject = encoding;
}
return this.realObject;
}
}
}

View File

@@ -1,203 +0,0 @@
/*
* Decoder.cs - Implementation of the "System.Text.Decoder" class.
*
* Copyright (c) 2001 Southern Storm Software, Pty Ltd
*
* 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.
*/
namespace System.Text
{
using System;
using System.Runtime.InteropServices;
[Serializable]
[ComVisible (true)]
public abstract class Decoder
{
// Constructor.
protected Decoder () {}
DecoderFallback fallback = new DecoderReplacementFallback ();
DecoderFallbackBuffer fallback_buffer;
[ComVisible (false)]
public DecoderFallback Fallback {
get { return fallback; }
set {
if (value == null)
throw new ArgumentNullException ();
fallback = value;
fallback_buffer = null;
}
}
[ComVisible (false)]
public DecoderFallbackBuffer FallbackBuffer {
get {
if (fallback_buffer == null)
fallback_buffer = fallback.CreateFallbackBuffer ();
return fallback_buffer;
}
}
// Get the number of characters needed to decode a buffer.
public abstract int GetCharCount (byte[] bytes, int index, int count);
// Get the characters that result from decoding a buffer.
public abstract int GetChars (byte[] bytes, int byteIndex, int byteCount,
char[] chars, int charIndex);
[ComVisible (false)]
public virtual int GetCharCount (byte [] bytes, int index, int count, bool flush)
{
if (flush)
Reset ();
return GetCharCount (bytes, index, count);
}
[CLSCompliant (false)]
[ComVisible (false)]
public unsafe virtual int GetCharCount (byte* bytes, int count, bool flush)
{
if (bytes == null)
throw new ArgumentNullException ("bytes");
if (count < 0)
throw new ArgumentOutOfRangeException ("count");
byte [] barr = new byte [count];
Marshal.Copy ((IntPtr) bytes, barr, 0, count);
return GetCharCount (barr, 0, count, flush);
}
public virtual int GetChars (
byte[] bytes, int byteIndex, int byteCount,
char[] chars, int charIndex, bool flush)
{
CheckArguments (bytes, byteIndex, byteCount);
CheckArguments (chars, charIndex);
if (flush)
Reset ();
return GetChars (bytes, byteIndex, byteCount, chars, charIndex);
}
[CLSCompliant (false)]
[ComVisible (false)]
public unsafe virtual int GetChars (byte* bytes, int byteCount,
char* chars, int charCount, bool flush)
{
CheckArguments (chars, charCount, bytes, byteCount);
char [] carr = new char [charCount];
byte [] barr = new byte [byteCount];
Marshal.Copy ((IntPtr) bytes, barr, 0, byteCount);
int charsUsed = GetChars (barr, 0, byteCount, carr, 0, flush);
Marshal.Copy (carr, 0, (IntPtr) chars, charsUsed);
return charsUsed;
}
[ComVisible (false)]
public virtual void Reset ()
{
if (fallback_buffer != null)
fallback_buffer.Reset ();
}
[CLSCompliant (false)]
[ComVisible (false)]
public unsafe virtual void Convert (
byte* bytes, int byteCount,
char* chars, int charCount, bool flush,
out int bytesUsed, out int charsUsed, out bool completed)
{
CheckArguments (chars, charCount, bytes, byteCount);
bytesUsed = byteCount;
while (true) {
charsUsed = GetCharCount (bytes, bytesUsed, flush);
if (charsUsed <= charCount)
break;
flush = false;
bytesUsed >>= 1;
}
completed = bytesUsed == byteCount;
charsUsed = GetChars (bytes, bytesUsed, chars, charCount, flush);
}
[ComVisible (false)]
public virtual 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)
{
CheckArguments (bytes, byteIndex, byteCount);
if (chars == null)
throw new ArgumentNullException ("chars");
if (charIndex < 0)
throw new ArgumentOutOfRangeException ("charIndex");
if (charCount < 0 || chars.Length < charIndex + charCount)
throw new ArgumentOutOfRangeException ("charCount");
bytesUsed = byteCount;
while (true) {
charsUsed = GetCharCount (bytes, byteIndex, bytesUsed, flush);
if (charsUsed <= charCount)
break;
flush = false;
bytesUsed >>= 1;
}
completed = bytesUsed == byteCount;
charsUsed = GetChars (bytes, byteIndex, bytesUsed, chars, charIndex, flush);
}
void CheckArguments (char [] chars, int charIndex)
{
if (chars == null)
throw new ArgumentNullException ("chars");
if (charIndex < 0 || chars.Length < charIndex)
throw new ArgumentOutOfRangeException ("charIndex");
}
void CheckArguments (byte [] bytes, int byteIndex, int byteCount)
{
if (bytes == null)
throw new ArgumentNullException ("bytes");
if (byteIndex < 0)
throw new ArgumentOutOfRangeException ("byteIndex");
if (byteCount < 0 || bytes.Length < byteIndex + byteCount)
throw new ArgumentOutOfRangeException ("byteCount");
}
unsafe void CheckArguments (char* chars, int charCount, byte* bytes, int byteCount)
{
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");
}
}; // class Decoder
}; // namespace System.Text

View File

@@ -1,58 +0,0 @@
//
// DecoderExceptionFallback.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.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.
//
namespace System.Text
{
[Serializable]
public sealed class DecoderExceptionFallback : DecoderFallback
{
public DecoderExceptionFallback ()
{
}
public override int MaxCharCount {
get { return 0; }
}
public override DecoderFallbackBuffer CreateFallbackBuffer ()
{
return new DecoderExceptionFallbackBuffer ();
}
public override bool Equals (object value)
{
return (value is DecoderExceptionFallback);
}
public override int GetHashCode ()
{
return 0;
}
}
}

View File

@@ -1,59 +0,0 @@
//
// DecoderExceptionFallbackBuffer.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.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.
//
namespace System.Text
{
public sealed class DecoderExceptionFallbackBuffer
: DecoderFallbackBuffer
{
public DecoderExceptionFallbackBuffer ()
{
}
public override int Remaining {
get { return 0; }
}
public override bool Fallback (byte [] bytesUnknown, int index)
{
throw new DecoderFallbackException (null, bytesUnknown, index);
}
public override char GetNextChar ()
{
return char.MinValue;
}
public override bool MovePrevious ()
{
return false;
}
}
}

View File

@@ -1,63 +0,0 @@
//
// DecoderFallback.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.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.
//
namespace System.Text
{
[Serializable]
public abstract class DecoderFallback
{
static readonly DecoderFallback exception_fallback =
new DecoderExceptionFallback ();
static readonly DecoderFallback replacement_fallback =
new DecoderReplacementFallback ();
static readonly DecoderFallback standard_safe_fallback =
new DecoderReplacementFallback ("\uFFFD");
protected DecoderFallback ()
{
}
public static DecoderFallback ExceptionFallback {
get { return exception_fallback; }
}
public abstract int MaxCharCount { get; }
public static DecoderFallback ReplacementFallback {
get { return replacement_fallback; }
}
internal static DecoderFallback StandardSafeFallback {
get { return standard_safe_fallback; }
}
public abstract DecoderFallbackBuffer CreateFallbackBuffer ();
}
}

View File

@@ -1,52 +0,0 @@
//
// DecoderFallbackBuffer.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.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.
//
namespace System.Text
{
public abstract class DecoderFallbackBuffer
{
protected DecoderFallbackBuffer ()
{
}
public abstract int Remaining { get; }
public abstract bool Fallback (byte [] bytesUnknown, int index);
public abstract char GetNextChar ();
public abstract bool MovePrevious ();
public virtual void Reset ()
{
}
}
}

View File

@@ -1,72 +0,0 @@
//
// DecoderFallbackException.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.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.
//
namespace System.Text
{
[Serializable]
public sealed class DecoderFallbackException : ArgumentException
{
public DecoderFallbackException ()
: this (null)
{
}
public DecoderFallbackException (string message)
: base (message)
{
}
public DecoderFallbackException (string message, Exception innerException)
: base (message, innerException)
{
}
public DecoderFallbackException (string message,
byte [] bytesUnknown, int index)
: base (message)
{
bytes_unknown = bytesUnknown;
this.index = index;
}
byte [] bytes_unknown;
int index = - 1;
[MonoTODO]
public byte [] BytesUnknown {
get { return bytes_unknown; }
}
[MonoTODO]
public int Index {
get { return index; }
}
}
}

View File

@@ -1,77 +0,0 @@
//
// DecoderReplacementFallback.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.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.
//
namespace System.Text
{
[Serializable]
public sealed class DecoderReplacementFallback : DecoderFallback
{
public DecoderReplacementFallback ()
: this ("?")
{
}
[MonoTODO]
public DecoderReplacementFallback (string replacement)
{
if (replacement == null)
throw new ArgumentNullException ();
// FIXME: check replacement validity (invalid surrogate)
this.replacement = replacement;
}
string replacement;
public string DefaultString {
get { return replacement; }
}
public override int MaxCharCount {
get { return replacement.Length; }
}
public override DecoderFallbackBuffer CreateFallbackBuffer ()
{
return new DecoderReplacementFallbackBuffer (this);
}
public override bool Equals (object value)
{
DecoderReplacementFallback f = value as DecoderReplacementFallback;
return f != null && replacement == f.replacement;
}
public override int GetHashCode ()
{
return replacement.GetHashCode ();
}
}
}

View File

@@ -1,95 +0,0 @@
//
// DecoderReplacementFallbackBuffer.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.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.
//
namespace System.Text
{
// This DecoderFallbackBuffer is simple. It ignores the input buffers.
// DecoderFallbackBuffer users could implement their own complex
// fallback buffers.
public sealed class DecoderReplacementFallbackBuffer
: DecoderFallbackBuffer
{
bool fallback_assigned;
int current;
string replacement;
public DecoderReplacementFallbackBuffer (
DecoderReplacementFallback fallback)
{
if (fallback == null)
throw new ArgumentNullException ("fallback");
replacement = fallback.DefaultString;
current = 0;
}
public override int Remaining {
get { return fallback_assigned ? replacement.Length - current : 0; }
}
public override bool Fallback (byte [] bytesUnknown, int index)
{
if (bytesUnknown == null)
throw new ArgumentNullException ("bytesUnknown");
if (fallback_assigned && Remaining != 0)
throw new ArgumentException ("Reentrant Fallback method invocation occurred. It might be because either this FallbackBuffer is incorrectly shared by multiple threads, invoked inside Encoding recursively, or Reset invocation is forgotten.");
if (index < 0 || bytesUnknown.Length < index)
throw new ArgumentOutOfRangeException ("index");
fallback_assigned = true;
current = 0;
return replacement.Length > 0;
}
public override char GetNextChar ()
{
if (!fallback_assigned)
return '\0';
if (current >= replacement.Length)
return char.MinValue;
return replacement [current++];
}
public override bool MovePrevious ()
{
if (current == 0)
return false;
current--;
return true;
}
public override void Reset ()
{
fallback_assigned = false;
current = 0;
}
}
}

View File

@@ -1,170 +0,0 @@
/*
* Encoder.cs - Implementation of the "System.Text.Encoder" class.
*
* Copyright (c) 2001 Southern Storm Software, Pty Ltd
*
* 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.
*/
namespace System.Text
{
using System;
using System.Runtime.InteropServices;
[Serializable]
[ComVisible (true)]
public abstract class Encoder
{
// Constructor.
protected Encoder() {}
EncoderFallback fallback = new EncoderReplacementFallback ();
EncoderFallbackBuffer fallback_buffer;
[ComVisible (false)]
public EncoderFallback Fallback {
get { return fallback; }
set {
if (value == null)
throw new ArgumentNullException ();
fallback = value;
fallback_buffer = null;
}
}
[ComVisible (false)]
public EncoderFallbackBuffer FallbackBuffer {
get {
if (fallback_buffer == null)
fallback_buffer = Fallback.CreateFallbackBuffer ();
return fallback_buffer;
}
}
// Get the number of bytes needed to encode a buffer.
public abstract int GetByteCount(char[] chars, int index,
int count, bool flush);
// Get the bytes that result from decoding a buffer.
public abstract int GetBytes(char[] chars, int charIndex, int charCount,
byte[] bytes, int byteIndex, bool flush);
[CLSCompliant (false)]
[ComVisible (false)]
public unsafe virtual int GetByteCount (char* chars, int count, bool flush)
{
if (chars == null)
throw new ArgumentNullException ("chars");
if (count < 0)
throw new ArgumentOutOfRangeException ("count");
char [] carr = new char [count];
Marshal.Copy ((IntPtr) chars, carr, 0, count);
return GetByteCount (carr, 0, count, flush);
}
[CLSCompliant (false)]
[ComVisible (false)]
public unsafe virtual int GetBytes (char* chars, int charCount,
byte* bytes, int byteCount, bool flush)
{
CheckArguments (chars, charCount, bytes, byteCount);
char [] carr = new char [charCount];
Marshal.Copy ((IntPtr) chars, carr, 0, charCount);
byte [] barr = new byte [byteCount];
Marshal.Copy ((IntPtr) bytes, barr, 0, byteCount);
return GetBytes (carr, 0, charCount, barr, 0, flush);
}
[ComVisible (false)]
public virtual void Reset ()
{
if (fallback_buffer != null)
fallback_buffer.Reset ();
}
[CLSCompliant (false)]
[ComVisible (false)]
public unsafe virtual void Convert (
char* chars, int charCount,
byte* bytes, int byteCount, bool flush,
out int charsUsed, out int bytesUsed, out bool completed)
{
CheckArguments (chars, charCount, bytes, byteCount);
charsUsed = charCount;
while (true) {
bytesUsed = GetByteCount (chars, charsUsed, flush);
if (bytesUsed <= byteCount)
break;
flush = false;
charsUsed >>= 1;
}
completed = charsUsed == charCount;
bytesUsed = GetBytes (chars, charsUsed, bytes, byteCount, flush);
}
[ComVisible (false)]
public virtual 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 = charCount;
while (true) {
bytesUsed = GetByteCount (chars, charIndex, charsUsed, flush);
if (bytesUsed <= byteCount)
break;
flush = false;
charsUsed >>= 1;
}
completed = charsUsed == charCount;
bytesUsed = GetBytes (chars, charIndex, charsUsed, bytes, byteIndex, flush);
}
unsafe void CheckArguments (char* chars, int charCount, byte* bytes, int byteCount)
{
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");
}
}; // class Encoder
}; // namespace System.Text

View File

@@ -1,58 +0,0 @@
//
// EncoderExceptionFallback.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.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.
//
namespace System.Text
{
[Serializable]
public sealed class EncoderExceptionFallback : EncoderFallback
{
public EncoderExceptionFallback ()
{
}
public override int MaxCharCount {
get { return 0; }
}
public override EncoderFallbackBuffer CreateFallbackBuffer ()
{
return new EncoderExceptionFallbackBuffer ();
}
public override bool Equals (object value)
{
return (value is EncoderExceptionFallback);
}
public override int GetHashCode ()
{
return 0;
}
}
}

View File

@@ -1,64 +0,0 @@
//
// EncoderExceptionFallbackBuffer.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.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.
//
namespace System.Text
{
public sealed class EncoderExceptionFallbackBuffer
: EncoderFallbackBuffer
{
public EncoderExceptionFallbackBuffer ()
{
}
public override int Remaining {
get { return 0; }
}
public override bool Fallback (char charUnknown, int index)
{
throw new EncoderFallbackException (charUnknown, index);
}
public override bool Fallback (char charUnknownHigh, char charUnknownLow, int index)
{
throw new EncoderFallbackException (charUnknownHigh, charUnknownLow, index);
}
public override char GetNextChar ()
{
return char.MinValue;
}
public override bool MovePrevious ()
{
return false;
}
}
}

View File

@@ -1,63 +0,0 @@
//
// EncoderFallback.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.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.
//
namespace System.Text
{
[Serializable]
public abstract class EncoderFallback
{
static readonly EncoderFallback exception_fallback =
new EncoderExceptionFallback ();
static readonly EncoderFallback replacement_fallback =
new EncoderReplacementFallback ();
static readonly EncoderFallback standard_safe_fallback =
new EncoderReplacementFallback ("\uFFFD");
protected EncoderFallback ()
{
}
public static EncoderFallback ExceptionFallback {
get { return exception_fallback; }
}
public abstract int MaxCharCount { get; }
public static EncoderFallback ReplacementFallback {
get { return replacement_fallback; }
}
internal static EncoderFallback StandardSafeFallback {
get { return standard_safe_fallback; }
}
public abstract EncoderFallbackBuffer CreateFallbackBuffer ();
}
}

View File

@@ -1,56 +0,0 @@
//
// EncoderFallbackBuffer.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.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.
//
namespace System.Text
{
public abstract class EncoderFallbackBuffer
{
protected EncoderFallbackBuffer ()
{
}
public abstract int Remaining { get; }
public abstract bool Fallback (char charUnknown, int index);
public abstract bool Fallback (char charUnknownHigh, char charUnknownLow, int index);
public abstract char GetNextChar ();
public abstract bool MovePrevious ();
public virtual void Reset ()
{
while (GetNextChar () != '\0')
;
}
}
}

View File

@@ -1,93 +0,0 @@
//
// EncoderFallbackException.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.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.
//
namespace System.Text
{
[Serializable]
public sealed class EncoderFallbackException : ArgumentException
{
public EncoderFallbackException ()
: this (null)
{
}
public EncoderFallbackException (string message)
: base (message)
{
}
public EncoderFallbackException (string message, Exception innerException)
: base (message, innerException)
{
}
internal EncoderFallbackException (char charUnknown, int index)
: base (null)
{
char_unknown = charUnknown;
this.index = index;
}
internal EncoderFallbackException (char charUnknownHigh,
char charUnknownLow, int index)
: base (null)
{
char_unknown_high = charUnknownHigh;
char_unknown_low = charUnknownLow;
this.index = index;
}
char char_unknown, char_unknown_high, char_unknown_low;
int index = - 1;
public char CharUnknown {
get { return char_unknown; }
}
public char CharUnknownHigh {
get { return char_unknown_high; }
}
public char CharUnknownLow {
get { return char_unknown_low; }
}
[MonoTODO]
public int Index {
get { return index; }
}
[MonoTODO]
public bool IsUnknownSurrogate ()
{
throw new NotImplementedException ();
}
}
}

View File

@@ -1,77 +0,0 @@
//
// EncoderReplacementFallback.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.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.
//
namespace System.Text
{
[Serializable]
public sealed class EncoderReplacementFallback : EncoderFallback
{
public EncoderReplacementFallback ()
: this ("?")
{
}
[MonoTODO]
public EncoderReplacementFallback (string replacement)
{
if (replacement == null)
throw new ArgumentNullException ();
// FIXME: check replacement validity (invalid surrogate)
this.replacement = replacement;
}
string replacement;
public string DefaultString {
get { return replacement; }
}
public override int MaxCharCount {
get { return replacement.Length; }
}
public override EncoderFallbackBuffer CreateFallbackBuffer ()
{
return new EncoderReplacementFallbackBuffer (this);
}
public override bool Equals (object value)
{
EncoderReplacementFallback f = value as EncoderReplacementFallback;
return f != null && replacement == f.replacement;
}
public override int GetHashCode ()
{
return replacement.GetHashCode ();
}
}
}

View File

@@ -1,103 +0,0 @@
//
// EncoderReplacementFallbackBuffer.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
// Copyright 2011 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.
//
namespace System.Text
{
// This EncoderFallbackBuffer is simple. It ignores the input buffers.
// EncoderFallbackBuffer users could implement their own complex
// fallback buffers.
public sealed class EncoderReplacementFallbackBuffer
: EncoderFallbackBuffer
{
string replacement;
int current;
bool fallback_assigned;
public EncoderReplacementFallbackBuffer (
EncoderReplacementFallback fallback)
{
if (fallback == null)
throw new ArgumentNullException ("fallback");
replacement = fallback.DefaultString;
current = 0;
}
public override int Remaining {
get { return replacement.Length - current; }
}
public override bool Fallback (char charUnknown, int index)
{
return Fallback (index);
}
public override bool Fallback (char charUnknownHigh, char charUnknownLow, int index)
{
return Fallback (index);
}
// hmm, what is this index for???
private bool Fallback (int index)
{
if (fallback_assigned && Remaining != 0)
throw new ArgumentException ("Reentrant Fallback method invocation occurred. It might be because either this FallbackBuffer is incorrectly shared by multiple threads, invoked inside Encoding recursively, or Reset invocation is forgotten.");
if (index < 0)
throw new ArgumentOutOfRangeException ("index");
fallback_assigned = true;
current = 0;
return replacement.Length > 0;
}
public override char GetNextChar ()
{
if (current >= replacement.Length)
return char.MinValue;
return replacement [current++];
}
public override bool MovePrevious ()
{
if (current == 0)
return false;
current--;
return true;
}
public override void Reset ()
{
fallback_assigned = false;
current = 0;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,102 +0,0 @@
//
// 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

Some files were not shown because too many files have changed in this diff Show More