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 class PPDStackElement
{
27 * @var string Opening character (\n for heading)
32 * @var string Matching closing character
37 * @var string Saved prefix that may affect later processing,
38 * e.g. to differentiate `-{{{{` and `{{{{` after later seeing `}}}`.
40 public $savedPrefix = '';
43 * @var int Number of opening characters found (number of "=" for heading)
48 * @var PPDPart[] Array of PPDPart objects describing pipe-separated parts.
53 * @var bool True if the open char appeared at the start of the input line.
54 * Not set for headings.
58 public $partClass = PPDPart
::class;
60 public function __construct( $data = [] ) {
61 $class = $this->partClass
;
62 $this->parts
= [ new $class ];
64 foreach ( $data as $name => $value ) {
65 $this->$name = $value;
69 public function &getAccum() {
70 return $this->parts
[count( $this->parts
) - 1]->out
;
73 public function addPart( $s = '' ) {
74 $class = $this->partClass
;
75 $this->parts
[] = new $class( $s );
81 public function getCurrentPart() {
82 return $this->parts
[count( $this->parts
) - 1];
88 public function getFlags() {
89 $partCount = count( $this->parts
);
90 $findPipe = $this->open
!= "\n" && $this->open
!= '[';
92 'findPipe' => $findPipe,
93 'findEquals' => $findPipe && $partCount > 1 && !isset( $this->parts
[$partCount - 1]->eqpos
),
94 'inHeading' => $this->open
== "\n",
99 * Get the output string that would result if the close is not found.
101 * @param bool|int $openingCount
104 public function breakSyntax( $openingCount = false ) {
105 if ( $this->open
== "\n" ) {
106 $s = $this->savedPrefix
. $this->parts
[0]->out
;
108 if ( $openingCount === false ) {
109 $openingCount = $this->count
;
111 $s = substr( $this->open
, 0, -1 );
113 substr( $this->open
, -1 ),
114 $openingCount - strlen( $s )
116 $s = $this->savedPrefix
. $s;
118 foreach ( $this->parts
as $part ) {