support for tokenizing arrays and nested arrays

This commit is contained in:
Eliot Jones
2017-11-12 14:42:01 +00:00
parent 00e3d06513
commit 158cd5f2e3
6 changed files with 245 additions and 20 deletions

View File

@@ -0,0 +1,47 @@
namespace UglyToad.Pdf.Tokenization
{
using System.Collections.Generic;
using IO;
using Scanner;
using Tokens;
public class ArrayTokenizer : ITokenizer
{
public bool ReadsNextByte { get; } = false;
public bool TryTokenize(byte currentByte, IInputBytes inputBytes, out IToken token)
{
token = null;
if (currentByte != '[')
{
return false;
}
var scanner = new CoreTokenScanner(inputBytes, ScannerScope.Array);
var contents = new List<IToken>();
IToken previousToken = null;
while (!CurrentByteEndsCurrentArray(inputBytes, previousToken) && scanner.MoveNext())
{
previousToken = scanner.CurrentToken;
contents.Add(scanner.CurrentToken);
}
token = new ArrayToken(contents);
return true;
}
private static bool CurrentByteEndsCurrentArray(IInputBytes inputBytes, IToken previousToken)
{
if (inputBytes.CurrentByte == ']' && !(previousToken is ArrayToken))
{
return true;
}
return false;
}
}
}