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.
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.
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
25 * @property int $startPos
27 class PPDStackElement
{
29 * @var string Opening character (\n for heading)
34 * @var string Matching closing character
39 * @var string Saved prefix that may affect later processing,
40 * e.g. to differentiate `-{{{{` and `{{{{` after later seeing `}}}`.
42 public $savedPrefix = '';
45 * @var int Number of opening characters found (number of "=" for heading)
50 * @var PPDPart[] Array of PPDPart objects describing pipe-separated parts.
55 * @var bool True if the open char appeared at the start of the input line.
56 * Not set for headings.
60 public $partClass = PPDPart
::class;
62 public function __construct( $data = [] ) {
63 $class = $this->partClass
;
64 $this->parts
= [ new $class ];
66 foreach ( $data as $name => $value ) {
67 $this->$name = $value;
71 public function &getAccum() {
72 return $this->parts
[count( $this->parts
) - 1]->out
;
75 public function addPart( $s = '' ) {
76 $class = $this->partClass
;
77 $this->parts
[] = new $class( $s );
83 public function getCurrentPart() {
84 return $this->parts
[count( $this->parts
) - 1];
90 public function getFlags() {
91 $partCount = count( $this->parts
);
92 $findPipe = $this->open
!= "\n" && $this->open
!= '[';
94 'findPipe' => $findPipe,
95 'findEquals' => $findPipe && $partCount > 1 && !isset( $this->parts
[$partCount - 1]->eqpos
),
96 'inHeading' => $this->open
== "\n",
101 * Get the output string that would result if the close is not found.
103 * @param bool|int $openingCount
106 public function breakSyntax( $openingCount = false ) {
107 if ( $this->open
== "\n" ) {
108 $s = $this->savedPrefix
. $this->parts
[0]->out
;
110 if ( $openingCount === false ) {
111 $openingCount = $this->count
;
113 $s = substr( $this->open
, 0, -1 );
115 substr( $this->open
, -1 ),
116 $openingCount - strlen( $s )
118 $s = $this->savedPrefix
. $s;
120 foreach ( $this->parts
as $part ) {