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

Breadcrumb

  1. Drupal Core 11.1.x

Escaper.php

Same filename in this branch
  1. 11.1.x vendor/twig/twig/src/Resources/escaper.php
  2. 11.1.x vendor/symfony/yaml/Escaper.php

Namespace

Behat\Mink\Selector\Xpath

File

vendor/behat/mink/src/Selector/Xpath/Escaper.php

View source
<?php


/*
 * This file is part of the Mink package.
 * (c) Konstantin Kudryashov <ever.zet@gmail.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace Behat\Mink\Selector\Xpath;


/**
 * XPath escaper.
 *
 * @author Konstantin Kudryashov <ever.zet@gmail.com>
 */
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));
    }

}

Classes

Title Deprecated Summary
Escaper XPath escaper.

API Navigation

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