Added PreviousChar() function
This commit is contained in:
parent
83c70333f8
commit
1bc3727ce8
@ -716,6 +716,30 @@ namespace Assignment_1
|
||||
return c;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the previous char
|
||||
/// </summary>
|
||||
/// <param name="s"></param>
|
||||
/// <returns></returns>
|
||||
static char PreviousChar(Stream s)
|
||||
{
|
||||
Stack<byte> charBytes = new Stack<byte>(4);
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
if (s.Position == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
s.Position--;
|
||||
byte read = (byte)s.ReadByte();
|
||||
charBytes.Push(read);
|
||||
// No longer an UTF-8 extension, last byte is the final
|
||||
if (read >> 6 != 2) break;
|
||||
}
|
||||
string converted = Encoding.UTF8.GetString(charBytes.ToArray());
|
||||
return converted[0];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Skips whitespace characters
|
||||
/// </summary>
|
||||
|
Loading…
x
Reference in New Issue
Block a user