You are here

public function Escaper::escapeLiteral in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/behat/mink/src/Selector/Xpath/Escaper.php \Behat\Mink\Selector\Xpath\Escaper::escapeLiteral()

Escapes the string as a XPath literal.

Parameters

string $s:

Return value

string

File

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

Class

Escaper
XPath escaper.

Namespace

Behat\Mink\Selector\Xpath

Code

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