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

@@ -98,26 +98,16 @@ public class CP51932 : MonoEncoding
public override int GetCharCount (byte [] bytes, int index, int count)
{
#if NET_2_0
return new CP51932Decoder ().GetCharCount (
bytes, index, count, true);
#else
return new CP51932Decoder ().GetCharCount (
bytes, index, count);
#endif
}
public override int GetChars (
byte [] bytes, int byteIndex, int byteCount,
char [] chars, int charIndex)
{
#if NET_2_0
return new CP51932Decoder ().GetChars (bytes,
byteIndex, byteCount, chars, charIndex, true);
#else
return new CP51932Decoder ().GetChars (bytes,
byteIndex, byteCount, chars, charIndex);
#endif
}
// Get the maximum number of bytes needed to encode a
@@ -312,13 +302,9 @@ public class CP51932Encoder : MonoEncoder
}
if (value == 0) {
#if NET_2_0
HandleFallback (
chars, ref i, ref charCount,
bytes, ref posn, ref byteCount, null);
#else
bytes [posn++] = (byte) '?';
#endif
} else if (value < 0x0100) {
bytes [posn++] = (byte) value;
} else if ((posn + 1) >= byteLength) {
@@ -468,12 +454,8 @@ public class CP51932Encoder : MonoEncoder
if (value == 0)
{
#if NET_2_0
HandleFallback (chars, ref i, ref charCount,
bytes, ref posn, ref byteCount, null);
#else
bytes [posn++] = (byte) '?';
#endif
}
else if (value < 0x0100)
{
@@ -521,11 +503,7 @@ internal class CP51932Decoder : DbcsEncoding.DbcsDecoder
return GetCharCount (bytes, index, count, false);
}
#if NET_2_0
public override
#else
internal
#endif
int GetCharCount (byte [] bytes, int index, int count, bool refresh)
{
CheckRange (bytes, index, count);
@@ -629,11 +607,7 @@ internal class CP51932Decoder : DbcsEncoding.DbcsDecoder
return GetChars (bytes, byteIndex, byteCount, chars, charIndex, false);
}
#if NET_2_0
public override
#else
internal
#endif
int GetChars (byte[] bytes, int byteIndex,
int byteCount, char[] chars,
int charIndex, bool refresh)

View File

@@ -130,9 +130,7 @@ namespace I18N.CJK
{
int charIndex = 0;
int byteIndex = 0;
#if NET_2_0
EncoderFallbackBuffer buffer = null;
#endif
// Convert the characters into their byte form.
int posn = byteIndex;
@@ -243,14 +241,9 @@ namespace I18N.CJK
}
else
{
#if NET_2_0
HandleFallback (ref buffer,
chars, ref charIndex, ref charCount,
bytes, ref posn, ref byteCount, null);
#else
// Invalid character.
bytes[posn++] = (byte)'?';
#endif
}
continue;
}
@@ -295,13 +288,9 @@ namespace I18N.CJK
}
if(value == 0)
{
#if NET_2_0
HandleFallback (ref buffer,
chars, ref charIndex, ref charCount,
bytes, ref posn, ref byteCount, null);
#else
bytes[posn++] = (byte)'?';
#endif
}
else if(value < 0x0100)
{
@@ -424,9 +413,7 @@ namespace I18N.CJK
public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex)
{
int byteCount = bytes.Length;
#if NET_2_0
EncoderFallbackBuffer buffer = null;
#endif
// Convert the characters into their byte form.
int posn = byteIndex;
@@ -533,13 +520,8 @@ namespace I18N.CJK
}
else
{
#if NET_2_0
HandleFallback (ref buffer, chars, ref i, ref charCount, bytes,
ref byteIndex, ref byteCount, null);
#else
// Invalid character.
bytes[posn++] = (byte)'?';
#endif
}
continue;
}
@@ -584,12 +566,8 @@ namespace I18N.CJK
}
if (value == 0)
{
#if NET_2_0
HandleFallback (ref buffer, chars, ref charIndex, ref charCount,
bytes, ref posn, ref byteCount, null);
#else
bytes[posn++] = (byte)'?';
#endif
}
else if (value < 0x0100)
{
@@ -734,6 +712,14 @@ namespace I18N.CJK
public override int WindowsCodePage {
get { return SHIFTJIS_CODE_PAGE; }
}
// FIXME: This doesn't make sense, but without declaring this override
// System.XML regresses at Encoder.Convert() in
// MonoTests.System.Xml.XmlWriterSettingsTests.EncodingTest.
public override Encoder GetEncoder ()
{
return new MonoEncodingDefaultEncoder (this);
}
}; // class CP932
@@ -762,9 +748,7 @@ namespace I18N.CJK
}
public
#if NET_2_0
override
#endif
int GetCharCount (byte [] bytes, int index, int count, bool refresh)
{
CheckRange (bytes, index, count);
@@ -814,9 +798,7 @@ namespace I18N.CJK
}
public
#if NET_2_0
override
#endif
int GetChars (
byte [] bytes, int byteIndex, int byteCount,
char [] chars, int charIndex, bool refresh)

View File

@@ -42,9 +42,7 @@ namespace I18N.CJK
int charIndex = 0;
int byteIndex = 0;
int end = charCount;
#if NET_2_0
EncoderFallbackBuffer buffer = null;
#endif
int origIndex = byteIndex;
for (int i = charIndex; i < end; i++, charCount--) {
@@ -57,14 +55,9 @@ namespace I18N.CJK
byte b1 = gb2312.u2n[((int)c) * 2 + 1];
byte b2 = gb2312.u2n[((int)c) * 2];
if (b1 == 0 && b2 == 0) {
#if NET_2_0
HandleFallback (ref buffer, chars,
ref i, ref charCount,
bytes, ref byteIndex, ref byteCount, null);
#else
int offset = byteIndex++;
if (bytes != null) bytes[offset] = (byte)'?';
#endif
} else {
if (bytes != null)
{
@@ -87,9 +80,7 @@ namespace I18N.CJK
int byteCount = bytes != null ? bytes.Length : 0;
DbcsConvert gb2312 = GetConvert();
#if NET_2_0
EncoderFallbackBuffer buffer = null;
#endif
for (int i = charIndex; i < end; i++, charCount--)
{
char c = chars[i];
@@ -103,13 +94,8 @@ namespace I18N.CJK
byte b2 = gb2312.u2n[((int)c) * 2];
if (b1 == 0 && b2 == 0)
{
#if NET_2_0
HandleFallback (ref buffer, chars, ref i, ref charCount,
bytes, ref byteIndex, ref byteCount, null);
#else
int offset = byteIndex++;
if (bytes != null) bytes[] = (byte)'?';
#endif
}
else
{
@@ -225,9 +211,7 @@ namespace I18N.CJK
return GetCharCount (bytes, index, count, false);
}
#if NET_2_0
public override
#endif
int GetCharCount (byte [] bytes, int index, int count, bool refresh)
{
CheckRange (bytes, index, count);
@@ -268,9 +252,7 @@ namespace I18N.CJK
return GetChars (bytes, byteIndex, byteCount, chars, charIndex, false);
}
#if NET_2_0
public override
#endif
int GetChars (byte [] bytes, int byteIndex, int byteCount,
char [] chars, int charIndex, bool refresh)
{

View File

@@ -136,12 +136,8 @@ namespace I18N.CJK
byte b1 = convert.u2n[((int)c) * 2];
byte b2 = convert.u2n[((int)c) * 2 + 1];
if (b1 == 0 && b2 == 0) {
#if NET_2_0
// FIXME: handle fallback for GetByteCountImpl().
length++;
#else
length++;
#endif
}
else
length += 2;
@@ -157,9 +153,7 @@ namespace I18N.CJK
int byteIndex = 0;
int end = charCount;
DbcsConvert convert = GetConvert ();
#if NET_2_0
EncoderFallbackBuffer buffer = null;
#endif
// 00 00 - FF FF
int origIndex = byteIndex;
@@ -172,12 +166,8 @@ namespace I18N.CJK
byte b1 = convert.u2n[((int)c) * 2];
byte b2 = convert.u2n[((int)c) * 2 + 1];
if (b1 == 0 && b2 == 0) {
#if NET_2_0
HandleFallback (ref buffer, chars, ref i, ref charCount,
bytes, ref byteIndex, ref byteCount, null);
#else
bytes[byteIndex++] = (byte)'?';
#endif
} else {
bytes[byteIndex++] = b1;
bytes[byteIndex++] = b2;
@@ -205,12 +195,8 @@ namespace I18N.CJK
byte b2 = convert.u2n[((int)c) * 2 + 1];
if (b1 == 0 && b2 == 0)
{
#if NET_2_0
// FIXME: handle fallback for GetByteCountImpl().
length++;
#else
length++;
#endif
}
else
length += 2;
@@ -225,9 +211,7 @@ namespace I18N.CJK
int end = charIndex + charCount;
DbcsConvert convert = GetConvert();
#if NET_2_0
EncoderFallbackBuffer buffer = null;
#endif
// 00 00 - FF FF
int origIndex = byteIndex;
@@ -243,12 +227,8 @@ namespace I18N.CJK
byte b2 = convert.u2n[((int)c) * 2 + 1];
if (b1 == 0 && b2 == 0)
{
#if NET_2_0
HandleFallback (ref buffer, chars, ref i, ref charCount,
bytes, ref byteIndex, ref byteCount, null);
#else
bytes[byteIndex++] = (byte)'?';
#endif
}
else
{
@@ -295,9 +275,7 @@ namespace I18N.CJK
return GetCharCount (bytes, index, count, false);
}
#if NET_2_0
public override
#endif
int GetCharCount (byte [] bytes, int index, int count, bool refresh)
{
CheckRange (bytes, index, count);
@@ -387,9 +365,7 @@ namespace I18N.CJK
return GetChars (bytes, byteIndex, byteCount, chars, charIndex, false);
}
#if NET_2_0
public override
#endif
int GetChars(byte[] bytes, int byteIndex,
int byteCount, char[] chars, int charIndex, bool refresh)
{

View File

@@ -44,12 +44,8 @@ namespace I18N.CJK
byte b1 = convert.u2n[((int)c) * 2 + 1];
byte b2 = convert.u2n[((int)c) * 2];
if (b1 == 0 && b2 == 0) {
#if NET_2_0
// FIXME: handle fallback for GetByteCountImpl().
length++;
#else
length++;
#endif
}
else
length += 2;
@@ -65,9 +61,7 @@ namespace I18N.CJK
int charIndex = 0;
int byteIndex = 0;
int end = charCount;
#if NET_2_0
EncoderFallbackBuffer buffer = null;
#endif
int origIndex = byteIndex;
for (int i = charIndex; i < end; i++, charCount--)
@@ -80,13 +74,9 @@ namespace I18N.CJK
byte b1 = convert.u2n[((int)c) * 2 + 1];
byte b2 = convert.u2n[((int)c) * 2];
if (b1 == 0 && b2 == 0) {
#if NET_2_0
HandleFallback (ref buffer, chars,
ref i, ref charCount,
bytes, ref byteIndex, ref byteCount, null);
#else
bytes[byteIndex++] = (byte)'?';
#endif
} else {
bytes[byteIndex++] = b1;
bytes[byteIndex++] = b2;
@@ -113,12 +103,8 @@ namespace I18N.CJK
byte b2 = convert.u2n[((int)c) * 2];
if (b1 == 0 && b2 == 0)
{
#if NET_2_0
// FIXME: handle fallback for GetByteCountImpl().
length++;
#else
length++;
#endif
}
else
length += 2;
@@ -133,9 +119,7 @@ namespace I18N.CJK
int end = charIndex + charCount;
DbcsConvert convert = GetConvert();
#if NET_2_0
EncoderFallbackBuffer buffer = null;
#endif
int origIndex = byteIndex;
for (int i = charIndex; i < end; i++, charCount--)
@@ -150,12 +134,8 @@ namespace I18N.CJK
byte b2 = convert.u2n[((int)c) * 2];
if (b1 == 0 && b2 == 0)
{
#if NET_2_0
HandleFallback (ref buffer, chars, ref i, ref charCount,
bytes, ref byteIndex, ref byteCount, null);
#else
bytes[byteIndex++] = (byte)'?';
#endif
}
else
{
@@ -259,9 +239,7 @@ namespace I18N.CJK
return GetCharCount (bytes, index, count, false);
}
#if NET_2_0
public override
#endif
int GetCharCount (byte[] bytes, int index, int count, bool refresh)
{
CheckRange (bytes, index, count);
@@ -311,9 +289,7 @@ namespace I18N.CJK
return GetChars (bytes, byteIndex, byteCount, chars, charIndex, false);
}
#if NET_2_0
public override
#endif
int GetChars(byte[] bytes, int byteIndex, int byteCount,
char[] chars, int charIndex, bool refresh)
{

View File

@@ -384,13 +384,9 @@ namespace I18N.CJK
char ch2 = chars [charIndex++];
if (!Char.IsSurrogate (ch2)) {
// invalid surrogate
#if NET_2_0
HandleFallback (
chars, ref charIndex, ref charCount,
bytes, ref byteIndex, ref byteCount, null);
#else
bytes [byteIndex++] = (byte) '?';
#endif
continue;
}
int cp = (ch - 0xD800) * 0x400 + ch2 - 0xDC00;
@@ -533,12 +529,8 @@ namespace I18N.CJK
if (!Char.IsSurrogate(ch2))
{
// invalid surrogate
#if NET_2_0
HandleFallback (chars, ref charIndex, ref charCount,
bytes, ref byteIndex, ref byteCount, null);
#else
bytes [byteIndex++] = (byte) '?';
#endif
continue;
}
int cp = (ch - 0xD800) * 0x400 + ch2 - 0xDC00;

View File

@@ -379,11 +379,9 @@ namespace I18N.CJK
SwitchMode (bytes, ref byteIndex, ref byteCount, ref m, ISO2022JPMode.ASCII);
value = (int) ch;
} else {
#if NET_2_0
HandleFallback (
chars, ref i, ref charCount,
bytes, ref byteIndex, ref byteCount, this);
#endif
// skip non-convertible character
continue;
}
@@ -525,10 +523,8 @@ namespace I18N.CJK
}
else
{
#if NET_2_0
HandleFallback (chars, ref i, ref charCount,
bytes, ref byteIndex, ref byteCount, this);
#endif
// skip non-convertible character
continue;
}
@@ -578,13 +574,11 @@ namespace I18N.CJK
}
#endif
#if NET_2_0
public override void Reset ()
{
m = ISO2022JPMode.ASCII;
shifted_in_conv = shifted_in_count = false;
}
#endif
}
@@ -747,13 +741,11 @@ namespace I18N.CJK
return charIndex - start;
}
#if NET_2_0
public override void Reset ()
{
m = ISO2022JPMode.ASCII;
shifted_in_count = shifted_in_conv = false;
}
#endif
}
[Serializable]

View File

@@ -214,18 +214,12 @@ namespace MonoTests.I18N.CJK
}
[Test]
#if !NET_2_0
[Category ("NotDotNet")] // MS is buggy here
#endif
public void CP50222_Encode ()
{
AssertEncode ("Test/texts/japanese-utf8.txt", "Test/texts/japanese-50222.txt", 50222);
}
[Test]
#if !NET_2_0
[Category ("NotDotNet")] // MS is buggy here
#endif
public void CP50222_Decode ()
{
AssertDecode ("Test/texts/japanese-utf8.txt", "Test/texts/japanese-50222.txt", 50222);
@@ -252,9 +246,6 @@ namespace MonoTests.I18N.CJK
}
[Test]
#if !NET_2_0
[Category ("NotDotNet")] // MS bug
#endif
public void Bug77723 ()
{
GetBytesAllSingleChars (51932);
@@ -323,9 +314,6 @@ namespace MonoTests.I18N.CJK
}
[Test]
#if !NET_2_0
[Category ("NotDotNet")] // MS bug
#endif
public void Encoder54936Refresh ()
{
Encoding e = Manager.GetEncoding ("gb18030");
@@ -355,7 +343,6 @@ namespace MonoTests.I18N.CJK
Manager.GetEncoding (932).GetBytes ("\uFF02"));
}
#if NET_2_0
[Test]
public void Decoder932Refresh ()
{
@@ -472,7 +459,6 @@ namespace MonoTests.I18N.CJK
Assert.AreEqual (1, d.GetChars (new byte [] {0xF9}, 0, 1, chars, 0, true), "#5");
Assert.AreEqual (new char [] {'?'}, chars, "#6");
}
#endif
[Test]

View File

@@ -48,11 +48,9 @@ public abstract class ByteEncoding : MonoEncoding
protected bool isMailNewsDisplay;
protected bool isMailNewsSave;
protected int windowsCodePage;
#if NET_2_0
static byte [] isNormalized;
static byte [] isNormalizedComputed;
static byte [] normalization_bytes;
#endif
// Constructor.
protected ByteEncoding(int codePage, char[] toChars,
@@ -78,7 +76,6 @@ public abstract class ByteEncoding : MonoEncoding
this.windowsCodePage = windowsCodePage;
}
#if NET_2_0
public override bool IsAlwaysNormalized (NormalizationForm form)
{
if (form != NormalizationForm.FormC)
@@ -114,7 +111,6 @@ public abstract class ByteEncoding : MonoEncoding
public override bool IsSingleByte {
get { return true; }
}
#endif
public override int GetByteCount(String s)
{

View File

@@ -51,11 +51,9 @@ public abstract class ByteSafeEncoding : MonoSafeEncoding
protected bool isMailNewsDisplay;
protected bool isMailNewsSave;
protected int windowsCodePage;
#if NET_2_0
static byte [] isNormalized;
static byte [] isNormalizedComputed;
static byte [] normalization_bytes;
#endif
// Constructor.
protected ByteSafeEncoding(int codePage, char[] toChars,
@@ -81,7 +79,6 @@ public abstract class ByteSafeEncoding : MonoSafeEncoding
this.windowsCodePage = windowsCodePage;
}
#if NET_2_0
public override bool IsAlwaysNormalized (NormalizationForm form)
{
if (form != NormalizationForm.FormC)
@@ -117,7 +114,6 @@ public abstract class ByteSafeEncoding : MonoSafeEncoding
public override bool IsSingleByte {
get { return true; }
}
#endif
public override int GetByteCount(String s)
{

View File

@@ -0,0 +1,148 @@
// This is partially copied source from referencesource/mscorlib/system/text/encoding.cs, modifying a bit.
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
using System;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Text;
namespace I18N.Common
{
[Serializable]
public class ReferenceSourceDefaultEncoder : Encoder, IObjectReference
{
private Encoding m_encoding;
[NonSerialized] private bool m_hasInitializedEncoding;
[NonSerialized] internal char charLeftOver;
public ReferenceSourceDefaultEncoder(Encoding encoding)
{
m_encoding = encoding;
m_hasInitializedEncoding = true;
}
// Constructor called by serialization, have to handle deserializing from Everett
internal ReferenceSourceDefaultEncoder(SerializationInfo info, StreamingContext context)
{
if (info==null) throw new ArgumentNullException("info");
Contract.EndContractBlock();
// All we have is our encoding
this.m_encoding = (Encoding)info.GetValue("encoding", typeof(Encoding));
try
{
//this.m_fallback = (EncoderFallback) info.GetValue("m_fallback", typeof(EncoderFallback));
this.charLeftOver = (Char) info.GetValue("charLeftOver", typeof(Char));
}
catch (SerializationException)
{
}
}
// Just get it from GetEncoding
[System.Security.SecurityCritical] // auto-generated
public Object GetRealObject(StreamingContext context)
{
// upon deserialization since the DefaultEncoder implement IObjectReference the
// serialization code tries to do the fixup. The fixup returns another
// IObjectReference (the DefaultEncoder) class and hence so on and on.
// Finally the deserialization logics fails after following maximum references
// unless we short circuit with the following
if (m_hasInitializedEncoding)
{
return this;
}
Encoder encoder = m_encoding.GetEncoder();
/*
if (m_fallback != null)
encoder.m_fallback = m_fallback;
if (charLeftOver != (char) 0)
{
EncoderNLS encoderNls = encoder as EncoderNLS;
if (encoderNls != null)
encoderNls.charLeftOver = charLeftOver;
}
*/
return encoder;
}
#if FEATURE_SERIALIZATION
// ISerializable implementation, get data for this object
[System.Security.SecurityCritical] // auto-generated_required
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
{
// Any info?
if (info==null) throw new ArgumentNullException("info");
Contract.EndContractBlock();
// All we have is our encoding
info.AddValue("encoding", this.m_encoding);
}
#endif
// Returns the number of bytes the next call to GetBytes will
// produce if presented with the given range of characters and the given
// value of the flush parameter. The returned value takes into
// account the state in which the encoder was left following the last call
// to GetBytes. The state of the encoder is not affected by a call
// to this method.
//
public override int GetByteCount(char[] chars, int index, int count, bool flush)
{
return m_encoding.GetByteCount(chars, index, count);
}
[System.Security.SecurityCritical] // auto-generated
[SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public unsafe override int GetByteCount(char* chars, int count, bool flush)
{
return m_encoding.GetByteCount(chars, count);
}
// Encodes a range of characters in a character array into a range of bytes
// in a byte array. The method encodes charCount characters from
// chars starting at index charIndex, storing the resulting
// bytes in bytes starting at index byteIndex. The encoding
// takes into account the state in which the encoder was left following the
// last call to this method. The flush parameter indicates whether
// the encoder should flush any shift-states and partial characters at the
// end of the conversion. To ensure correct termination of a sequence of
// blocks of encoded bytes, the last call to GetBytes should specify
// a value of true for the flush parameter.
//
// An exception occurs if the byte array is not large enough to hold the
// complete encoding of the characters. The GetByteCount method can
// be used to determine the exact number of bytes that will be produced for
// a given range of characters. Alternatively, the GetMaxByteCount
// method of the Encoding that produced this encoder can be used to
// determine the maximum number of bytes that will be produced for a given
// number of characters, regardless of the actual character values.
//
public override int GetBytes(char[] chars, int charIndex, int charCount,
byte[] bytes, int byteIndex, bool flush)
{
return m_encoding.GetBytes(chars, charIndex, charCount, bytes, byteIndex);
}
[System.Security.SecurityCritical] // auto-generated
[SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public unsafe override int GetBytes(char* chars, int charCount,
byte* bytes, int byteCount, bool flush)
{
return m_encoding.GetBytes(chars, charCount, bytes, byteCount);
}
}
}

View File

@@ -6,4 +6,5 @@ Handlers.cs
Manager.cs
MonoEncoding.cs
MonoSafeEncoding.cs
DefaultEncoder.cs
Strings.cs

View File

@@ -32,7 +32,6 @@ namespace I18N.Common
get { return win_code_page != 0 ? win_code_page : base.WindowsCodePage; }
}
#if NET_2_0
/// <summary>
/// GetBytes method used internally by state-full encoders/encodings.
/// </summary>
@@ -90,7 +89,6 @@ namespace I18N.Common
HandleFallback(ref buffer, chars, ref charIndex, ref charCount,
bytes, ref byteIndex, ref byteCount, null);
}
#endif
// Get the bytes that result from encoding a character buffer.
public override int GetByteCount (
@@ -193,7 +191,6 @@ namespace I18N.Common
}
}
#if NET_2_0
public unsafe override int GetByteCount (char* chars, int count)
{
@@ -206,7 +203,6 @@ namespace I18N.Common
{
return GetBytesImpl (chars, charCount, bytes, byteCount);
}
#endif
//[CLSCompliant (false)]
public unsafe abstract int GetByteCountImpl (char* chars, int charCount);
@@ -214,19 +210,20 @@ namespace I18N.Common
//[CLSCompliant (false)]
public unsafe abstract int GetBytesImpl (char* chars, int charCount,
byte* bytes, int byteCount);
public override Encoder GetEncoder ()
{
return new MonoEncodingDefaultEncoder (this);
}
}
public abstract class MonoEncoder : Encoder
{
#if NET_2_0
MonoEncoding encoding;
#endif
public MonoEncoder (MonoEncoding encoding)
{
#if NET_2_0
this.encoding = encoding;
#endif
}
public override int GetByteCount (
@@ -289,7 +286,6 @@ namespace I18N.Common
public unsafe abstract int GetBytesImpl (char* chars, int charCount, byte* bytes, int byteCount, bool refresh);
#if NET_2_0
public unsafe override int GetBytes (char* chars, int charCount, byte* bytes, int byteCount, bool flush)
{
return GetBytesImpl (chars, charCount, bytes, byteCount, flush);
@@ -312,6 +308,77 @@ namespace I18N.Common
HandleFallback(chars, ref charIndex, ref charCount,
bytes, ref byteIndex, ref byteCount, null);
}*/
#endif
}
public class MonoEncodingDefaultEncoder : ReferenceSourceDefaultEncoder
{
public MonoEncodingDefaultEncoder (Encoding encoding)
: base (encoding)
{
}
[CLSCompliant (false)]
[ComVisible (false)]
public unsafe override 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 override void Convert (
char [] chars, int charIndex, int charCount,
byte [] bytes, int byteIndex, int byteCount, bool flush,
out int charsUsed, out int bytesUsed, out bool completed)
{
if (chars == null)
throw new ArgumentNullException ("chars");
if (bytes == null)
throw new ArgumentNullException ("bytes");
if (charIndex < 0)
throw new ArgumentOutOfRangeException ("charIndex");
if (charCount < 0 || chars.Length < charIndex + charCount)
throw new ArgumentOutOfRangeException ("charCount");
if (byteIndex < 0)
throw new ArgumentOutOfRangeException ("byteIndex");
if (byteCount < 0 || bytes.Length < byteIndex + byteCount)
throw new ArgumentOutOfRangeException ("byteCount");
charsUsed = 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");
}
}
}

View File

@@ -87,15 +87,11 @@ namespace I18N.Common
public abstract class MonoSafeEncoder : Encoder
{
#if NET_2_0
MonoSafeEncoding encoding;
#endif
public MonoSafeEncoder (MonoSafeEncoding encoding)
{
#if NET_2_0
this.encoding = encoding;
#endif
}
public void HandleFallback(

View File

@@ -140,9 +140,7 @@ public class CP1254 : ByteEncoding
int ch;
int charIndex = 0;
int byteIndex = 0;
#if NET_2_0
EncoderFallbackBuffer buffer = null;
#endif
while (charCount > 0)
{
ch = (int)(chars[charIndex]);

View File

@@ -140,9 +140,7 @@ public class CP1255 : ByteEncoding
int ch;
int charIndex = 0;
int byteIndex = 0;
#if NET_2_0
EncoderFallbackBuffer buffer = null;
#endif
while (charCount > 0)
{
ch = (int)(chars[charIndex]);

View File

@@ -140,9 +140,7 @@ public class CP1256 : ByteEncoding
int ch;
int charIndex = 0;
int byteIndex = 0;
#if NET_2_0
EncoderFallbackBuffer buffer = null;
#endif
while (charCount > 0)
{
ch = (int)(chars[charIndex]);

View File

@@ -140,9 +140,7 @@ public class CP28596 : ByteEncoding
int ch;
int charIndex = 0;
int byteIndex = 0;
#if NET_2_0
EncoderFallbackBuffer buffer = null;
#endif
while (charCount > 0)
{
ch = (int)(chars[charIndex]);

View File

@@ -140,9 +140,7 @@ public class CP28598 : ByteEncoding
int ch;
int charIndex = 0;
int byteIndex = 0;
#if NET_2_0
EncoderFallbackBuffer buffer = null;
#endif
while (charCount > 0)
{
ch = (int)(chars[charIndex]);

View File

@@ -140,9 +140,7 @@ public class CP28599 : ByteEncoding
int ch;
int charIndex = 0;
int byteIndex = 0;
#if NET_2_0
EncoderFallbackBuffer buffer = null;
#endif
while (charCount > 0)
{
ch = (int)(chars[charIndex]);

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