]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - vendor/wikimedia/css-sanitizer/src/Grammar/NonEmpty.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / vendor / wikimedia / css-sanitizer / src / Grammar / NonEmpty.php
diff --git a/vendor/wikimedia/css-sanitizer/src/Grammar/NonEmpty.php b/vendor/wikimedia/css-sanitizer/src/Grammar/NonEmpty.php
new file mode 100644 (file)
index 0000000..b8810b3
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+/**
+ * @file
+ * @license https://opensource.org/licenses/Apache-2.0 Apache-2.0
+ */
+
+namespace Wikimedia\CSS\Grammar;
+
+use Wikimedia\CSS\Objects\ComponentValueList;
+
+/**
+ * Matcher that requires its sub-Matcher has only non-empty matches ("!" multipier)
+ * @see https://www.w3.org/TR/2016/CR-css-values-3-20160929/#mult-req
+ */
+class NonEmpty extends Matcher {
+       /** @var Matcher */
+       protected $matcher;
+
+       /**
+        * @param Matcher $matcher
+        */
+       public function __construct( Matcher $matcher ) {
+               $this->matcher = $matcher;
+       }
+
+       protected function generateMatches( ComponentValueList $values, $start, array $options ) {
+               foreach ( $this->matcher->generateMatches( $values, $start, $options ) as $match ) {
+                       if ( $match->getLength() !== 0 ) {
+                               yield $this->makeMatch( $values, $start, $match->getNext(), $match );
+                       }
+               }
+       }
+}