Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

SingleByteStringFunctions.php

Zuletzt modifiziert: 02.04.2025, 15:04 - Dateigröße: 5.81 KiB


001  <?php
002   
003  /**
004  * @package   s9e\TextFormatter
005  * @copyright Copyright (c) 2010-2022 The s9e authors
006  * @license   http://www.opensource.org/licenses/mit-license.php The MIT License
007  */
008  namespace s9e\TextFormatter\Configurator\RendererGenerators\PHP\XPathConvertor\Convertors;
009   
010  class SingleByteStringFunctions extends AbstractConvertor
011  {
012      /**
013      * {@inheritdoc}
014      */
015      public function getMatchers(): array
016      {
017          $groups = 'Boolean:BooleanFunction:';
018   
019          return [
020              $groups . 'Contains'      => 'contains \\( ((?&String)) , ((?&String)) \\)',
021              $groups . 'EndsWith'      => 'ends-with \\( ((?&String)) , ((?&String)) \\)',
022              $groups . 'NotContains'   => 'not \\( contains \\( ((?&String)) , ((?&String)) \\) \\)',
023              $groups . 'NotEndsWith'   => 'not \\( ends-with \\( ((?&String)) , ((?&String)) \\) \\)',
024              $groups . 'NotStartsWith' => 'not \\( starts-with \\( ((?&String)) , ((?&String)) \\) \\)',
025              $groups . 'StartsWith'    => 'starts-with \\( ((?&String)) , ((?&String)) \\)',
026              'Number:StringLength'     => 'string-length \\( ((?&String))? \\)'
027          ];
028      }
029   
030      /**
031      * Convert a call to contains()
032      *
033      * @param  string $haystack Expression for the haystack part of the call
034      * @param  string $needle   Expression for the needle part of the call
035      * @return string
036      */
037      public function parseContains($haystack, $needle)
038      {
039          return $this->generateContains($haystack, $needle, true);
040      }
041   
042      /**
043      * Convert a call to ends-with()
044      *
045      * @param  string $string    Expression for the string part of the call
046      * @param  string $substring Expression for the substring part of the call
047      * @return string
048      */
049      public function parseEndsWith($string, $substring)
050      {
051          return $this->generateEndsWith($string, $substring, true);
052      }
053   
054      /**
055      * Convert a call to not(contains())
056      *
057      * @param  string $haystack Expression for the haystack part of the call
058      * @param  string $needle   Expression for the needle part of the call
059      * @return string
060      */
061      public function parseNotContains($haystack, $needle)
062      {
063          return $this->generateContains($haystack, $needle, false);
064      }
065   
066      /**
067      * Convert a call to not(ends-with())
068      *
069      * @param  string $string    Expression for the string part of the call
070      * @param  string $substring Expression for the substring part of the call
071      * @return string
072      */
073      public function parseNotEndsWith($string, $substring)
074      {
075          return $this->generateEndsWith($string, $substring, false);
076      }
077   
078      /**
079      * Convert a call to not(starts-with())
080      *
081      * @param  string $string    Expression for the string part of the call
082      * @param  string $substring Expression for the substring part of the call
083      * @return string
084      */
085      public function parseNotStartsWith($string, $substring)
086      {
087          return $this->generateStartsWith($string, $substring, false);
088      }
089   
090      /**
091      * Convert a call to starts-with()
092      *
093      * @param  string $string    Expression for the string part of the call
094      * @param  string $substring Expression for the substring part of the call
095      * @return string
096      */
097      public function parseStartsWith($string, $substring)
098      {
099          return $this->generateStartsWith($string, $substring, true);
100      }
101   
102      /**
103      * Convert a call to string-length()
104      *
105      * @param  string $expr
106      * @return string
107      */
108      public function parseStringLength($expr = '.')
109      {
110          return "preg_match_all('(.)su'," . $this->recurse($expr) . ')';
111      }
112   
113      /**
114      * Generate the code for a call to contains()
115      *
116      * @param  string $haystack Expression for the haystack part of the call
117      * @param  string $needle   Expression for the needle part of the call
118      * @param  bool   $bool     Return value for a positive match
119      * @return string
120      */
121      protected function generateContains($haystack, $needle, $bool)
122      {
123          $operator = ($bool) ? '!==' : '===';
124   
125          return '(strpos(' . $this->recurse($haystack) . ',' . $this->recurse($needle) . ')' . $operator . 'false)';
126      }
127   
128      /**
129      * Generate the code for a call to ends-with()
130      *
131      * @param  string $string    Expression for the string part of the call
132      * @param  string $substring Expression for the substring part of the call
133      * @param  bool   $bool      Return value for a positive match
134      * @return string
135      */
136      protected function generateEndsWith($string, $substring, $bool)
137      {
138          return (preg_match('(^(?:\'[^\']+\'|"[^"]+")$)D', $substring))
139               ? $this->generateEndsWithLiteral($string, $substring, $bool)
140               : $this->generateEndsWithExpression($string, $substring, $bool);
141      }
142   
143      /**
144      * Generate the code for a call to ends-with() where the second argument is a literal string
145      *
146      * @param  string $string    Expression for the string part of the call
147      * @param  string $substring Expression for a literal substring
148      * @param  bool   $bool      Return value for a positive match
149      * @return string
150      */
151      protected function generateEndsWithLiteral($string, $substring, $bool)
152      {
153          $operator = ($bool) ? '===' : '!==';
154   
155          return '(substr(' . $this->recurse($string) . ',-' . (strlen($substring) - 2) . ')' . $operator . $this->recurse($substring) . ')';
156      }
157   
158      /**
159      * Generate the code for a call to ends-with()
160      *
161      * @param  string $string    Expression for the string part of the call
162      * @param  string $substring Expression for the substring part of the call
163      * @param  bool   $bool      Return value for a positive match
164      * @return string
165      */
166      protected function generateEndsWithExpression($string, $substring, $bool)
167      {
168          $operator = ($bool) ? '' : '!';
169   
170          return $operator . "preg_match('('.preg_quote(" . $this->recurse($substring) . ").'$)D'," . $this->recurse($string) . ')';
171      }
172   
173      /**
174      * Generate the code for a call to starts-with()
175      *
176      * @param  string $string    Expression for the string part of the call
177      * @param  string $substring Expression for the substring part of the call
178      * @param  bool   $bool      Return value for a positive match
179      * @return string
180      */
181      protected function generateStartsWith($string, $substring, $bool)
182      {
183          $operator = ($bool) ? '===' : '!==';
184   
185          return '(strpos(' . $this->recurse($string) . ',' . $this->recurse($substring) . ')' . $operator . '0)';
186      }
187  }