You are here

class Escaper in Zircon Profile 8

Same name in this branch
  1. 8 vendor/symfony/yaml/Escaper.php \Symfony\Component\Yaml\Escaper
  2. 8 vendor/zendframework/zend-escaper/src/Escaper.php \Zend\Escaper\Escaper
  3. 8 vendor/behat/mink/src/Selector/Xpath/Escaper.php \Behat\Mink\Selector\Xpath\Escaper
Same name and namespace in other branches
  1. 8.0 vendor/behat/mink/src/Selector/Xpath/Escaper.php \Behat\Mink\Selector\Xpath\Escaper

XPath escaper.

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

Hierarchy

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

Expanded class hierarchy of Escaper

4 files declare their use of Escaper
EscaperTest.php in vendor/behat/mink/tests/Selector/Xpath/EscaperTest.php
NamedSelector.php in vendor/behat/mink/src/Selector/NamedSelector.php
NamedSelectorTest.php in vendor/behat/mink/tests/Selector/NamedSelectorTest.php
SelectorsHandler.php in vendor/behat/mink/src/Selector/SelectorsHandler.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($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

Namesort descending Modifiers Type Description Overrides
Escaper::escapeLiteral public function Escapes the string as a XPath literal.