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)
{
}
[ComVisible (false)]
- public virtual void Convert (
+ public unsafe 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)
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;
+ // refactorize passing control to byte* version
+ fixed (char* cptr = chars) {
+ fixed (byte* bptr = bytes) {
+ Convert(bptr + byteIndex, byteCount,
+ cptr + charIndex, charCount,
+ flush,
+ out bytesUsed, out charsUsed,
+ out completed);
+ }
}
- 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)
+ if (charIndex < 0 || chars.Length < charIndex)
throw new ArgumentOutOfRangeException ("charIndex");
}
{
if (bytes == null)
throw new ArgumentNullException ("bytes");
- if (byteIndex < 0 || bytes.Length <= byteIndex)
+ if (byteIndex < 0)
throw new ArgumentOutOfRangeException ("byteIndex");
if (byteCount < 0 || bytes.Length < byteIndex + byteCount)
throw new ArgumentOutOfRangeException ("byteCount");
if (byteCount < 0)
throw new ArgumentOutOfRangeException ("byteCount");
}
-#endif
-
}; // class Decoder
}; // namespace System.Text