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

@ -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");
}
}
}