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

FoldArithmeticConstants.php

Zuletzt modifiziert: 02.04.2025, 15:04 - Dateigröße: 2.47 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\TemplateNormalizations;
009   
010  use s9e\TextFormatter\Configurator\Helpers\XPathHelper;
011  use s9e\TextFormatter\Utils\XPath;
012   
013  class FoldArithmeticConstants extends AbstractConstantFolding
014  {
015      /**
016      * {@inheritdoc}
017      */
018      protected function getOptimizationPasses()
019      {
020          // Regular expression matching a number
021          $n = '-?\\.[0-9]++|-?[0-9]++(?:\\.[0-9]++)?';
022   
023          return [
024              '(^[0-9\\s]*[-+][-+0-9\\s]+$)'                               => 'foldOperation',
025              '( \\+ 0(?= $| [-+\\)])|(?<![^\\(])0 \\+ )'                  => 'foldAdditiveIdentity',
026              '(^((?>' . $n . ' [-+] )*)(' . $n . ') div (' . $n . '))'    => 'foldDivision',
027              '(^((?>' . $n . ' [-+] )*)(' . $n . ') \\* (' . $n . '))'    => 'foldMultiplication',
028              '(\\( (?:' . $n . ') (?>(?>[-+*]|div) (?:' . $n . ') )+\\))' => 'foldSubExpression',
029              '((?<=[-+*\\(]|\\bdiv|^) \\( ([@$][-\\w]+|' . $n . ') \\) (?=[-+*\\)]|div|$))' => 'removeParentheses'
030          ];
031      }
032   
033      /**
034      * {@inheritdoc}
035      */
036      protected function evaluateExpression($expr)
037      {
038          $expr = XPathHelper::encodeStrings($expr);
039          $expr = parent::evaluateExpression($expr);
040          $expr = XPathHelper::decodeStrings($expr);
041   
042          return $expr;
043      }
044   
045      /**
046      * Remove "+ 0" additions
047      *
048      * @param  array  $m
049      * @return string
050      */
051      protected function foldAdditiveIdentity(array $m)
052      {
053          return '';
054      }
055   
056      /**
057      * Evaluate and return the result of a division
058      *
059      * @param  array  $m
060      * @return string
061      */
062      protected function foldDivision(array $m)
063      {
064          return $m[1] . XPath::export($m[2] / $m[3]);
065      }
066   
067      /**
068      * Evaluate and return the result of a multiplication
069      *
070      * @param  array  $m
071      * @return string
072      */
073      protected function foldMultiplication(array $m)
074      {
075          return $m[1] . XPath::export($m[2] * $m[3]);
076      }
077   
078      /**
079      * Evaluate and replace a constant operation
080      *
081      * @param  array  $m
082      * @return string
083      */
084      protected function foldOperation(array $m)
085      {
086          return XPath::export($this->xpath->evaluate($m[0]));
087      }
088   
089      /**
090      * Evaluate and return the result of a simple subexpression
091      *
092      * @param  array  $m
093      * @return string
094      */
095      protected function foldSubExpression(array $m)
096      {
097          return '(' . $this->evaluateExpression(trim(substr($m[0], 1, -1))) . ')';
098      }
099   
100      /**
101      * Remove the parentheses around an integer
102      *
103      * @param  array  $m
104      * @return string
105      */
106      protected function removeParentheses(array $m)
107      {
108          return ' ' . $m[1] . ' ';
109      }
110  }