singrdk/base/Applications/WebServer/ByteParser.sg

55 lines
1.4 KiB
Plaintext
Raw Permalink Normal View History

2008-03-05 09:52:00 -05:00
//------------------------------------------------------------------------------
2008-11-17 18:29:00 -05:00
// Copyright (c) Microsoft Corporation. All Rights Reserved.
2008-03-05 09:52:00 -05:00
//------------------------------------------------------------------------------
namespace Microsoft.Singularity.WebServer
{
using System;
using System.Collections;
using System.Text;
internal sealed class ByteParser
{
private byte[] bytes;
private int pos;
public ByteParser(byte[]! bytes)
{
this.bytes = bytes;
this.pos = 0;
}
public int CurrentOffset
{
get {
return pos;
}
}
public ByteString ReadLine()
{
ByteString line = null;
for (int i = pos; i < bytes.Length; i++) {
if (bytes[i] == (byte)'\n') {
int len = i-pos;
2008-11-17 18:29:00 -05:00
if (len > 0 && bytes[i - 1] == (byte)'\r') {
2008-03-05 09:52:00 -05:00
len--;
}
line = new ByteString(bytes, pos, len);
pos = i+1;
return line;
}
}
if (pos < bytes.Length) {
line = new ByteString(bytes, pos, bytes.Length-pos);
}
pos = bytes.Length;
return line;
}
}
}