Merge pull request #4036 from dokuwiki/issue4033
[dokuwiki.git] / _test / vendor / symfony / css-selector / Parser / Shortcut / HashParser.php
blobfb07ee6cf86ffd4e87ab9d63837869ea23ca33cf
1 <?php
3 /*
4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\CssSelector\Parser\Shortcut;
14 use Symfony\Component\CssSelector\Node\ElementNode;
15 use Symfony\Component\CssSelector\Node\HashNode;
16 use Symfony\Component\CssSelector\Node\SelectorNode;
17 use Symfony\Component\CssSelector\Parser\ParserInterface;
19 /**
20 * CSS selector hash parser shortcut.
22 * This component is a port of the Python cssselect library,
23 * which is copyright Ian Bicking, @see https://github.com/SimonSapin/cssselect.
25 * @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
27 * @internal
29 class HashParser implements ParserInterface
31 /**
32 * {@inheritdoc}
34 public function parse(string $source): array
36 // Matches an optional namespace, optional element, and required id
37 // $source = 'test|input#ab6bd_field';
38 // $matches = array (size=4)
39 // 0 => string 'test|input#ab6bd_field' (length=22)
40 // 1 => string 'test' (length=4)
41 // 2 => string 'input' (length=5)
42 // 3 => string 'ab6bd_field' (length=11)
43 if (preg_match('/^(?:([a-z]++)\|)?+([\w-]++|\*)?+#([\w-]++)$/i', trim($source), $matches)) {
44 return [
45 new SelectorNode(new HashNode(new ElementNode($matches[1] ?: null, $matches[2] ?: null), $matches[3])),
49 return [];