mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-11-28 09:28:25 +08:00
adding in PlainTokenizer to unpooled SB changes
This commit is contained in:
@@ -1,11 +1,12 @@
|
|||||||
namespace UglyToad.PdfPig.Tokenization
|
namespace UglyToad.PdfPig.Tokenization
|
||||||
{
|
{
|
||||||
using Core;
|
using Core;
|
||||||
|
using System.Text;
|
||||||
using Tokens;
|
using Tokens;
|
||||||
|
|
||||||
internal class PlainTokenizer : ITokenizer
|
internal class PlainTokenizer : ITokenizer
|
||||||
{
|
{
|
||||||
private static readonly StringBuilderPool StringBuilderPool = new StringBuilderPool(10);
|
private readonly StringBuilder stringBuilder = new();
|
||||||
|
|
||||||
public bool ReadsNextByte { get; } = true;
|
public bool ReadsNextByte { get; } = true;
|
||||||
|
|
||||||
@@ -18,7 +19,7 @@
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var builder = StringBuilderPool.Borrow();
|
var builder = stringBuilder;
|
||||||
builder.Append((char)currentByte);
|
builder.Append((char)currentByte);
|
||||||
while (inputBytes.MoveNext())
|
while (inputBytes.MoveNext())
|
||||||
{
|
{
|
||||||
@@ -39,7 +40,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
var text = builder.ToString();
|
var text = builder.ToString();
|
||||||
StringBuilderPool.Return(builder);
|
builder.Clear();
|
||||||
|
|
||||||
switch (text)
|
switch (text)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -15,10 +15,10 @@
|
|||||||
private static readonly DictionaryTokenizer DictionaryTokenizer = new DictionaryTokenizer();
|
private static readonly DictionaryTokenizer DictionaryTokenizer = new DictionaryTokenizer();
|
||||||
private static readonly HexTokenizer HexTokenizer = new HexTokenizer();
|
private static readonly HexTokenizer HexTokenizer = new HexTokenizer();
|
||||||
private static readonly NameTokenizer NameTokenizer = new NameTokenizer();
|
private static readonly NameTokenizer NameTokenizer = new NameTokenizer();
|
||||||
private static readonly PlainTokenizer PlainTokenizer = new PlainTokenizer();
|
|
||||||
|
|
||||||
// NOTE: these are not thread safe so should not be static. Each instance includes a
|
// NOTE: these are not thread safe so should not be static. Each instance includes a
|
||||||
// StringBuilder it re-uses.
|
// StringBuilder it re-uses.
|
||||||
|
private readonly PlainTokenizer PlainTokenizer = new PlainTokenizer();
|
||||||
private readonly NumericTokenizer NumericTokenizer = new NumericTokenizer();
|
private readonly NumericTokenizer NumericTokenizer = new NumericTokenizer();
|
||||||
private readonly StringTokenizer StringTokenizer = new StringTokenizer();
|
private readonly StringTokenizer StringTokenizer = new StringTokenizer();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user