4 * This file is part of the Mink package.
5 * (c) Konstantin Kudryashov <ever.zet@gmail.com>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
11 namespace Behat\Mink\Selector\Xpath;
16 * @author Konstantin Kudryashov <ever.zet@gmail.com>
21 * Escapes the string as a XPath literal.
27 public function escapeLiteral($s)
29 if (false === strpos($s, "'")) {
30 return sprintf("'%s'", $s);
33 if (false === strpos($s, '"')) {
34 return sprintf('"%s"', $s);
40 if (false !== $pos = strpos($string, "'")) {
41 $parts[] = sprintf("'%s'", substr($string, 0, $pos));
43 $string = substr($string, $pos + 1);
45 $parts[] = "'$string'";
50 return sprintf('concat(%s)', implode($parts, ','));