Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Standard.php

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

Standard

Namespace

PhpParser\PrettyPrinter

Code

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) . '\'';
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal