function Standard::pSingleQuotedString
1 call to Standard::pSingleQuotedString()
- Standard::pScalar_String in vendor/
nikic/ php-parser/ lib/ PhpParser/ PrettyPrinter/ Standard.php
File
-
vendor/
nikic/ php-parser/ lib/ PhpParser/ PrettyPrinter/ Standard.php, line 1064
Class
Namespace
PhpParser\PrettyPrinterCode
protected function pSingleQuotedString(string $string) : string {
// It is idiomatic to only escape backslashes when necessary, i.e. when followed by ', \ or
// the end of the string ('Foo\Bar' instead of 'Foo\\Bar'). However, we also don't want to
// produce an odd number of backslashes, so '\\\\a' should not get rendered as '\\\a', even
// though that would be legal.
$regex = '/\'|\\\\(?=[\'\\\\]|$)|(?<=\\\\)\\\\/';
return '\'' . preg_replace($regex, '\\\\$0', $string) . '\'';
}