private function splitUnionParts($xpath)
    {
        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\0\x0B");

        $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\0\x0B", $i + 1);
            $startPosition = $i + 1;
        }

        return array($xpath); // The XPath expression is invalid
    }
private function splitUnionParts($xpath)
    {
        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\0\x0B");

        $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\0\x0B", $i + 1);
            $startPosition = $i + 1;
        }

        return array($xpath); // The XPath expression is invalid
    }
private function splitUnionParts ( $ xpath ) { 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\0\x0B" ) ; $ 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\0\x0B" , $ i + 1 ) ; $ startPosition = $ i + 1 ; } return array ( $ xpath ) ; // The XPath expression is invalid }
Splits the XPath into parts that are separated by the union operator.

@param string $xpath

@return string[]
Splits the XPath into parts that are separated by the union operator .