@@ -505,44 +505,68 @@ public boolean startNewLine() throws IOException
505
505
* @since 2.10.1
506
506
*/
507
507
public boolean skipLinesWhenNeeded () throws IOException {
508
- if (!(_allowComments || _skipBlankLines )) {
508
+ if (_allowComments ) {
509
+ return _skipCommentLines ();
510
+ }
511
+ if (!_skipBlankLines ) {
509
512
return hasMoreInput ();
510
513
}
511
- int firstCharacterPtr = _inputPtr ;
514
+
515
+ // only need to skip fully empty lines
512
516
while (hasMoreInput ()) {
513
- char ch = _inputBuffer [_inputPtr ++ ];
517
+ char ch = _inputBuffer [_inputPtr ];
514
518
if (ch == '\r' || ch == '\n' ) {
519
+ ++_inputPtr ;
515
520
_pendingLF = ch ;
516
521
_handleLF ();
517
- // track the start of the new line
518
- firstCharacterPtr = _inputPtr ;
519
522
continue ;
520
523
}
521
- if (ch == ' ' ) {
524
+ if (ch != ' ' ) {
525
+ return true ; // processing can go on
526
+ }
527
+ ++_inputPtr ;
528
+ }
529
+ return false ; // end of input
530
+ }
531
+
532
+ public boolean _skipCommentLines () throws IOException
533
+ {
534
+ while ((_inputPtr < _inputEnd ) || loadMore ()) {
535
+ char ch = _inputBuffer [_inputPtr ];
536
+ switch (ch ) {
537
+ case '#' :
538
+ ++_inputPtr ;
539
+ _skipCommentContents ();
540
+ continue ;
541
+ case '\r' :
542
+ case '\n' :
543
+ ++_inputPtr ;
544
+ _pendingLF = ch ;
545
+ _handleLF ();
546
+ continue ;
547
+ case ' ' :
522
548
// skip all blanks (in both comments/blanks skip mode)
549
+ ++_inputPtr ;
523
550
continue ;
551
+ default :
552
+ return true ;
524
553
}
525
- if (_allowComments ) {
526
- if (_inputBuffer [firstCharacterPtr ] == '#' ) {
527
- // on a commented line, skip everything
528
- continue ;
529
- }
530
- if (ch == '#' ) {
531
- // we reach this point when whitespaces precedes the hash character
532
- // move the firstCharacterPtr to the '#' location in order to skip the line completely
533
- firstCharacterPtr = _inputPtr -1 ;
534
- continue ;
535
- }
536
- }
537
- // we reached a non skippable character, this line needs to be parsed
538
- // rollback the input pointer to the beginning of the line
539
- _inputPtr = firstCharacterPtr ;
540
- return true ; // processing can go on
541
554
}
542
555
return false ; // end of input
543
556
}
544
557
545
- // 12-Apr-2020, tatu: Not used any more (probably replaced by above?)
558
+ private void _skipCommentContents () throws IOException
559
+ {
560
+ while ((_inputPtr < _inputEnd ) || loadMore ()) {
561
+ char ch = _inputBuffer [_inputPtr ++];
562
+ if (ch == '\r' || ch == '\n' ) {
563
+ _pendingLF = ch ;
564
+ _handleLF ();
565
+ break ;
566
+ }
567
+ }
568
+ }
569
+
546
570
/*
547
571
private final static int INT_HASH = '#';
548
572
@@ -559,7 +583,8 @@ protected int _skipCommentLines() throws IOException
559
583
// Ok, skipped the end of the line. Check next one...
560
584
int i = _nextChar();
561
585
if (i != INT_HASH) {
562
- return i;
586
+ --_inputPtr;
587
+ return true;
563
588
}
564
589
}
565
590
return -1; // end of input
0 commit comments