Use references to edit string in place

This commit is contained in:
2023-06-27 09:51:26 +01:00
parent 692789b21d
commit 8b698bb3fd

View File

@@ -84,12 +84,13 @@ final class IconRuntime implements RuntimeExtensionInterface
private function getSanitisedIconSvg(string $iconName): string
{
$iconFilepath = $this->findSvgFilepath($iconName);
$rawSvgMarkup = $this->getSvgMarkup($iconFilepath);
$cleanSvgMarkup = $this->removeExistingTitleElement($rawSvgMarkup);
$cleanSvgMarkup = $this->removeBlackStrokeAttributes($cleanSvgMarkup);
$cleanSvgMarkup = $this->removeStrokeCurrentColor($cleanSvgMarkup);
$svg = $this->getSvgMarkup($iconFilepath);
return $this->removeBlackFillAttributes($cleanSvgMarkup);
$this->removeExistingTitleElement($svg);
$this->removeBlackStrokeAttributes($svg);
$this->removeStrokeCurrentColor($svg);
return $this->removeBlackFillAttributes($svg);
}
private function findSvgFilepath(string $iconName): string
@@ -110,19 +111,19 @@ final class IconRuntime implements RuntimeExtensionInterface
return file_get_contents($filepath);
}
private function removeExistingTitleElement(string $svg): string
private function removeExistingTitleElement(string &$svg): void
{
return preg_replace('/<title>.*<\/title>/', '', $svg);
$svg = preg_replace('/<title>.*<\/title>/', '', $svg);
}
private function removeBlackStrokeAttributes(string $content): string
private function removeBlackStrokeAttributes(string &$svg): void
{
return preg_replace('/stroke(=|:)"?\s*(#0{6}|#000|rgb\(\s*0,\s*0,\s*0\s*\)|black)\s*"?/', '', $content);
$svg = preg_replace('/stroke(=|:)"?\s*(#0{6}|#000|rgb\(\s*0,\s*0,\s*0\s*\)|black)\s*"?/', '', $svg);
}
private function removeStrokeCurrentColor(string $content): string
private function removeStrokeCurrentColor(string &$svg): void
{
return \preg_replace('/stroke=(\'|")currentColor(\'|")/', '', $content);
$svg = \preg_replace('/stroke=(\'|")currentColor(\'|")/', '', $svg);
}
private function removeBlackFillAttributes(string $content): string