1
0
mirror of https://github.com/danog/PHP-Parser.git synced 2025-01-22 05:41:23 +01:00

Extract pSingleQuotedString as an extension point

And add some more string formatting tests.
This commit is contained in:
Nikita Popov 2017-12-01 18:31:21 +01:00
parent b507fa43da
commit e5453f0d46
2 changed files with 13 additions and 5 deletions

View File

@ -110,7 +110,7 @@ class Standard extends PrettyPrinterAbstract
}
/* break missing intentionally */
case Scalar\String_::KIND_SINGLE_QUOTED:
return '\'' . addcslashes($node->value, '\'\\') . '\'';
return $this->pSingleQuotedString($node->value);
case Scalar\String_::KIND_HEREDOC:
$label = $node->getAttribute('docLabel');
if ($label && !$this->containsEndLabel($node->value, $label)) {
@ -875,6 +875,10 @@ class Standard extends PrettyPrinterAbstract
return $return;
}
protected function pSingleQuotedString(string $string) {
return '\'' . addcslashes($string, '\'\\') . '\'';
}
protected function escapeString($string, $quote) {
if (null === $quote) {
// For doc strings, don't escape newlines

View File

@ -44,11 +44,13 @@ FALSE;
'a';
'a
b';
"a";
"a\nb";
'a\'b';
'a\b';
'a\\';
// strings (double quoted)
"a";
"a\nb";
"a'b";
"a\b";
"$a";
@ -119,10 +121,12 @@ FALSE;
'a';
'a
b';
'a\'b';
'a\\b';
'a\\';
// strings (double quoted)
"a";
"a\nb";
'a\'b';
// strings (double quoted)
"a'b";
"a\\b";
"{$a}";