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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
MultiByteStringManipulation.php
01 <?php
02
03 /**
04 * @package s9e\TextFormatter
05 * @copyright Copyright (c) 2010-2022 The s9e authors
06 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
07 */
08 namespace s9e\TextFormatter\Configurator\RendererGenerators\PHP\XPathConvertor\Convertors;
09
10 class MultiByteStringManipulation extends AbstractConvertor
11 {
12 /**
13 * {@inheritdoc}
14 */
15 public function getMatchers(): array
16 {
17 return [
18 'String:Substring' => 'substring \\( ((?&String)) , ((?&Attribute)|(?&Math)|(?&Number)) (?:, ((?&Attribute)|(?&Math)|(?&Number)))? \\)'
19 ];
20 }
21
22 /**
23 * Convert a substring() function call
24 *
25 * @param string $exprString
26 * @param string $exprPos
27 * @param string $exprLen
28 * @return string
29 */
30 public function parseSubstring($exprString, $exprPos, $exprLen = null)
31 {
32 // Try to fix negative lengths when possible
33 if (is_numeric($exprPos) && is_numeric($exprLen) && $exprPos < 1)
34 {
35 $exprLen += $exprPos - 1;
36 }
37
38 $args = [];
39 $args[] = $this->recurse($exprString);
40 $args[] = $this->convertPos($exprPos);
41 $args[] = (isset($exprLen)) ? $this->convertLen($exprLen) : 'null';
42 $args[] = "'utf-8'";
43
44 return 'mb_substr(' . implode(',', $args) . ')';
45 }
46
47 /**
48 * Convert the length expression of a substring() call
49 *
50 * @param string $expr
51 * @return string
52 */
53 protected function convertLen($expr)
54 {
55 // NOTE: negative values for the second argument do not produce the same result as
56 // specified in XPath if the argument is not a literal number
57 if (is_numeric($expr))
58 {
59 return (string) max(0, $expr);
60 }
61
62 return 'max(0,' . $this->recurse($expr) . ')';
63 }
64
65 /**
66 * Convert the position expression of a substring() call
67 *
68 * @param string $expr
69 * @return string
70 */
71 protected function convertPos($expr)
72 {
73 if (is_numeric($expr))
74 {
75 return (string) max(0, $expr - 1);
76 }
77
78 return 'max(0,' . $this->recurse($expr) . '-1)';
79 }
80 }