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

Breadcrumb

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

class Escaper

Same name in this branch
  1. 11.1.x vendor/symfony/yaml/Escaper.php \Symfony\Component\Yaml\Escaper

XPath escaper.

@author Konstantin Kudryashov <ever.zet@gmail.com>

Hierarchy

  • class \Behat\Mink\Selector\Xpath\Escaper

Expanded class hierarchy of Escaper

3 files declare their use of Escaper
NamedSelector.php in vendor/behat/mink/src/Selector/NamedSelector.php
SelectorsHandler.php in vendor/behat/mink/src/Selector/SelectorsHandler.php
Selenium2Driver.php in vendor/lullabot/mink-selenium2-driver/src/Selenium2Driver.php

File

vendor/behat/mink/src/Selector/Xpath/Escaper.php, line 18

Namespace

Behat\Mink\Selector\Xpath
View source
class Escaper {
    
    /**
     * Escapes the string as a XPath literal.
     *
     * @param string $s
     *
     * @return string
     */
    public function escapeLiteral(string $s) {
        if (false === strpos($s, "'")) {
            return sprintf("'%s'", $s);
        }
        if (false === strpos($s, '"')) {
            return sprintf('"%s"', $s);
        }
        $string = $s;
        $parts = array();
        while (true) {
            if (false !== ($pos = strpos($string, "'"))) {
                $parts[] = sprintf("'%s'", substr($string, 0, $pos));
                $parts[] = "\"'\"";
                $string = substr($string, $pos + 1);
            }
            else {
                $parts[] = "'{$string}'";
                break;
            }
        }
        return sprintf('concat(%s)', implode(',', $parts));
    }

}

Members

Title Sort descending Modifiers Object type Summary
Escaper::escapeLiteral public function Escapes the string as a XPath literal.

API Navigation

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