[ Index ]

PHP Cross Reference of phpBB-3.2.8-deutsch

title

Body

[close]

/vendor/s9e/text-formatter/src/Utils/ -> XPath.php (source)

   1  <?php
   2  
   3  /*
   4  * @package   s9e\TextFormatter
   5  * @copyright Copyright (c) 2010-2019 The s9e Authors
   6  * @license   http://www.opensource.org/licenses/mit-license.php The MIT License
   7  */
   8  namespace s9e\TextFormatter\Utils;
   9  use InvalidArgumentException;
  10  abstract class XPath
  11  {
  12  	public static function export($value)
  13      {
  14          if (!\is_scalar($value))
  15              throw new InvalidArgumentException(__METHOD__ . '() cannot export non-scalar values');
  16          if (\is_int($value))
  17              return (string) $value;
  18          if (\is_float($value))
  19              return \preg_replace('(\\.?0+$)', '', \sprintf('%F', $value));
  20          return self::exportString((string) $value);
  21      }
  22  	protected static function exportString($str)
  23      {
  24          if (\strpos($str, "'") === \false)
  25              return "'" . $str . "'";
  26          if (\strpos($str, '"') === \false)
  27              return '"' . $str . '"';
  28          $toks = [];
  29          $c    = '"';
  30          $pos  = 0;
  31          while ($pos < \strlen($str))
  32          {
  33              $spn = \strcspn($str, $c, $pos);
  34              if ($spn)
  35              {
  36                  $toks[] = $c . \substr($str, $pos, $spn) . $c;
  37                  $pos   += $spn;
  38              }
  39              $c = ($c === '"') ? "'" : '"';
  40          }
  41          return 'concat(' . \implode(',', $toks) . ')';
  42      }
  43  }


Generated: Tue Apr 7 19:42:26 2020 Cross-referenced by PHPXref 0.7.1