mirror of
https://github.com/UglyToad/PdfPig.git
synced 2026-03-10 00:23:29 +08:00
Some checks failed
Build, test and publish draft / build (push) Has been cancelled
Build and test [MacOS] / build (push) Has been cancelled
Run Common Crawl Tests / build (0000-0001) (push) Has been cancelled
Run Common Crawl Tests / build (0002-0003) (push) Has been cancelled
Run Common Crawl Tests / build (0004-0005) (push) Has been cancelled
Run Common Crawl Tests / build (0006-0007) (push) Has been cancelled
Run Integration Tests / build (push) Has been cancelled
Nightly Release / Check if this commit has already been published (push) Has been cancelled
Nightly Release / tests (push) Has been cancelled
Nightly Release / build_and_publish_nightly (push) Has been cancelled
63 lines
1.7 KiB
C#
63 lines
1.7 KiB
C#
namespace UglyToad.PdfPig.Tokenization
|
|
{
|
|
using System.Collections.Generic;
|
|
using Core;
|
|
using Scanner;
|
|
using Tokens;
|
|
|
|
internal sealed class ArrayTokenizer : ITokenizer
|
|
{
|
|
private readonly bool usePdfDocEncoding;
|
|
private readonly StackDepthGuard stackDepthGuard;
|
|
|
|
public bool ReadsNextByte { get; } = false;
|
|
|
|
public ArrayTokenizer(bool usePdfDocEncoding, StackDepthGuard stackDepthGuard)
|
|
{
|
|
this.usePdfDocEncoding = usePdfDocEncoding;
|
|
this.stackDepthGuard = stackDepthGuard;
|
|
}
|
|
|
|
public bool TryTokenize(byte currentByte, IInputBytes inputBytes, out IToken token)
|
|
{
|
|
token = null;
|
|
|
|
if (currentByte != '[')
|
|
{
|
|
return false;
|
|
}
|
|
|
|
var scanner = new CoreTokenScanner(inputBytes, usePdfDocEncoding, stackDepthGuard, ScannerScope.Array);
|
|
|
|
var contents = new List<IToken>();
|
|
|
|
IToken previousToken = null;
|
|
while (!CurrentByteEndsCurrentArray(inputBytes, previousToken) && scanner.MoveNext())
|
|
{
|
|
previousToken = scanner.CurrentToken;
|
|
|
|
if (scanner.CurrentToken is CommentToken)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|