//
// (C)2003 Atsushi Enomoto
//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
using System;
using System.IO;
using System.Text;
private void Initialize (Stream stream)
{
- buffer = new byte [1024];
+ buffer = new byte [64];
this.stream = stream;
enc = Encoding.UTF8; // Default to UTF8 if we can't guess it
bufLength = stream.Read (buffer, 0, buffer.Length);
// try to get encoding name from XMLDecl.
if (bufLength >= 5 && Encoding.ASCII.GetString (buffer, 1, 4) == "?xml") {
bufPos += 4;
- int loop = 0;
c = SkipWhitespace ();
// version. It is optional here.
if (c == 'v') {
- while (loop++ >= 0 && c >= 0) {
- ReadByteSpecial ();
+ while (c >= 0) {
c = ReadByteSpecial ();
if (c == '0') { // 0 of 1.0
+ ReadByteSpecial ();
break;
}
}
if (c == 'e') {
int remaining = bufLength - bufPos;
- if (remaining >= 7 && Encoding.ASCII.GetString(buffer, 0, 7) == "ncoding") {
+ if (remaining >= 7 && Encoding.ASCII.GetString(buffer, bufPos, 7) == "ncoding") {
bufPos += 7;
c = SkipWhitespace();
if (c != '=')
c = SkipWhitespace ();
int quoteChar = c;
StringBuilder sb = new StringBuilder ();
- while (loop++ >= 0) {
+ while (true) {
c = ReadByteSpecial ();
if (c == quoteChar)
break;
}
// skips whitespace and returns misc char that was read from stream
- private int SkipWhitespace () // ms may be null
+ private int SkipWhitespace ()
{
- int loop = 0;
int c;
- while (loop++ >= 0) { // defends infinite loop (expecting overflow)
+ while (true) {
c = ReadByteSpecial ();
- switch (c) {
+ switch ((char) c) {
case '\r': goto case ' ';
case '\n': goto case ' ';
case '\t': goto case ' ';
{
int ret;
if (count <= bufLength - bufPos) { // all from buffer
- Array.Copy (this.buffer, bufPos, buffer, offset, count);
+ Buffer.BlockCopy (this.buffer, bufPos, buffer, offset, count);
bufPos += count;
ret = count;
} else {
int bufRest = bufLength - bufPos;
if (bufLength > bufPos) {
- Array.Copy (this.buffer, bufPos, buffer, offset, bufRest);
+ Buffer.BlockCopy (this.buffer, bufPos, buffer, offset, bufRest);
bufPos += bufRest;
}
ret = bufRest +