more cleanPgn() cleanup: trim lines, del initial blanks, one space only...
This commit is contained in:
@@ -89,11 +89,6 @@ class PgnParser
|
|||||||
*/
|
*/
|
||||||
$c = preg_replace('/"\]\s*([\.0-9]|{)/s', "\"]\n\n$1", $c);
|
$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)
|
/* set '\n\n' between non tag line and tag line (between two games)
|
||||||
* This is possible because brackets within comments are protected above
|
* This is possible because brackets within comments are protected above
|
||||||
*/
|
*/
|
||||||
@@ -102,7 +97,15 @@ class PgnParser
|
|||||||
/* revert brackets within movetext comments */
|
/* revert brackets within movetext comments */
|
||||||
$c = str_replace("//--SB--//", "[", $c);
|
$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);
|
$c = preg_replace("/\n{3,}/s", "\n\n", $c);
|
||||||
|
|
||||||
return $c;
|
return $c;
|
||||||
|
Reference in New Issue
Block a user