You are here

public static function Translator::getXpathLiteral in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony/css-selector/XPath/Translator.php \Symfony\Component\CssSelector\XPath\Translator::getXpathLiteral()

Parameters

string $element:

Return value

string

13 calls to Translator::getXpathLiteral()
AttributeMatchingExtension::translateDashMatch in vendor/symfony/css-selector/XPath/Extension/AttributeMatchingExtension.php
AttributeMatchingExtension::translateDifferent in vendor/symfony/css-selector/XPath/Extension/AttributeMatchingExtension.php
AttributeMatchingExtension::translateEquals in vendor/symfony/css-selector/XPath/Extension/AttributeMatchingExtension.php
AttributeMatchingExtension::translateIncludes in vendor/symfony/css-selector/XPath/Extension/AttributeMatchingExtension.php
AttributeMatchingExtension::translatePrefixMatch in vendor/symfony/css-selector/XPath/Extension/AttributeMatchingExtension.php

... See full list

File

vendor/symfony/css-selector/XPath/Translator.php, line 92

Class

Translator
XPath expression translator interface.

Namespace

Symfony\Component\CssSelector\XPath

Code

public static function getXpathLiteral($element) {
  if (false === strpos($element, "'")) {
    return "'" . $element . "'";
  }
  if (false === strpos($element, '"')) {
    return '"' . $element . '"';
  }
  $string = $element;
  $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, ', '));
}