return base.Read (dest_buffer, index, count);
}
#if NET_1_1
- catch (System.ArgumentException) {
- throw invalidDataException;
+ catch (System.ArgumentException ex) {
+ throw new XmlException ("Invalid data", ex);
}
#else
catch (System.Text.DecoderFallbackException) {
Initialize (stream);
}
- static string GetStringFromBytes (byte [] bytes, int index, int count)
+ // this returns null, instead of throwing ArgumentOutOfRangeException
+ string GetStringFromBytes (int index, int count)
{
+ int posBak = bufPos;
+ while (bufPos < index + count)
+ if (ReadByteSpecial () < 0)
+ return null;
+ bufPos = posBak;
#if MOONLIGHT
char [] chars = new char [count];
for (int i = index; i < count; i++)
- chars [i] = (char) bytes [i];
+ chars [i] = (char) buffer [i];
return new string (chars);
#else
- return Encoding.ASCII.GetString (bytes, index, count);
+ return Encoding.ASCII.GetString (buffer, index, count);
#endif
}
break;
case '<':
// try to get encoding name from XMLDecl.
- if (bufLength >= 5 && GetStringFromBytes (buffer, 1, 4) == "?xml") {
+ if (bufLength >= 5 && GetStringFromBytes (1, 4) == "?xml") {
bufPos += 4;
c = SkipWhitespace ();
}
if (c == 'e') {
- int remaining = bufLength - bufPos;
- if (remaining >= 7 && GetStringFromBytes (buffer, bufPos, 7) == "ncoding") {
+ if (GetStringFromBytes (bufPos, 7) == "ncoding") {
bufPos += 7;
c = SkipWhitespace();
if (c != '=')