mirror of
https://github.com/FreshRSS/FreshRSS.git
synced 2026-07-28 07:47:18 -04:00
CSSXPath 1.5.0 (#8642)
https://github.com/phpgt/CssXPath/releases/tag/v1.5.0
This commit is contained in:
committed by
GitHub
parent
71c26f5512
commit
37c8f1f466
54
lib/phpgt/cssxpath/src/XPathExpression.php
Normal file
54
lib/phpgt/cssxpath/src/XPathExpression.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Gt\CssXPath;
|
||||
|
||||
class XPathExpression {
|
||||
/** @var array<int, string> */
|
||||
private array $parts;
|
||||
private bool $hasElement = false;
|
||||
|
||||
public function __construct(string $prefix) {
|
||||
$this->parts = [$prefix];
|
||||
}
|
||||
|
||||
public function appendElement(string $element, bool $htmlMode):void {
|
||||
$this->parts[] = $htmlMode ? strtolower($element) : $element;
|
||||
$this->hasElement = true;
|
||||
}
|
||||
|
||||
public function ensureElement():void {
|
||||
if($this->hasElement) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->parts[] = "*";
|
||||
$this->hasElement = true;
|
||||
}
|
||||
|
||||
public function appendFragment(string $fragment):void {
|
||||
$this->parts[] = $fragment;
|
||||
}
|
||||
|
||||
public function markElementMissing():void {
|
||||
$this->hasElement = false;
|
||||
}
|
||||
|
||||
public function prependToLast(string $prefix):void {
|
||||
$index = count($this->parts) - 1;
|
||||
$this->parts[$index] = $prefix . $this->parts[$index];
|
||||
}
|
||||
|
||||
public function replaceInLast(string $search, string $replace):void {
|
||||
$index = count($this->parts) - 1;
|
||||
$this->parts[$index] = str_replace($search, $replace, $this->parts[$index]);
|
||||
}
|
||||
|
||||
public function lastPartEndsWith(string $suffix):bool {
|
||||
$index = count($this->parts) - 1;
|
||||
return substr($this->parts[$index], -strlen($suffix)) === $suffix;
|
||||
}
|
||||
|
||||
public function toString():string {
|
||||
return implode("", $this->parts);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user