public static function Xpath::escapeXpathString in Views XML Backend 8
Escapes an XPath string.
Parameters
string $argument: The string to escape.
Return value
string The escaped string.
9 calls to Xpath::escapeXpathString()
- Date::__toString in src/
Plugin/ views/ argument/ Date.php - Generates an XPath argument string.
- DayDate::__toString in src/
Plugin/ views/ argument/ DayDate.php - Generates an XPath argument string.
- MonthDate::__toString in src/
Plugin/ views/ argument/ MonthDate.php - Generates an XPath argument string.
- Numeric::__toString in src/
Plugin/ views/ filter/ Numeric.php - Generates an XPath filter string.
- Standard::__toString in src/
Plugin/ views/ filter/ Standard.php - Generates an XPath filter string.
File
- src/
Xpath.php, line 24 - Contains \Drupal\views_xml_backend\Xpath.
Class
- Xpath
- Helper functions for handling XPath.
Namespace
Drupal\views_xml_backendCode
public static function escapeXpathString($argument) {
if (strpos($argument, "'") === FALSE) {
return "'" . $argument . "'";
}
if (strpos($argument, '"') === FALSE) {
return '"' . $argument . '"';
}
$string = $argument;
$parts = [];
// XPath doesn't provide a way to escape quotes in strings, so we break up
// the string and return a concat() function call.
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, ', '));
}