Commit b5b669cc authored by David Maus's avatar David Maus
Browse files

Use regular expression to ignore certain lines from input

* src/HAB/Pica/Reader/PicaPlainReader.php (next): Use regular
  expression to ignore certain lines from input.
* src/HAB/Pica/Reader/PicaPlainReader.php ($ignoreLineRegexp): New
  property. Regexp for lines that should be ignored.
parent 142fe277
......@@ -20,7 +20,7 @@
*
* @package PicaReader
* @author David Maus <maus@hab.de>
* @copyright Copyright (c) 2012 - 2016 by Herzog August Bibliothek Wolfenbüttel
* @copyright Copyright (c) 2012 - 2017 by Herzog August Bibliothek Wolfenbüttel
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License v3
*/
......@@ -32,6 +32,13 @@ use HAB\Pica\Parser\PicaPlainParser;
class PicaPlainReader extends Reader
{
/**
* Regular expression matching lines that should be ignore.
*
* @var string
*/
public $ignoreLineRegexp = '/^$/';
/**
* Current input data.
*
......@@ -78,7 +85,9 @@ class PicaPlainReader extends Reader
$record = array('fields' => array());
do {
$line = current($this->_data);
$record['fields'] []= $this->_parser->parseField($line);
if (!preg_match($this->ignoreLineRegexp, $line)) {
$record['fields'] []= $this->_parser->parseField($line);
}
} while (next($this->_data));
next($this->_data);
}
......
......@@ -105,6 +105,13 @@ class PicaPlainReaderTest extends PHPUnit_FrameWork_TestCase
$this->_reader->unsetFilter();
}
public function testReadIgnoreLines ()
{
$this->_reader->open("002@/00 \$0T\nfoo: foobar");
$this->_reader->ignoreLineRegexp = '/^[a-z]+:/';
$this->_reader->read();
}
///
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment