# Consume matching text, if found next: sub eat { my( $re, # Regex or string to match against next part of doc. $keep_ws, # Don't skip over whitespace first? $sv, # Append matched text to referenced scalar (if any). $to_end, # Allow match to hit end of $Buf? $peek, # Keep pos() unchanged? ) = @_; $Buf =~ /\G\s+/gc if ! $keep_ws; my $start = pos( $Buf ); $re = _compile( $re ); # Prepends \G also do { return 0 if $Buf !~ /$re/gc; } while( ! $to_end && _hit_end(\$start) ); $$sv .= substr( $Buf, $start, pos($Buf)-$start ) if $sv; pos($Buf) = $start if $peek; return 1; } #### # Consume matching text, if found next: sub eat { my( $re, # Regex or string to match against next part of doc. $keep_ws, # Don't skip over whitespace first? $sv, # Append matched text to referenced scalar (if any). $to_end, # Allow match to hit end of $Buf? $peek, # Keep pos() unchanged? ) = @_; 0 while ! $keep_ws && eat( '\s+', 1, '', 1 ); my $start = pos( $Buf ); _hit_end( \$start ); $re = _compile( $re ); # Prepends \G also do { return 0 if $Buf !~ /$re/gc; } while( ! $to_end && _hit_end(\$start) ); $$sv .= substr( $Buf, $start, pos($Buf)-$start ) if $sv; pos($Buf) = $start if $peek; return 1; }