public function testStripCommentFromLine() { $test_data = 'www IN CNAME example.com ; This is a comment that needs to be stripped'; $empty_comment = 'example.com IN A 255.255.255.255'; $stripped = Interpreter::stripCommentFromLine($test_data); $this->assertEquals('www IN CNAME example.com', $stripped[0]); $this->assertEquals('This is a comment that needs to be stripped', $stripped[1]); $stripped = Interpreter::stripCommentFromLine($empty_comment); $this->assertEquals('example.com IN A 255.255.255.255', $stripped[0]); $this->assertEquals('', $stripped[1]); }
/** * Parses a data(s) and returns the logic * part and comment part * * @param \ArrayIterator $iterator * @return Line */ public static function parseLine(\ArrayIterator $iterator) { list($line, $comment) = Interpreter::stripCommentFromLine($iterator->current()); if (strpos($line, '(') !== false) { $comment = (array) $comment; $flag = true; while ($flag) { $iterator->next(); list($_line, $comment[]) = Interpreter::stripCommentFromLine($iterator->current()); $line .= ' ' . $_line; if (strpos($_line, ')') !== false) { $line = trim(preg_replace('/\\s*[\\(\\)]\\s*/', ' ', $line)); //Remove the brackets $flag = false; } } $comment = trim(preg_replace('/\\s+/', ' ', implode(' ', $comment))); } return new Line($line, $comment); }