Fix bug in parser when there are hidden chars at beginning of pgn
This commit is contained in:
@@ -83,6 +83,7 @@ class PgnParser
|
||||
$c = str_replace("0-0-0", "O-O-O", $c);
|
||||
$c = str_replace("0-0", "O-O", $c);
|
||||
|
||||
$c = preg_replace('/^([^\[])*?\[/', '[', $c);
|
||||
|
||||
return $c;
|
||||
}
|
||||
@@ -102,12 +103,16 @@ class PgnParser
|
||||
$ret = array();
|
||||
$content = "\n\n" . $pgn;
|
||||
$games = preg_split("/\n\n\[/s", $content, -1, PREG_SPLIT_DELIM_CAPTURE);
|
||||
|
||||
file_put_contents("parsed.pgn", $content);
|
||||
|
||||
for ($i = 1, $count = count($games); $i < $count; $i++) {
|
||||
$gameContent = trim("[" . $games[$i]);
|
||||
if (strlen($gameContent) > 10) {
|
||||
array_push($ret, $gameContent);
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
@@ -2691,5 +2691,20 @@ $pgn = '[Event "URS-ch23"]
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldImportAllGames(){
|
||||
$pgn = file_get_contents("pgn/philadelphiainternational2019.pgn");
|
||||
// when
|
||||
$parser = new PgnParser();
|
||||
$parser->setPgnContent($pgn);
|
||||
$content = $parser->getUnparsedGames();
|
||||
// when
|
||||
|
||||
// then
|
||||
$this->assertEquals(132, $parser->countGames());
|
||||
}
|
||||
}
|
||||
|
||||
|
3140
test/pgn/philadelphiainternational2019.pgn
Normal file
3140
test/pgn/philadelphiainternational2019.pgn
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user