forked from UglyToad/PdfPig
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayTokenizer.cs
More file actions
60 lines (46 loc) · 1.55 KB
/
ArrayTokenizer.cs
File metadata and controls
60 lines (46 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
namespace UglyToad.PdfPig.Tokenization
{
using System.Collections.Generic;
using Core;
using Scanner;
using Tokens;
internal sealed class ArrayTokenizer : ITokenizer
{
private readonly bool usePdfDocEncoding;
public bool ReadsNextByte => false;
public ArrayTokenizer(bool usePdfDocEncoding)
{
this.usePdfDocEncoding = usePdfDocEncoding;
}
public bool TryTokenize(byte currentByte, IInputBytes inputBytes, out IToken token)
{
token = null;
if (currentByte != '[')
{
return false;
}
var scanner = new CoreTokenScanner(inputBytes, usePdfDocEncoding, 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;
}
}
}