1- using System ;
2-
31namespace RobotsTxt
42{
5- public class RobotsTxtParser
3+ public class RobotsTxtParser ( byte [ ] robotsBody , IRobotsParseHandler handler )
64 {
7- static readonly byte [ ] UtfBom = { 0xEF , 0xBB , 0xBF } ;
5+ static readonly byte [ ] UtfBom = [ 0xEF , 0xBB , 0xBF ] ;
86 static readonly byte [ ] HexDigits = "0123456789ABCDEF"u8 . ToArray ( ) ;
97
108 public void Parse ( )
@@ -21,9 +19,9 @@ public void Parse()
2119 var lineNum = 0 ;
2220 var bomPos = 0 ;
2321 bool lastWasCarriageReturn = false ;
24- _handler . HandleRobotsStart ( ) ;
22+ handler . HandleRobotsStart ( ) ;
2523
26- foreach ( var ch in _robotsBody )
24+ foreach ( var ch in robotsBody )
2725 {
2826 // Google-specific optimization: UTF-8 byte order marks should never
2927 // appear in a robots.txt file, but they do nevertheless. Skipping
@@ -62,16 +60,7 @@ public void Parse()
6260
6361 var spanLeft = lineBuffer . AsSpan ( 0 , linePos ) ;
6462 ParseAndEmitLine ( ++ lineNum , spanLeft ) ;
65- _handler . HandleRobotsEnd ( ) ;
66- }
67-
68- private readonly byte [ ] _robotsBody ;
69- private readonly IRobotsParseHandler _handler ;
70-
71- public RobotsTxtParser ( byte [ ] robotsBody , IRobotsParseHandler handler )
72- {
73- _robotsBody = robotsBody ;
74- _handler = handler ;
63+ handler . HandleRobotsEnd ( ) ;
7564 }
7665
7766 void ParseAndEmitLine ( int currentLine , ReadOnlySpan < byte > line )
@@ -86,16 +75,15 @@ void ParseAndEmitLine(int currentLine, ReadOnlySpan<byte> line)
8675 if ( NeedEscapeValueForKey ( key ) )
8776 {
8877 var escapedValue = MaybeEscapePattern ( value ) ;
89- EmitKeyValueToHandler ( currentLine , key , escapedValue , _handler ) ;
78+ EmitKeyValueToHandler ( currentLine , key , escapedValue ) ;
9079 }
9180 else
9281 {
93- EmitKeyValueToHandler ( currentLine , key , value , _handler ) ;
82+ EmitKeyValueToHandler ( currentLine , key , value ) ;
9483 }
9584 }
9685
97- private void EmitKeyValueToHandler ( int currentLine , ParsedRobotsKey key , ReadOnlySpan < byte > value ,
98- IRobotsParseHandler handler )
86+ private void EmitKeyValueToHandler ( int currentLine , ParsedRobotsKey key , ReadOnlySpan < byte > value )
9987 {
10088 switch ( key . Type )
10189 {
0 commit comments