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:
parent
b507fa43da
commit
e5453f0d46
@ -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
|
||||
|
@ -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}";
|
||||
|
Loading…
x
Reference in New Issue
Block a user