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

XPath.php

Zuletzt modifiziert: 02.04.2025, 15:03 - Dateigröße: 2.32 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\Utils;
009   
010  use InvalidArgumentException;
011   
012  abstract class XPath
013  {
014      /**
015      * Export a literal as an XPath expression
016      *
017      * @param  mixed  $value Literal, e.g. "foo"
018      * @return string        XPath expression, e.g. "'foo'"
019      */
020      public static function export($value)
021      {
022          $callback = get_called_class() . '::export' . ucfirst(gettype($value));
023          if (!is_callable($callback))
024          {
025              throw new InvalidArgumentException(__METHOD__ . '() cannot export non-scalar values');
026          }
027   
028          return $callback($value);
029      }
030   
031      /**
032      * Export given boolean value
033      *
034      * @param  bool   $value
035      * @return string
036      */
037      protected static function exportBoolean(bool $value): string
038      {
039          return ($value) ? 'true()' : 'false()';
040      }
041   
042      /**
043      * Export given float value
044      *
045      * @param  float  $value
046      * @return string
047      */
048      protected static function exportDouble(float $value): string
049      {
050          if (!is_finite($value))
051          {
052              throw new InvalidArgumentException(__METHOD__ . '() cannot export irrational numbers');
053          }
054   
055          // Avoid locale issues by using sprintf()
056          return preg_replace('(\\.?0+$)', '', sprintf('%F', $value));
057      }
058   
059      /**
060      * Export given integer value
061      *
062      * @param  integer $value
063      * @return string
064      */
065      protected static function exportInteger(int $value): string
066      {
067          return (string) $value;
068      }
069   
070      /**
071      * Export a string as an XPath expression
072      *
073      * @param  string $str Literal, e.g. "foo"
074      * @return string      XPath expression, e.g. "'foo'"
075      */
076      protected static function exportString(string $str): string
077      {
078          // foo becomes 'foo'
079          if (strpos($str, "'") === false)
080          {
081              return "'" . $str . "'";
082          }
083   
084          // d'oh becomes "d'oh"
085          if (strpos($str, '"') === false)
086          {
087              return '"' . $str . '"';
088          }
089   
090          // This string contains both ' and ". XPath 1.0 doesn't have a mechanism to escape quotes,
091          // so we have to get creative and use concat() to join chunks in single quotes and chunks
092          // in double quotes
093          $toks = [];
094          $c    = '"';
095          $pos  = 0;
096          while ($pos < strlen($str))
097          {
098              $spn = strcspn($str, $c, $pos);
099              if ($spn)
100              {
101                  $toks[] = $c . substr($str, $pos, $spn) . $c;
102                  $pos   += $spn;
103              }
104              $c = ($c === '"') ? "'" : '"';
105          }
106   
107          return 'concat(' . implode(',', $toks) . ')';
108      }
109  }