more cleanPgn() cleanup: trim lines, del initial blanks, one space only...

This commit is contained in:
2023-06-18 21:01:59 +02:00
parent ce0923d0e9
commit c1b1beab72

View File

@@ -89,11 +89,6 @@ class PgnParser
*/
$c = preg_replace('/"\]\s*([\.0-9]|{)/s', "\"]\n\n$1", $c);
/* remove space before '['
* This is possible because brackets within comments are protected above
*/
$c = str_replace(" +[", "[", $c);
/* set '\n\n' between non tag line and tag line (between two games)
* This is possible because brackets within comments are protected above
*/
@@ -102,7 +97,15 @@ class PgnParser
/* revert brackets within movetext comments */
$c = str_replace("//--SB--//", "[", $c);
/* max 2 consecutive '\n */
/* Final trimming:
* - remove initial blanks
* - keep only one space
* - trim lines
* - max 2 consecutive '\n'
*/
$c = preg_replace("/^\s+([^\s])/", "$1", $c);
$c = preg_replace("/ +/", " ", $c);
$c = preg_replace("/\s*\n\s*/", "\n", $c);
$c = preg_replace("/\n{3,}/s", "\n\n", $c);
return $c;