#
# This software is Copyright 2005 by Elsevier Inc.  You may use it
# under the terms of the license at http://perl.plover.com/hop/LICENSE.txt .
#



###
### records-string-terminated
###

## Chapter 8 section 1.1

sub records {
  my $chars = shift;
  my $terminator = @_ ? shift : $/;
  my $buffer = "";
  sub {
    my $char;
    while (substr($buffer, -(length $terminator)) ne $terminator 
           && defined($char = $chars->())
          ) {
      $buffer .= $char;
    }
    if ($buffer ne "") {
      my $line = $buffer;
      $buffer = "";
      return $line;
    } else {
      return;
    }
  }
}
