@@ -2286,10 +2286,10 @@ private function read_next_token(): int {
2286
2286
2287
2287
if ( "' " === $ byte || '" ' === $ byte || '` ' === $ byte ) {
2288
2288
$ type = $ this ->read_quoted_text ();
2289
- } elseif ( $ this -> is_digit ( $ byte ) ) {
2289
+ } elseif ( null !== $ byte && strspn ( $ byte, self :: DIGIT_MASK ) > 0 ) {
2290
2290
$ type = $ this ->read_number ();
2291
2291
} elseif ( '. ' === $ byte ) {
2292
- if ( $ this -> is_digit ( $ next_byte ) ) {
2292
+ if ( null !== $ next_byte && strspn ( $ next_byte, self :: DIGIT_MASK ) > 0 ) {
2293
2293
$ type = $ this ->read_number ();
2294
2294
} else {
2295
2295
$ this ->bytes_already_read += 1 ;
@@ -2348,7 +2348,11 @@ private function read_next_token(): int {
2348
2348
$ this ->bytes_already_read += 1 ;
2349
2349
$ type = self ::PLUS_OPERATOR ;
2350
2350
} elseif ( '- ' === $ byte ) {
2351
- if ( '- ' === $ next_byte && $ this ->is_whitespace ( $ this ->sql [ $ this ->bytes_already_read + 2 ] ?? null ) ) {
2351
+ if (
2352
+ '- ' === $ next_byte
2353
+ && $ this ->bytes_already_read + 2 < strlen ( $ this ->sql )
2354
+ && strspn ( $ this ->sql [ $ this ->bytes_already_read + 2 ], self ::WHITESPACE_MASK ) > 0
2355
+ ) {
2352
2356
$ type = $ this ->read_line_comment ();
2353
2357
} elseif ( '> ' === $ next_byte ) {
2354
2358
$ this ->bytes_already_read += 2 ; // Consume the '->'.
@@ -2473,7 +2477,7 @@ private function read_next_token(): int {
2473
2477
}
2474
2478
} elseif ( '# ' === $ byte ) {
2475
2479
$ type = $ this ->read_line_comment ();
2476
- } elseif ( $ this -> is_whitespace ( $ byte ) ) {
2480
+ } elseif ( null !== $ byte && strspn ( $ byte, self :: WHITESPACE_MASK ) > 0 ) {
2477
2481
$ this ->bytes_already_read += strspn ( $ this ->sql , self ::WHITESPACE_MASK , $ this ->bytes_already_read );
2478
2482
$ type = self ::WHITESPACE ;
2479
2483
} elseif ( '0 ' === $ byte && ( 'x ' === $ next_byte || 'b ' === $ next_byte ) ) {
@@ -2641,11 +2645,13 @@ private function read_number(): int {
2641
2645
$ next_byte = $ this ->sql [ $ this ->bytes_already_read + 1 ] ?? null ;
2642
2646
$ has_exponent =
2643
2647
( 'e ' === $ byte || 'E ' === $ byte )
2648
+ && null !== $ next_byte
2644
2649
&& (
2645
- $ this -> is_digit ( $ next_byte )
2650
+ strspn ( $ next_byte, self :: DIGIT_MASK ) > 0
2646
2651
|| (
2647
2652
( '+ ' === $ next_byte || '- ' === $ next_byte )
2648
- && $ this ->is_digit ( $ this ->sql [ $ this ->bytes_already_read + 2 ] ?? null )
2653
+ && $ this ->bytes_already_read + 2 < strlen ( $ this ->sql )
2654
+ && strspn ( $ this ->sql [ $ this ->bytes_already_read + 2 ], self ::DIGIT_MASK ) > 0
2649
2655
)
2650
2656
);
2651
2657
if ( $ has_exponent ) {
@@ -2840,14 +2846,6 @@ private function read_comment_content(): void {
2840
2846
}
2841
2847
}
2842
2848
2843
- private function is_whitespace ( ?string $ byte ): bool {
2844
- return null !== $ byte && strspn ( $ byte , self ::WHITESPACE_MASK ) > 0 ;
2845
- }
2846
-
2847
- private function is_digit ( ?string $ byte ): bool {
2848
- return null !== $ byte && strspn ( $ byte , self ::DIGIT_MASK ) > 0 ;
2849
- }
2850
-
2851
2849
private function determine_identifier_or_keyword_type ( string $ value ): int {
2852
2850
$ value = strtoupper ( $ value );
2853
2851
0 commit comments