singrdk/base/Applications/cassini/ByteParser.cs

51 lines
1.4 KiB
C#
Raw 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
//------------------------------------------------------------------------------
2008-11-17 18:29:00 -05:00
namespace Microsoft.VisualStudio.WebHost
{
2008-03-05 09:52:00 -05:00
using System;
using System.Collections;
using System.Text;
internal sealed class ByteParser {
private byte[] _bytes;
private int _pos;
public ByteParser(byte[] bytes) {
_bytes = bytes;
_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;
}
}
}