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

Breadcrumb

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

function Manipulator::splitUnionParts

Splits the XPath into parts that are separated by the union operator.

Parameters

string $xpath:

Return value

string[]

1 call to Manipulator::splitUnionParts()
Manipulator::prepend in vendor/behat/mink/src/Selector/Xpath/Manipulator.php
Prepends the XPath prefix to the given XPath.

File

vendor/behat/mink/src/Selector/Xpath/Manipulator.php, line 77

Class

Manipulator
XPath manipulation utility.

Namespace

Behat\Mink\Selector\Xpath

Code

private function splitUnionParts(string $xpath) : array {
    if (false === strpos($xpath, '|')) {
        return array(
            $xpath,
        );
        // If there is no pipe in the string, we know for sure that there is no union
    }
    $xpathLen = strlen($xpath);
    $openedBrackets = 0;
    // Consume whitespaces chars at the beginning of the string (this is the list of chars removed by trim() by default)
    $startPosition = strspn($xpath, " \t\n\r\x00\v");
    $unionParts = array();
    for ($i = $startPosition; $i <= $xpathLen; ++$i) {
        // Consume all chars until we reach a quote, a bracket or a pipe
        $i += strcspn($xpath, '"\'[]|', $i);
        if ($i < $xpathLen) {
            switch ($xpath[$i]) {
                case '"':
                case "'":
                    // Move to the end of the string literal
                    if (false === ($i = strpos($xpath, $xpath[$i], $i + 1))) {
                        return array(
                            $xpath,
                        );
                        // The XPath expression is invalid, don't split it
                    }
                    continue 2;
                case '[':
                    ++$openedBrackets;
                    continue 2;
                case ']':
                    --$openedBrackets;
                    continue 2;
            }
        }
        if ($openedBrackets) {
            continue;
        }
        $unionParts[] = substr($xpath, $startPosition, $i - $startPosition);
        if ($i === $xpathLen) {
            return $unionParts;
        }
        // Consume any whitespace chars after the pipe
        $i += strspn($xpath, " \t\n\r\x00\v", $i + 1);
        $startPosition = $i + 1;
    }
    return array(
        $xpath,
    );
    // The XPath expression is invalid
}

API Navigation

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