Merge "Make generatePhpCharToUpperMappings.php a proper maintenance script"
[lhc/web/wiklou.git] / includes / parser / PPDStackElement_Hash.php
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 * @ingroup Parser
20 */
21
22 /**
23 * @ingroup Parser
24 */
25 // phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps
26 class PPDStackElement_Hash extends PPDStackElement {
27
28 public function __construct( $data = [] ) {
29 $this->partClass = PPDPart_Hash::class;
30 parent::__construct( $data );
31 }
32
33 /**
34 * Get the accumulator that would result if the close is not found.
35 *
36 * @param int|bool $openingCount
37 * @return array
38 */
39 public function breakSyntax( $openingCount = false ) {
40 if ( $this->open == "\n" ) {
41 $accum = array_merge( [ $this->savedPrefix ], $this->parts[0]->out );
42 } else {
43 if ( $openingCount === false ) {
44 $openingCount = $this->count;
45 }
46 $s = substr( $this->open, 0, -1 );
47 $s .= str_repeat(
48 substr( $this->open, -1 ),
49 $openingCount - strlen( $s )
50 );
51 $accum = [ $this->savedPrefix . $s ];
52 $lastIndex = 0;
53 $first = true;
54 foreach ( $this->parts as $part ) {
55 if ( $first ) {
56 $first = false;
57 } elseif ( is_string( $accum[$lastIndex] ) ) {
58 $accum[$lastIndex] .= '|';
59 } else {
60 $accum[++$lastIndex] = '|';
61 }
62 foreach ( $part->out as $node ) {
63 if ( is_string( $node ) && is_string( $accum[$lastIndex] ) ) {
64 $accum[$lastIndex] .= $node;
65 } else {
66 $accum[++$lastIndex] = $node;
67 }
68 }
69 }
70 }
71 return $accum;
72 }
73 }