// state between multiple calls to this method.
private static int InternalGetCharCount (
byte[] bytes, int index, int count, uint leftOverBits,
- uint leftOverCount, object provider,
- ref DecoderFallbackBuffer fallbackBuffer, bool flush)
+ uint leftOverCount, DecoderFallbackBuffer fallbackBuffer, bool flush)
#else
private static int InternalGetCharCount (
byte[] bytes, int index, int count, uint leftOverBits,
} else {
// Invalid UTF-8 start character.
#if NET_2_0
- length += Fallback (provider, ref fallbackBuffer, bytes, index - 1);
+ length += Fallback (fallbackBuffer, bytes, index - 1);
#else
if (throwOnInvalid)
throw new ArgumentException (_("Arg_InvalidUTF8"), "bytes");
}
if (overlong) {
#if NET_2_0
- length += Fallback (provider, ref fallbackBuffer, bytes, index - 1);
+ length += Fallback (fallbackBuffer, bytes, index - 1);
#else
if (throwOnInvalid)
throw new ArgumentException (_("Overlong"), leftBits.ToString ());
length += 2;
} else {
#if NET_2_0
- length += Fallback (provider, ref fallbackBuffer, bytes, index - 1);
+ length += Fallback (fallbackBuffer, bytes, index - 1);
#else
if (throwOnInvalid)
throw new ArgumentException (_("Arg_InvalidUTF8"), "bytes");
} else {
// Invalid UTF-8 sequence: clear and restart.
#if NET_2_0
- length += Fallback (provider, ref fallbackBuffer, bytes, index - 1);
+ length += Fallback (fallbackBuffer, bytes, index - 1);
#else
if (throwOnInvalid)
throw new ArgumentException (_("Arg_InvalidUTF8"), "bytes");
// 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, bytes, index - 1);
+ length += Fallback (fallbackBuffer, bytes, index - 1);
#else
if (throwOnInvalid)
throw new ArgumentException (_("Arg_InvalidUTF8"), "bytes");
#if NET_2_0
// for GetCharCount()
- static int Fallback (object provider, ref DecoderFallbackBuffer buffer, byte [] bytes, int index)
+ static int Fallback (DecoderFallbackBuffer buffer, byte [] bytes, int index)
{
- if (buffer == null) {
- DecoderFallback fb = provider as DecoderFallback;
- if (fb != null)
- buffer = fb.CreateFallbackBuffer ();
- else
- buffer = ((Decoder) provider).FallbackBuffer;
- }
buffer.Fallback (bytes, index - 1);
return buffer.Remaining;
}
// for GetChars()
- static void Fallback (object provider, ref DecoderFallbackBuffer buffer, byte [] bytes, int byteIndex,
+ static void Fallback (DecoderFallbackBuffer buffer, byte [] bytes, int byteIndex,
char [] chars, ref int charIndex)
{
- if (buffer == null) {
- DecoderFallback fb = provider as DecoderFallback;
- if (fb != null)
- buffer = fb.CreateFallbackBuffer ();
- else
- buffer = ((Decoder) provider).FallbackBuffer;
- }
buffer.Fallback (bytes, byteIndex - 1);
while (buffer.Remaining > 0)
chars [charIndex++] = buffer.GetNextChar ();
public override int GetCharCount (byte[] bytes, int index, int count)
{
#if NET_2_0
- DecoderFallbackBuffer buf = null;
- return InternalGetCharCount (bytes, index, count, 0, 0, DecoderFallback, ref buf, true);
+ return InternalGetCharCount (bytes, index, count, 0, 0, DecoderFallback.CreateFallbackBuffer (), true);
#else
return InternalGetCharCount (bytes, index, count, 0, 0, throwOnInvalid, true);
#endif
private static int InternalGetChars (
byte[] bytes, int byteIndex, int byteCount, char[] chars,
int charIndex, ref uint leftOverBits, ref uint leftOverCount,
- object provider,
- ref DecoderFallbackBuffer fallbackBuffer, bool flush)
+ DecoderFallbackBuffer fallbackBuffer, bool flush)
#else
private static int InternalGetChars (
byte[] bytes, int byteIndex, int byteCount, char[] chars,
uint leftBits = leftOverBits;
uint leftSoFar = (leftOverCount & (uint)0x0F);
uint leftSize = ((leftOverCount >> 4) & (uint)0x0F);
-
- int byteEnd = byteIndex + byteCount;
- if (byteEnd < 0 || byteEnd > bytes.Length)
- throw new SystemException (String.Format ("INTERNAL ERROR: should not happen: {0} {1} {2}", byteIndex, byteCount, byteEnd));
-
- for(; byteIndex < byteEnd; byteIndex++) {
+ while (byteCount > 0) {
// Fetch the next character from the byte buffer.
- ch = (uint)(bytes[byteIndex]);
+ ch = (uint)(bytes[byteIndex++]);
+ --byteCount;
if (leftSize == 0) {
// Process a UTF-8 start character.
if (ch < (uint)0x0080) {
} else {
// Invalid UTF-8 start character.
#if NET_2_0
- Fallback (provider, ref fallbackBuffer, bytes, byteIndex, chars, ref posn);
+ Fallback (fallbackBuffer, bytes, byteIndex, chars, ref posn);
#else
if (throwOnInvalid)
throw new ArgumentException (_("Arg_InvalidUTF8"), "bytes");
}
if (overlong) {
#if NET_2_0
- Fallback (provider, ref fallbackBuffer, bytes, byteIndex, chars, ref posn);
+ Fallback (fallbackBuffer, bytes, byteIndex, chars, ref posn);
#else
if (throwOnInvalid)
throw new ArgumentException (_("Overlong"), leftBits.ToString ());
(char)((leftBits & (uint)0x3FF) + (uint)0xDC00);
} else {
#if NET_2_0
- Fallback (provider, ref fallbackBuffer, bytes, byteIndex, chars, ref posn);
+ Fallback (fallbackBuffer, bytes, byteIndex, chars, ref posn);
#else
if (throwOnInvalid)
throw new ArgumentException (_("Arg_InvalidUTF8"), "bytes");
} else {
// Invalid UTF-8 sequence: clear and restart.
#if NET_2_0
- Fallback (provider, ref fallbackBuffer, bytes, byteIndex, chars, ref posn);
+ Fallback (fallbackBuffer, bytes, byteIndex, chars, ref posn);
#else
if (throwOnInvalid)
throw new ArgumentException (_("Arg_InvalidUTF8"), "bytes");
#endif
leftSize = 0;
--byteIndex;
+ ++byteCount;
}
}
}
// We had left-over bytes that didn't make up
// a complete UTF-8 character sequence.
#if NET_2_0
- Fallback (provider, ref fallbackBuffer, bytes, byteIndex, chars, ref posn);
+ Fallback (fallbackBuffer, bytes, byteIndex, chars, ref posn);
#else
if (throwOnInvalid)
throw new ArgumentException (_("Arg_InvalidUTF8"), "bytes");
uint leftOverBits = 0;
uint leftOverCount = 0;
#if NET_2_0
- DecoderFallbackBuffer buf = null;
return InternalGetChars (bytes, byteIndex, byteCount, chars,
- charIndex, ref leftOverBits, ref leftOverCount, DecoderFallback, ref buf, true);
+ charIndex, ref leftOverBits, ref leftOverCount, DecoderFallback.CreateFallbackBuffer (), true);
#else
return InternalGetChars (bytes, byteIndex, byteCount, chars,
charIndex, ref leftOverBits, ref leftOverCount, throwOnInvalid, true);
public override int GetCharCount (byte[] bytes, int index, int count)
{
#if NET_2_0
- DecoderFallbackBuffer buf = null;
return InternalGetCharCount (bytes, index, count,
- leftOverBits, leftOverCount, this, ref buf, false);
+ leftOverBits, leftOverCount, FallbackBuffer, false);
#else
return InternalGetCharCount (bytes, index, count,
leftOverBits, leftOverCount, throwOnInvalid, false);
int byteCount, char[] chars, int charIndex)
{
#if NET_2_0
- DecoderFallbackBuffer buf = null;
return InternalGetChars (bytes, byteIndex, byteCount,
- chars, charIndex, ref leftOverBits, ref leftOverCount, this, ref buf, false);
+ chars, charIndex, ref leftOverBits, ref leftOverCount, FallbackBuffer, false);
#else
return InternalGetChars (bytes, byteIndex, byteCount,
chars, charIndex, ref leftOverBits, ref leftOverCount, throwOnInvalid, false);