using System.Runtime.InteropServices;
[Serializable]
-#if NET_2_0
[ComVisible (true)]
-#endif
-[MonoTODO ("Serialization format not compatible with .NET")]
+[MonoLimitation ("Serialization format not compatible with .NET")]
public class ASCIIEncoding : Encoding
{
// Magic number used by Windows for "ASCII".
is_mail_news_save = true;
}
-#if NET_2_0
[ComVisible (false)]
public override bool IsSingleByte {
get { return true; }
}
-#endif
// Get the number of bytes needed to encode a character buffer.
public override int GetByteCount (char[] chars, int index, int count)
// Get the bytes that result from encoding a character buffer.
public override int GetBytes (char[] chars, int charIndex, int charCount,
- byte[] bytes, int byteIndex)
+ byte[] bytes, int byteIndex)
{
-#if NET_2_0
-// well, yes, I know this #if is ugly, but I think it is the simplest switch.
+ // well, yes, I know this #if is ugly, but I think it is the simplest switch.
EncoderFallbackBuffer buffer = null;
char [] fallback_chars = null;
- return GetBytes (chars, charIndex, charCount, bytes,
- byteIndex, ref buffer, ref fallback_chars);
+
+ return GetBytes (chars, charIndex, charCount, bytes, byteIndex,
+ ref buffer, ref fallback_chars);
}
int GetBytes (char[] chars, int charIndex, int charCount,
ref EncoderFallbackBuffer buffer,
ref char [] fallback_chars)
{
-#endif
- if (chars == null) {
+ if (chars == null)
throw new ArgumentNullException ("chars");
- }
- if (bytes == null) {
+
+ if (bytes == null)
throw new ArgumentNullException ("bytes");
- }
- if (charIndex < 0 || charIndex > chars.Length) {
+
+ if (charIndex < 0 || charIndex > chars.Length)
throw new ArgumentOutOfRangeException ("charIndex", _("ArgRange_Array"));
- }
- if (charCount < 0 || charCount > (chars.Length - charIndex)) {
+
+ if (charCount < 0 || charCount > (chars.Length - charIndex))
throw new ArgumentOutOfRangeException ("charCount", _("ArgRange_Array"));
- }
- if (byteIndex < 0 || byteIndex > bytes.Length) {
+
+ if (byteIndex < 0 || byteIndex > bytes.Length)
throw new ArgumentOutOfRangeException ("byteIndex", _("ArgRange_Array"));
- }
- if ((bytes.Length - byteIndex) < charCount) {
+
+ if ((bytes.Length - byteIndex) < charCount)
throw new ArgumentException (_("Arg_InsufficientSpace"));
- }
+
int count = charCount;
char ch;
while (count-- > 0) {
if (ch < (char)0x80) {
bytes [byteIndex++] = (byte)ch;
} else {
-#if NET_2_0
if (buffer == null)
buffer = EncoderFallback.CreateFallbackBuffer ();
if (Char.IsSurrogate (ch) && count > 1 &&
byteIndex += GetBytes (fallback_chars, 0,
fallback_chars.Length, bytes, byteIndex,
ref buffer, ref fallback_chars);
-#else
- bytes [byteIndex++] = (byte)'?';
-#endif
}
}
return charCount;
// Convenience wrappers for "GetBytes".
public override int GetBytes (String chars, int charIndex, int charCount, byte[] bytes, int byteIndex)
{
-#if NET_2_0
// I know this #if is ugly, but I think it is the simplest switch.
EncoderFallbackBuffer buffer = null;
char [] fallback_chars = null;
ref EncoderFallbackBuffer buffer,
ref char [] fallback_chars)
{
-#endif
if (chars == null) {
throw new ArgumentNullException ("chars");
}
if (ch < (char)0x80) {
bytes [byteIndex++] = (byte)ch;
} else {
-#if NET_2_0
if (buffer == null)
buffer = EncoderFallback.CreateFallbackBuffer ();
if (Char.IsSurrogate (ch) && count > 1 &&
byteIndex += GetBytes (fallback_chars, 0,
fallback_chars.Length, bytes, byteIndex,
ref buffer, ref fallback_chars);
-#else
- bytes [byteIndex++] = (byte)'?';
-#endif
}
}
return charCount;
// Get the characters that result from decoding a byte buffer.
public override int GetChars (byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
{
-#if NET_2_0
// well, yes, I know this #if is ugly, but I think it is the simplest switch.
DecoderFallbackBuffer buffer = null;
return GetChars (bytes, byteIndex, byteCount, chars,
char[] chars, int charIndex,
ref DecoderFallbackBuffer buffer)
{
-#endif
if (bytes == null)
throw new ArgumentNullException ("bytes");
if (chars == null)
if (c < '\x80')
chars [charIndex++] = c;
else {
-#if NET_2_0
if (buffer == null)
buffer = DecoderFallback.CreateFallbackBuffer ();
buffer.Fallback (bytes, byteIndex);
while (buffer.Remaining > 0)
chars [charIndex++] = buffer.GetNextChar ();
-#else
- chars [charIndex++] = '?';
-#endif
}
}
return byteCount;
char* currChar = charPtr;
while (currByte < lastByte) {
-#if NET_2_0
byte b = currByte++ [0];
currChar++ [0] = b <= 0x7F ? (char) b : (char) '?';
-#else
- // GetString is incompatible with GetChars
- currChar++ [0] = (char) (currByte++ [0] & 0x7F);
-#endif
}
}
}
}
-#if NET_2_0
[CLSCompliantAttribute (false)]
[ComVisible (false)]
public unsafe override int GetBytes (char *chars, int charCount, byte *bytes, int byteCount)
{
return count;
}
-#else
- // This routine is gone in 2.x
- public override String GetString (byte[] bytes)
- {
- if (bytes == null) {
- throw new ArgumentNullException ("bytes");
- }
-
- return GetString (bytes, 0, bytes.Length);
- }
-#endif
-#if NET_2_0
- [MonoTODO ("we have simple override to match method signature.")]
[ComVisible (false)]
public override Decoder GetDecoder ()
{
return base.GetDecoder ();
}
- [MonoTODO ("we have simple override to match method signature.")]
[ComVisible (false)]
public override Encoder GetEncoder ()
{
return base.GetEncoder ();
}
-#endif
}; // class ASCIIEncoding
}; // namespace System.Text
+2009-11-02 Miguel de Icaza <miguel@novell.com>
+
+ * Jumbo patch to drop support for pre-NET_2_0 code:
+
+ Remove NET_2_0 defines assuming the value is true.
+
2009-10-22 Miguel de Icaza <miguel@novell.com>
* StringBuilder.cs (Text): Add new 4.0 method.
}
private int codePage;
-#if NET_2_0
private bool isReadOnly;
private EncoderFallback encoderFallback;
private DecoderFallback decoderFallback;
-#endif
private Encoding realObject;
private CodePageEncoding (SerializationInfo info, StreamingContext context)
this.codePage = (int) info.GetValue ("m_codePage", typeof (int));
-#if NET_2_0
try {
this.isReadOnly = (bool) info.GetValue ("m_isReadOnly", typeof (bool));
this.encoderFallback = (EncoderFallback) info.GetValue ("encoderFallback", typeof (EncoderFallback));
// .NET Framework 1.x has no fallbacks
this.isReadOnly = true;
}
-#endif
}
public void GetObjectData (SerializationInfo info, StreamingContext context)
if (this.realObject == null) {
Encoding encoding = Encoding.GetEncoding (this.codePage);
-#if NET_2_0
if (!this.isReadOnly) {
encoding = (Encoding) encoding.Clone ();
encoding.EncoderFallback = this.encoderFallback;
encoding.DecoderFallback = this.decoderFallback;
}
-#endif
this.realObject = encoding;
}
using System.Runtime.InteropServices;
[Serializable]
-#if NET_2_0
[ComVisible (true)]
-#endif
public abstract class Decoder
{
// Constructor.
protected Decoder () {}
-#if NET_2_0
DecoderFallback fallback = new DecoderReplacementFallback ();
DecoderFallbackBuffer fallback_buffer;
return fallback_buffer;
}
}
-#endif
// Get the number of characters needed to decode a buffer.
public abstract int GetCharCount (byte[] bytes, int index, int count);
public abstract int GetChars (byte[] bytes, int byteIndex, int byteCount,
char[] chars, int charIndex);
-#if NET_2_0
[ComVisible (false)]
public virtual int GetCharCount (byte [] bytes, int index, int count, bool flush)
{
if (byteCount < 0)
throw new ArgumentOutOfRangeException ("byteCount");
}
-#endif
-
}; // class Decoder
}; // namespace System.Text
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-#if NET_2_0 || NET_2_0_BOOTSTRAP
-
namespace System.Text
{
[Serializable]
}
}
}
-
-#endif
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-#if NET_2_0 || NET_2_0_BOOTSTRAP
-
namespace System.Text
{
public sealed class DecoderExceptionFallbackBuffer
}
}
}
-
-#endif
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-#if NET_2_0
-
namespace System.Text
{
[Serializable]
public abstract DecoderFallbackBuffer CreateFallbackBuffer ();
}
}
-
-#endif
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-#if NET_2_0 || NET_2_0_BOOTSTRAP
-
namespace System.Text
{
public abstract class DecoderFallbackBuffer
}
}
-#endif
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-#if NET_2_0 || NET_2_0_BOOTSTRAP
-
namespace System.Text
{
[Serializable]
}
}
}
-
-#endif
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-#if NET_2_0 || NET_2_0_BOOTSTRAP
-
namespace System.Text
{
[Serializable]
}
}
}
-
-#endif
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-#if NET_2_0 || NET_2_0_BOOTSTRAP
namespace System.Text
{
}
}
}
-
-#endif
using System.Runtime.InteropServices;
[Serializable]
-#if NET_2_0
[ComVisible (true)]
-#endif
public abstract class Encoder
{
// Constructor.
protected Encoder() {}
-#if NET_2_0
EncoderFallback fallback = new EncoderReplacementFallback ();
EncoderFallbackBuffer fallback_buffer;
return fallback_buffer;
}
}
-#endif
// Get the number of bytes needed to encode a buffer.
public abstract int GetByteCount(char[] chars, int index,
public abstract int GetBytes(char[] chars, int charIndex, int charCount,
byte[] bytes, int byteIndex, bool flush);
-#if NET_2_0
[CLSCompliant (false)]
[ComVisible (false)]
public unsafe virtual int GetByteCount (char* chars, int count, bool flush)
if (byteCount < 0)
throw new ArgumentOutOfRangeException ("byteCount");
}
-#endif
}; // class Encoder
}; // namespace System.Text
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-#if NET_2_0 || NET_2_0_BOOTSTRAP
-
namespace System.Text
{
[Serializable]
}
}
}
-
-#endif
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-#if NET_2_0 || NET_2_0_BOOTSTRAP
-
namespace System.Text
{
public sealed class EncoderExceptionFallbackBuffer
}
}
}
-
-#endif
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-#if NET_2_0 || NET_2_0_BOOTSTRAP
-
namespace System.Text
{
[Serializable]
public abstract EncoderFallbackBuffer CreateFallbackBuffer ();
}
}
-
-#endif
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-#if NET_2_0 || NET_2_0_BOOTSTRAP
-
namespace System.Text
{
public abstract class EncoderFallbackBuffer
}
}
-#endif
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-#if NET_2_0 || NET_2_0_BOOTSTRAP
-
namespace System.Text
{
[Serializable]
}
}
}
-
-#endif
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-#if NET_2_0 || NET_2_0_BOOTSTRAP
-
namespace System.Text
{
[Serializable]
}
}
}
-
-#endif
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-#if NET_2_0 || NET_2_0_BOOTSTRAP
-
namespace System.Text
{
// This EncoderFallbackBuffer is simple. It ignores the input buffers.
}
}
-#endif
using System.Runtime.InteropServices;
[Serializable]
-#if NET_2_0
[ComVisible (true)]
-#endif
-public abstract class Encoding
-#if NET_2_0
- : ICloneable
-#endif
+public abstract class Encoding : ICloneable
{
// Code page used by this encoding.
internal int codePage;
internal int windows_code_page;
-#if NET_2_0
bool is_readonly = true;
-#endif
// Constructor.
protected Encoding ()
{
this.codePage = windows_code_page = codePage;
-#if NET_2_0
switch (codePage) {
default:
// MS has "InternalBestFit{Decoder|Encoder}Fallback
encoder_fallback = EncoderFallback.StandardSafeFallback;
break;
}
-#endif
}
// until we change the callers:
return arg;
}
-#if NET_2_0
DecoderFallback decoder_fallback;
EncoderFallback encoder_fallback;
if (d != null)
decoder_fallback = d;
}
-#endif
// Convert between two encodings.
public static byte[] Convert (Encoding srcEncoding, Encoding dstEncoding,
{
Encoding enc = (value as Encoding);
if (enc != null) {
-#if NET_2_0
return codePage == enc.codePage &&
DecoderFallback.Equals (enc.DecoderFallback) &&
EncoderFallback.Equals (enc.EncoderFallback);
-#else
- return (codePage == enc.codePage);
-#endif
} else {
return false;
}
if (s.Length == 0)
return 0;
-#if NET_2_0
unsafe {
fixed (char* cptr = s) {
return GetByteCount (cptr, s.Length);
}
}
-#else
- char[] chars = s.ToCharArray ();
- return GetByteCount (chars, 0, chars.Length);
-#endif
}
public virtual int GetByteCount (char[] chars)
{
{
if (s == null)
throw new ArgumentNullException ("s");
-#if NET_2_0
if (charIndex < 0 || charIndex > s.Length)
throw new ArgumentOutOfRangeException ("charIndex", _("ArgRange_Array"));
if (charCount < 0 || charIndex > (s.Length - charCount))
}
}
}
-#else
- return GetBytes (s.ToCharArray(), charIndex, charCount, bytes, byteIndex);
-#endif
}
public virtual byte[] GetBytes (String s)
{
if (s == null)
throw new ArgumentNullException ("s");
-#if NET_2_0
if (s.Length == 0)
return new byte [0];
int byteCount = GetByteCount (s);
}
}
}
-#else
- char[] chars = s.ToCharArray ();
- int numBytes = GetByteCount (chars, 0, chars.Length);
- byte[] bytes = new byte [numBytes];
- GetBytes (chars, 0, chars.Length, bytes, 0);
- return bytes;
-#endif
}
+
public virtual byte[] GetBytes (char[] chars, int index, int count)
{
int numBytes = GetByteCount (chars, index, count);
case UTF8Encoding.UTF8_CODE_PAGE:
return UTF8;
-#if NET_2_0
case UTF32Encoding.UTF32_CODE_PAGE:
return UTF32;
case UTF32Encoding.BIG_UTF32_CODE_PAGE:
return BigEndianUTF32;
-#endif
case UnicodeEncoding.UNICODE_CODE_PAGE:
return Unicode;
// Try to obtain a code page handler from the I18N handler.
Encoding enc = (Encoding)(InvokeI18N ("GetEncoding", codepage));
if (enc != null) {
-#if NET_2_0
enc.is_readonly = true;
-#endif
return enc;
}
Type type = assembly.GetType (cpName);
if (type != null) {
enc = (Encoding)(Activator.CreateInstance (type));
-#if NET_2_0
enc.is_readonly = true;
-#endif
return enc;
}
type = Type.GetType (cpName);
if (type != null) {
enc = (Encoding)(Activator.CreateInstance (type));
-#if NET_2_0
enc.is_readonly = true;
-#endif
return enc;
}
#endif // !NET_2_1
#if !ECMA_COMPAT
-#if NET_2_0
[ComVisible (false)]
public virtual object Clone ()
{
}
#endif // NET_2_1
-#endif
-
// Table of builtin web encoding names and the corresponding code pages.
private static readonly object[] encodings =
{
UnicodeEncoding.BIG_UNICODE_CODE_PAGE,
"unicodefffe", "utf_16be",
-#if NET_2_0
+
UTF32Encoding.UTF32_CODE_PAGE,
"utf_32", "UTF_32LE", "ucs_4",
UTF32Encoding.BIG_UTF32_CODE_PAGE,
"UTF_32BE",
-#endif
#if !NET_2_1
Latin1Encoding.ISOLATIN_CODE_PAGE,
// Get a hash code for this instance.
public override int GetHashCode ()
{
-#if NET_2_0
return DecoderFallback.GetHashCode () << 24 + EncoderFallback.GetHashCode () << 16 + codePage;
-#else
- return codePage;
-#endif
}
// Get the maximum number of bytes needed to encode a
static volatile Encoding utf8EncodingWithoutMarkers;
static volatile Encoding unicodeEncoding;
static volatile Encoding isoLatin1Encoding;
-#if NET_2_0
static volatile Encoding utf8EncodingUnsafe;
static volatile Encoding utf32Encoding;
static volatile Encoding bigEndianUTF32Encoding;
-#endif
static readonly object lockobj = new object ();
// not supported by underlying OS
defaultEncoding = UTF8Unmarked;
}
-#if NET_2_0
defaultEncoding.is_readonly = true;
-#endif
}
}
}
//
internal static Encoding UTF8UnmarkedUnsafe {
get {
-#if NET_2_0
if (utf8EncodingUnsafe == null) {
lock (lockobj){
if (utf8EncodingUnsafe == null){
}
return utf8EncodingUnsafe;
-#else
- return UTF8Unmarked;
-#endif
}
}
}
}
-#if NET_2_0
// Get the standard little-endian UTF-32 encoding object.
public static Encoding UTF32
{
return bigEndianUTF32Encoding;
}
}
-#endif
// Forwarding decoder implementation.
private sealed class ForwardingDecoder : Decoder
public ForwardingDecoder (Encoding enc)
{
encoding = enc;
-#if NET_2_0
DecoderFallback fallback = encoding.DecoderFallback;
if (fallback != null)
Fallback = fallback;
-#endif
}
// Override inherited methods.
public ForwardingEncoder (Encoding enc)
{
encoding = enc;
-#if NET_2_0
EncoderFallback fallback = encoding.EncoderFallback;
if (fallback != null)
Fallback = fallback;
-#endif
}
// Override inherited methods.
} // class ForwardingEncoder
-#if NET_2_0
[CLSCompliantAttribute(false)]
[ComVisible (false)]
public unsafe virtual int GetByteCount (char *chars, int count)
return b.Length;
}
-#endif
-
}; // class Encoding
}; // namespace System.Text
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-#if NET_2_0
namespace System.Text
{
}
}
}
-
-#endif
// Nothing to do here.
}
-#if NET_2_0
public override bool IsSingleByte {
get { return true; }
}
{
return form == NormalizationForm.FormC;
}
-#endif
// Get the number of bytes needed to encode a character buffer.
public override int GetByteCount (char[] chars, int index, int count)
public override int GetBytes (char[] chars, int charIndex, int charCount,
byte[] bytes, int byteIndex)
{
-#if NET_2_0
-// well, yes, I know this #if is ugly, but I think it is the simplest switch.
EncoderFallbackBuffer buffer = null;
char [] fallback_chars = null;
return GetBytes (chars, charIndex, charCount, bytes,
ref EncoderFallbackBuffer buffer,
ref char [] fallback_chars)
{
-#endif
if (chars == null) {
throw new ArgumentNullException ("chars");
}
} else if (ch >= '\uFF01' && ch <= '\uFF5E') {
bytes [byteIndex++] = (byte)(ch - 0xFEE0);
} else {
-#if NET_2_0
if (buffer == null)
buffer = EncoderFallback.CreateFallbackBuffer ();
if (Char.IsSurrogate (ch) && count > 1 &&
byteIndex += GetBytes (fallback_chars, 0,
fallback_chars.Length, bytes, byteIndex,
ref buffer, ref fallback_chars);
-#else
- bytes [byteIndex++] = (byte)'?';
-#endif
}
}
return charCount;
public override int GetBytes (String s, int charIndex, int charCount,
byte[] bytes, int byteIndex)
{
-#if NET_2_0
-// I know this #if is ugly, but I think it is the simplest switch.
EncoderFallbackBuffer buffer = null;
char [] fallback_chars = null;
return GetBytes (s, charIndex, charCount, bytes, byteIndex,
ref EncoderFallbackBuffer buffer,
ref char [] fallback_chars)
{
-#endif
if (s == null) {
throw new ArgumentNullException ("s");
}
} else if (ch >= '\uFF01' && ch <= '\uFF5E') {
bytes [byteIndex++] = (byte)(ch - 0xFEE0);
} else {
-
-#if NET_2_0
if (buffer == null)
buffer = EncoderFallback.CreateFallbackBuffer ();
if (Char.IsSurrogate (ch) && count > 1 &&
byteIndex += GetBytes (fallback_chars, 0,
fallback_chars.Length, bytes, byteIndex,
ref buffer, ref fallback_chars);
-#else
- bytes [byteIndex++] = (byte)'?';
-#endif
}
}
return charCount;
// This class supports serialization compatibility.
//
-#if NET_2_0
[Serializable]
private sealed class MLangEncoder : ISerializable, IObjectReference
{
return this.realObject;
}
}
-#else
- private sealed class MLangEncoder
- {
- private MLangEncoder ()
- {
- }
- }
-#endif
//
// .NET Framework 1.x uses this class for internal decoders.
// This class supports serialization compatibility.
//
-#if NET_2_0
[Serializable]
private sealed class MLangDecoder : ISerializable, IObjectReference
{
return this.realObject;
}
}
-#else
- private sealed class MLangDecoder
- {
- private MLangDecoder ()
- {
- }
- }
-#endif
private int codePage;
-#if NET_2_0
private bool isReadOnly;
private EncoderFallback encoderFallback;
private DecoderFallback decoderFallback;
-#endif
private Encoding realObject;
private MLangCodePageEncoding (SerializationInfo info, StreamingContext context)
this.codePage = (int) info.GetValue ("m_codePage", typeof (int));
-#if NET_2_0
try {
this.isReadOnly = (bool) info.GetValue ("m_isReadOnly", typeof (bool));
this.encoderFallback = (EncoderFallback) info.GetValue ("encoderFallback", typeof (EncoderFallback));
// .NET Framework 1.x has no fallbacks
this.isReadOnly = true;
}
-#endif
}
public void GetObjectData (SerializationInfo info, StreamingContext context)
if (this.realObject == null) {
Encoding encoding = Encoding.GetEncoding (this.codePage);
-#if NET_2_0
if (!this.isReadOnly) {
encoding = (Encoding) encoding.Clone ();
encoding.EncoderFallback = this.encoderFallback;
encoding.DecoderFallback = this.decoderFallback;
}
-#endif
-
this.realObject = encoding;
}
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-#if NET_2_0
using System.Runtime.InteropServices;
FormKD = 6
}
}
-#endif
namespace System.Text {
[Serializable]
-#if NET_2_0
[ComVisible (true)]
-#endif
- [MonoTODO ("Serialization format not compatible with .NET")]
- public sealed class StringBuilder
-#if NET_2_0
- : ISerializable
-#endif
+ [MonoLimitation ("Serialization format not compatible with .NET")]
+ public sealed class StringBuilder : ISerializable
{
private int _length;
private string _str;
* OTHER DEALINGS IN THE SOFTWARE.
*/
-#if NET_2_0
-
namespace System.Text
{
} // class UTF32Decoder
-#if NET_2_0
[CLSCompliantAttribute(false)]
public unsafe override int GetByteCount (char *chars, int count)
{
throw new ArgumentNullException ("chars");
return count * 4;
}
-#else
- public override byte [] GetBytes (String s)
- {
- return base.GetBytes (s);
- }
-#endif
-#if NET_2_0
// a bunch of practically missing implementations (but should just work)
public override int GetByteCount (string s)
{
return base.GetEncoder ();
}
-#endif
-
}; // class UTF32Encoding
}; // namespace System.Text
-
-#endif
using System.Runtime.InteropServices;
[Serializable]
-#if NET_2_0
[ComVisible (true)]
-#endif
-[MonoTODO ("Serialization format not compatible with .NET")]
+[MonoLimitation ("Serialization format not compatible with .NET")]
#if ECMA_COMPAT
internal
#else
windows_code_page = UnicodeEncoding.UNICODE_CODE_PAGE;
}
-#if NET_2_0
[ComVisible (false)]
public override int GetHashCode ()
{
EncoderFallback.Equals (e.EncoderFallback) &&
DecoderFallback.Equals (e.DecoderFallback);
}
-#endif
// Internal version of "GetByteCount" that can handle
// a rolling state between calls.
} // class UTF7Encoder
-#if NET_2_0
// a bunch of practically missing implementations (but should just work)
[CLSCompliantAttribute (false)]
return base.GetString (bytes, index, count);
}
-#endif
-
}; // class UTF7Encoding
}; // namespace System.Text
using System.Runtime.InteropServices;
[Serializable]
-[MonoTODO ("Serialization format not compatible with .NET")]
-#if NET_2_0
-[MonoTODO ("EncoderFallback is not handled")]
+[MonoLimitation ("Serialization format not compatible with .NET")]
+[MonoLimitation ("EncoderFallback is not handled")]
[ComVisible (true)]
-#endif
public class UTF8Encoding : Encoding
{
// Magic number used by Windows for UTF-8.
// Internal state.
private bool emitIdentifier;
-#if !NET_2_0
- private bool throwOnInvalid;
-#endif
// Constructors.
public UTF8Encoding () : this (false, false) {}
: base (UTF8_CODE_PAGE)
{
emitIdentifier = encoderShouldEmitUTF8Identifier;
-#if NET_2_0
if (throwOnInvalidBytes)
SetFallbackInternal (null, DecoderFallback.ExceptionFallback);
else
SetFallbackInternal (null, DecoderFallback.StandardSafeFallback);
-#else
- throwOnInvalid = throwOnInvalidBytes;
-#endif
web_name = body_name = header_name = "utf-8";
encoding_name = "Unicode (UTF-8)";
return InternalGetByteCount (chars, index, count, ref dummy, true);
}
-#if !NET_2_0
- // Convenience wrappers for "GetByteCount".
- public override int GetByteCount (String chars)
- {
- // Validate the parameters.
- if (chars == null) {
- throw new ArgumentNullException ("chars");
- }
- unsafe {
- fixed (char* cptr = chars) {
- char dummy = '\0';
- return InternalGetByteCount (cptr, chars.Length, ref dummy, true);
- }
- }
- }
-#endif
-
-#if NET_2_0
[CLSCompliant (false)]
[ComVisible (false)]
public unsafe override int GetByteCount (char* chars, int count)
char dummy = '\0';
return InternalGetByteCount (chars, count, ref dummy, true);
}
-#endif
#endregion
if (charIndex == chars.Length) {
if (flush && leftOver != '\0') {
-#if NET_2_0
// FIXME: use EncoderFallback.
//
// By default it is empty, so I do nothing for now.
leftOver = '\0';
-#else
- // Flush the left-over surrogate pair start.
- if (byteIndex >= bytes.Length - 3)
- throw new ArgumentException (_("Arg_InsufficientSpace"), "bytes");
- bytes [byteIndex++] = 0xEF;
- bytes [byteIndex++] = 0xBB;
- bytes [byteIndex++] = 0xBF;
- leftOver = '\0';
- return 3;
-#endif
}
return 0;
}
}
}
-#if NET_2_0
[CLSCompliant (false)]
[ComVisible (false)]
public unsafe override int GetBytes (char* chars, int charCount, byte* bytes, int byteCount)
else
return InternalGetBytes (chars, charCount, bytes, byteCount, ref dummy, true);
}
-#endif
#endregion
// Internal version of "GetCharCount" which can handle a rolling
// state between multiple calls to this method.
-#if NET_2_0
private unsafe static int InternalGetCharCount (
byte[] bytes, int index, int count, uint leftOverBits,
uint leftOverCount, object provider,
ref DecoderFallbackBuffer fallbackBuffer, ref byte [] bufferArg, bool flush)
-#else
- private unsafe static int InternalGetCharCount (
- byte[] bytes, int index, int count, uint leftOverBits,
- uint leftOverCount, bool throwOnInvalid, bool flush)
-#endif
{
// Validate the parameters.
if (bytes == null) {
if (count == 0)
return 0;
fixed (byte *bptr = bytes)
-#if NET_2_0
return InternalGetCharCount (bptr + index, count,
leftOverBits, leftOverCount, provider, ref fallbackBuffer, ref bufferArg, flush);
-#else
- return InternalGetCharCount (bptr + index, count,
- leftOverBits, leftOverCount, throwOnInvalid, flush);
-#endif
}
-#if NET_2_0
private unsafe static int InternalGetCharCount (
byte* bytes, int count, uint leftOverBits,
uint leftOverCount, object provider,
ref DecoderFallbackBuffer fallbackBuffer, ref byte [] bufferArg, bool flush)
-#else
- private unsafe static int InternalGetCharCount (
- byte* bytes, int count, uint leftOverBits,
- uint leftOverCount, bool throwOnInvalid, bool flush)
-#endif
{
int index = 0;
leftSize = 6;
} else {
// Invalid UTF-8 start character.
-#if NET_2_0
length += Fallback (provider, ref fallbackBuffer, ref bufferArg, bytes, index - 1, 1);
-#else
- if (throwOnInvalid)
- throw new ArgumentException (_("Arg_InvalidUTF8"), "bytes");
-#endif
}
} else {
// Process an extra byte in a multi-byte sequence.
break;
}
if (overlong) {
-#if NET_2_0
length += Fallback (provider, ref fallbackBuffer, ref bufferArg, bytes, index - leftSoFar, leftSoFar);
-#else
- if (throwOnInvalid)
- throw new ArgumentException (_("Overlong"), leftBits.ToString ());
-#endif
}
else if ((leftBits & 0xF800) == 0xD800) {
// UTF-8 doesn't use surrogate characters
-#if NET_2_0
length += Fallback (provider, ref fallbackBuffer, ref bufferArg, bytes, index - leftSoFar, leftSoFar);
-#else
- if (throwOnInvalid)
- throw new ArgumentException (_("Arg_InvalidUTF8"), "bytes");
-#endif
}
else
++length;
} else if (leftBits < (uint)0x110000) {
length += 2;
} else {
-#if NET_2_0
length += Fallback (provider, ref fallbackBuffer, ref bufferArg, bytes, index - leftSoFar, leftSoFar);
-#else
- if (throwOnInvalid)
- throw new ArgumentException (_("Arg_InvalidUTF8"), "bytes");
-#endif
}
leftSize = 0;
}
} else {
// Invalid UTF-8 sequence: clear and restart.
-#if NET_2_0
length += Fallback (provider, ref fallbackBuffer, ref bufferArg, bytes, index - leftSoFar, leftSoFar);
-#else
- if (throwOnInvalid)
- throw new ArgumentException (_("Arg_InvalidUTF8"), "bytes");
-#endif
leftSize = 0;
--index;
++count;
if (flush && leftSize != 0) {
// We had left-over bytes that didn't make up
// a complete UTF-8 character sequence.
-#if NET_2_0
length += Fallback (provider, ref fallbackBuffer, ref bufferArg, bytes, index - leftSoFar, leftSoFar);
-#else
- if (throwOnInvalid)
- throw new ArgumentException (_("Arg_InvalidUTF8"), "bytes");
-#endif
}
// Return the final length to the caller.
return length;
}
-#if NET_2_0
// for GetCharCount()
static unsafe int Fallback (object provider, ref DecoderFallbackBuffer buffer, ref byte [] bufferArg, byte* bytes, long index, uint size)
{
buffer.Reset ();
}
}
-#endif
// Get the number of characters needed to decode a byte buffer.
public override int GetCharCount (byte[] bytes, int index, int count)
{
-#if NET_2_0
DecoderFallbackBuffer buf = null;
byte [] bufferArg = null;
return InternalGetCharCount (bytes, index, count, 0, 0, DecoderFallback, ref buf, ref bufferArg, true);
-#else
- return InternalGetCharCount (bytes, index, count, 0, 0, throwOnInvalid, true);
-#endif
}
-#if NET_2_0
[CLSCompliant (false)]
[ComVisible (false)]
public unsafe override int GetCharCount (byte* bytes, int count)
byte [] bufferArg = null;
return InternalGetCharCount (bytes, count, 0, 0, DecoderFallback, ref buf, ref bufferArg, true);
}
-#endif
// Get the characters that result from decoding a byte buffer.
-#if NET_2_0
private unsafe static int InternalGetChars (
byte[] bytes, int byteIndex, int byteCount, char[] chars,
int charIndex, ref uint leftOverBits, ref uint leftOverCount,
object provider,
ref DecoderFallbackBuffer fallbackBuffer, ref byte [] bufferArg, bool flush)
-#else
- private unsafe static int InternalGetChars (
- byte[] bytes, int byteIndex, int byteCount, char[] chars,
- int charIndex, ref uint leftOverBits, ref uint leftOverCount,
- bool throwOnInvalid, bool flush)
-#endif
{
// Validate the parameters.
if (bytes == null) {
return 0;
fixed (char* cptr = chars) {
-#if NET_2_0
if (byteCount == 0 || byteIndex == bytes.Length)
return InternalGetChars (null, 0, cptr + charIndex, chars.Length - charIndex, ref leftOverBits, ref leftOverCount, provider, ref fallbackBuffer, ref bufferArg, flush);
// otherwise...
fixed (byte* bptr = bytes)
return InternalGetChars (bptr + byteIndex, byteCount, cptr + charIndex, chars.Length - charIndex, ref leftOverBits, ref leftOverCount, provider, ref fallbackBuffer, ref bufferArg, flush);
-#else
- if (byteCount == 0 || byteIndex == bytes.Length)
- return InternalGetChars (null, 0, cptr + charIndex, chars.Length - charIndex, ref leftOverBits, ref leftOverCount, throwOnInvalid, flush);
- // otherwise...
- fixed (byte* bptr = bytes)
- return InternalGetChars (bptr + byteIndex, byteCount, cptr + charIndex, chars.Length - charIndex, ref leftOverBits, ref leftOverCount, throwOnInvalid, flush);
-#endif
}
}
-#if NET_2_0
private unsafe static int InternalGetChars (
byte* bytes, int byteCount, char* chars, int charCount,
ref uint leftOverBits, ref uint leftOverCount,
object provider,
ref DecoderFallbackBuffer fallbackBuffer, ref byte [] bufferArg, bool flush)
-#else
- private unsafe static int InternalGetChars (
- byte* bytes, int byteCount, char* chars, int charCount,
- ref uint leftOverBits, ref uint leftOverCount,
- bool throwOnInvalid, bool flush)
-#endif
{
int charIndex = 0, byteIndex = 0;
int length = charCount;
leftSize = 6;
} else {
// Invalid UTF-8 start character.
-#if NET_2_0
Fallback (provider, ref fallbackBuffer, ref bufferArg, bytes, byteIndex, 1, chars, ref posn);
-#else
- if (throwOnInvalid)
- throw new ArgumentException (_("Arg_InvalidUTF8"), "bytes");
-#endif
}
} else {
// Process an extra byte in a multi-byte sequence.
break;
}
if (overlong) {
-#if NET_2_0
Fallback (provider, ref fallbackBuffer, ref bufferArg, bytes, byteIndex - leftSoFar, leftSoFar, chars, ref posn);
-#else
- if (throwOnInvalid)
- throw new ArgumentException (_("Overlong"), leftBits.ToString ());
-#endif
}
else if ((leftBits & 0xF800) == 0xD800) {
// UTF-8 doesn't use surrogate characters
-#if NET_2_0
Fallback (provider, ref fallbackBuffer, ref bufferArg, bytes, byteIndex - leftSoFar, leftSoFar, chars, ref posn);
-#else
- if (throwOnInvalid)
- throw new ArgumentException (_("Arg_InvalidUTF8"), "bytes");
-#endif
}
else {
if (posn >= length) {
chars[posn++] =
(char)((leftBits & (uint)0x3FF) + (uint)0xDC00);
} else {
-#if NET_2_0
Fallback (provider, ref fallbackBuffer, ref bufferArg, bytes, byteIndex - leftSoFar, leftSoFar, chars, ref posn);
-#else
- if (throwOnInvalid)
- throw new ArgumentException (_("Arg_InvalidUTF8"), "bytes");
-#endif
}
leftSize = 0;
}
} else {
// Invalid UTF-8 sequence: clear and restart.
-#if NET_2_0
Fallback (provider, ref fallbackBuffer, ref bufferArg, bytes, byteIndex - leftSoFar, leftSoFar, chars, ref posn);
-#else
- if (throwOnInvalid)
- throw new ArgumentException (_("Arg_InvalidUTF8"), "bytes");
-#endif
leftSize = 0;
--byteIndex;
}
if (flush && leftSize != 0) {
// We had left-over bytes that didn't make up
// a complete UTF-8 character sequence.
-#if NET_2_0
Fallback (provider, ref fallbackBuffer, ref bufferArg, bytes, byteIndex - leftSoFar, leftSoFar, chars, ref posn);
-#else
- if (throwOnInvalid)
- throw new ArgumentException (_("Arg_InvalidUTF8"), "bytes");
-#endif
}
leftOverBits = leftBits;
leftOverCount = (leftSoFar | (leftSize << 4));
{
uint leftOverBits = 0;
uint leftOverCount = 0;
-#if NET_2_0
DecoderFallbackBuffer buf = null;
byte [] bufferArg = null;
return InternalGetChars (bytes, byteIndex, byteCount, chars,
charIndex, ref leftOverBits, ref leftOverCount, DecoderFallback, ref buf, ref bufferArg, true);
-#else
- return InternalGetChars (bytes, byteIndex, byteCount, chars,
- charIndex, ref leftOverBits, ref leftOverCount, throwOnInvalid, true);
-#endif
}
-#if NET_2_0
[CLSCompliant (false)]
[ComVisible (false)]
public unsafe override int GetChars (byte* bytes, int byteCount, char* chars, int charCount)
return InternalGetChars (bytes, byteCount, chars,
charCount, ref leftOverBits, ref leftOverCount, DecoderFallback, ref buf, ref bufferArg, true);
}
-#endif
// Get the maximum number of bytes needed to encode a
// specified number of characters.
// Get a UTF8-specific decoder that is attached to this instance.
public override Decoder GetDecoder ()
{
-#if NET_2_0
return new UTF8Decoder (DecoderFallback);
-#else
- return new UTF8Decoder (throwOnInvalid);
-#endif
}
// Get a UTF8-specific encoder that is attached to this instance.
{
UTF8Encoding enc = (value as UTF8Encoding);
if (enc != null) {
-#if NET_2_0
return (codePage == enc.codePage &&
emitIdentifier == enc.emitIdentifier &&
DecoderFallback.Equals (enc.DecoderFallback) &&
EncoderFallback.Equals (enc.EncoderFallback));
-#else
- return (codePage == enc.codePage &&
- emitIdentifier == enc.emitIdentifier &&
- throwOnInvalid == enc.throwOnInvalid);
-#endif
} else {
return false;
}
return base.GetHashCode ();
}
-#if NET_2_0
public override int GetByteCount (string chars)
{
// hmm, does this override make any sense?
// hmm, does this override make any sense?
return base.GetString (bytes, index, count);
}
-#endif
-
-#if !NET_2_0
- public override byte [] GetBytes (String s)
- {
- if (s == null)
- throw new ArgumentNullException ("s");
-
- int length = GetByteCount (s);
- byte [] bytes = new byte [length];
- GetBytes (s, 0, s.Length, bytes, 0);
- return bytes;
- }
-#endif
// UTF-8 decoder implementation.
[Serializable]
private class UTF8Decoder : Decoder
{
-#if !NET_2_0
- private bool throwOnInvalid;
-#endif
private uint leftOverBits;
private uint leftOverCount;
// Constructor.
-#if NET_2_0
public UTF8Decoder (DecoderFallback fallback)
-#else
- public UTF8Decoder (bool throwOnInvalid)
-#endif
{
-#if NET_2_0
Fallback = fallback;
-#else
- this.throwOnInvalid = throwOnInvalid;
-#endif
leftOverBits = 0;
leftOverCount = 0;
}
// Override inherited methods.
public override int GetCharCount (byte[] bytes, int index, int count)
{
-#if NET_2_0
DecoderFallbackBuffer buf = null;
byte [] bufferArg = null;
return InternalGetCharCount (bytes, index, count,
leftOverBits, leftOverCount, this, ref buf, ref bufferArg, false);
-#else
- return InternalGetCharCount (bytes, index, count,
- leftOverBits, leftOverCount, throwOnInvalid, false);
-#endif
}
public override int GetChars (byte[] bytes, int byteIndex,
int byteCount, char[] chars, int charIndex)
{
-#if NET_2_0
DecoderFallbackBuffer buf = null;
byte [] bufferArg = null;
return InternalGetChars (bytes, byteIndex, byteCount,
chars, charIndex, ref leftOverBits, ref leftOverCount, this, ref buf, ref bufferArg, false);
-#else
- return InternalGetChars (bytes, byteIndex, byteCount,
- chars, charIndex, ref leftOverBits, ref leftOverCount, throwOnInvalid, false);
-#endif
}
} // class UTF8Decoder
return result;
}
-#if NET_2_0
public unsafe override int GetByteCount (char* chars, int count, bool flush)
{
return InternalGetByteCount (chars, count, ref leftOverForCount, flush);
// emitIdentifier = false;
return result;
}
-#endif
-
} // class UTF8Encoder
}; // class UTF8Encoding
using System.Runtime.InteropServices;
[Serializable]
-#if NET_2_0
[ComVisible (true)]
-#endif
-[MonoTODO ("Serialization format not compatible with .NET")]
+[MonoLimitation ("Serialization format not compatible with .NET")]
public class UnicodeEncoding : Encoding
{
// Magic numbers used by Windows for Unicode.
{
}
-#if NET_2_0
- public
-#endif
- UnicodeEncoding (bool bigEndian, bool byteOrderMark, bool throwOnInvalidBytes)
+ public UnicodeEncoding (bool bigEndian, bool byteOrderMark, bool throwOnInvalidBytes)
: base ((bigEndian ? BIG_UNICODE_CODE_PAGE : UNICODE_CODE_PAGE))
{
-#if NET_2_0
if (throwOnInvalidBytes)
SetFallbackInternal (null, new DecoderExceptionFallback ());
else
SetFallbackInternal (null, new DecoderReplacementFallback ("\uFFFD"));
-#endif
this.bigEndian = bigEndian;
this.byteOrderMark = byteOrderMark;
return s.Length * 2;
}
-#if NET_2_0
[CLSCompliantAttribute (false)]
[ComVisible (false)]
public unsafe override int GetByteCount (char* chars, int count)
return count * 2;
}
-#endif
// Get the bytes that result from encoding a character buffer.
public unsafe override int GetBytes (char [] chars, int charIndex, int charCount,
return GetBytesInternal (charPtr + charIndex, charCount, bytePtr + byteIndex, byteCount);
}
-#if !NET_2_0
- public override byte [] GetBytes (String s)
- {
- if (s == null)
- throw new ArgumentNullException ("s");
-
- int byteCount = GetByteCount (s);
- byte [] bytes = new byte [byteCount];
-
- GetBytes (s, 0, s.Length, bytes, 0);
-
- return bytes;
- }
-#endif
-
public unsafe override int GetBytes (String s, int charIndex, int charCount,
byte [] bytes, int byteIndex)
{
return GetBytesInternal (charPtr + charIndex, charCount, bytePtr + byteIndex, byteCount);
}
-#if NET_2_0
[CLSCompliantAttribute (false)]
[ComVisible (false)]
public unsafe override int GetBytes (char* chars, int charCount,
return GetBytesInternal (chars, charCount, bytes, byteCount);
}
-#endif
private unsafe int GetBytesInternal (char* chars, int charCount,
byte* bytes, int byteCount)
return count / 2;
}
-#if NET_2_0
[CLSCompliantAttribute (false)]
[ComVisible (false)]
public unsafe override int GetCharCount (byte* bytes, int count)
return count / 2;
}
-#endif
// Get the characters that result from decoding a byte buffer.
public unsafe override int GetChars (byte [] bytes, int byteIndex, int byteCount,
return GetCharsInternal (bytePtr + byteIndex, byteCount, charPtr + charIndex, charCount);
}
-#if NET_2_0
[CLSCompliantAttribute (false)]
[ComVisible (false)]
public unsafe override int GetChars (byte* bytes, int byteCount,
return GetCharsInternal (bytes, byteCount, chars, charCount);
}
-#endif
// Decode a buffer of bytes into a string.
[ComVisible (false)]