Files
PdfPig/src/UglyToad.PdfPig.Tokenization/CommentTokenizer.cs
Jason Nelson 7f42a8d60c Reduce Allocations (#821)
* Introduce ValueStringBuilder

* Make NumericTokenizer and PlanTextTokenizer thread-safe

* Replace ListPool with ArrayPoolBufferWriter

* Seal ITokenizer classes

* Eliminate array allocation in Type1ArrayTokenizer

* Eliminate array allocation in AcroFormFactory

* Eliminate StringBuilder allocation in Page.GetText

* Optimize PdfSubpath.ToLines

* Eliminate various allocations when parsing CompactFontFormat

* Remove unused FromOctalInt helper

* Ensure Pdf.Content is not null

* Write ASCII values directly to stream (avoiding allocations)

* Avoid encoding additional ASCII values

* Eliminate allocations in TokenWriter.WriteName

* Eliminate allocation in TokenWriter.WriteNumber

* Add System.Memory reference to Fonts
2024-04-28 18:55:58 +01:00

33 lines
786 B
C#

namespace UglyToad.PdfPig.Tokenization
{
using Core;
using System.Text;
using Tokens;
internal sealed class CommentTokenizer : ITokenizer
{
public bool ReadsNextByte { get; } = true;
public bool TryTokenize(byte currentByte, IInputBytes inputBytes, out IToken token)
{
token = null;
if (currentByte != '%')
{
return false;
}
using var builder = new ValueStringBuilder();
while (inputBytes.MoveNext() && !ReadHelper.IsEndOfLine(inputBytes.CurrentByte))
{
builder.Append((char) inputBytes.CurrentByte);
}
token = new CommentToken(builder.ToString());
return true;
}
}
}