cvs: pear /Text_Wiki/Text/Wiki/BBCode Parse.php

From: Date: Sat, 16 Jul 2005 04:56:50 +0000
Subject: cvs: pear /Text_Wiki/Text/Wiki/BBCode Parse.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-33067@lists.php.net to get a copy of this message
toggg Sat Jul 16 00:56:50 2005 EDT Modified files: /pear/Text_Wiki/Text/Wiki/BBCode Parse.php Log: Headers + post synchronization transmits nesting depth http://cvs.php.net/diff.php/pear/Text_Wiki/Text/Wiki/BBCode/Parse.php?r1=1.1&r2=1.2&ty=u Index: pear/Text_Wiki/Text/Wiki/BBCode/Parse.php diff -u pear/Text_Wiki/Text/Wiki/BBCode/Parse.php:1.1 pear/Text_Wiki/Text/Wiki/BBCode/Parse.php:1.2 --- pear/Text_Wiki/Text/Wiki/BBCode/Parse.php:1.1 Tue Jul 12 09:19:31 2005 +++ pear/Text_Wiki/Text/Wiki/BBCode/Parse.php Sat Jul 16 00:56:46 2005 @@ -1,97 +1,85 @@ <?php +// vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: /** -* @version Exp $ -* -* BBCode: Parse redefinition to parse nested components -* -* @category Text -* -* @package Text_Wiki -* -* @author Bertrand Gugger <bertrand@toggg.com> -* -*/ -/** -* -* Baseline rule class for BBCode parser. -* -* @see Text_Wiki_Parse -* -* The parse() method enables the nesting of components -* by checking the done property (default true) -* -* A process() method needing to "rerun" has to set it to false -* -*/ + * BBCode: Parse redefinition to parse nested components + * + * PHP versions 4 and 5 + * + * @category Text + * @package Text_Wiki + * @author Bertrand Gugger <bertrand@toggg.com> + * @copyright 2005 bertrand Gugger + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version CVS: $Id: Parse.php,v 1.2 2005/07/16 04:56:46 toggg Exp $ + * @link http://pear.php.net/package/Text_Wiki + */ +/** + * Baseline rule class for BBCode parser. + * + * @see Text_Wiki_Parse + * + * The parse() method enables the nesting of components + * thru a custom method to synchronize "start" and "end" tags + * + * It also checks the done property (default true) + * A process() method needing to "rerun" has to set it to false + */ class Text_Wiki_Parse_BBCode extends Text_Wiki_Parse { - /** - * - * Flag indicating to the parse method to re-parse the source for nesting - * - * @access public - * - * @var boolean - * - */ + * Flag indicating to the parse method to re-parse the source for nesting + * + * @access public + * @var boolean + */ var $done = true; /** - * - * Flag indicating to the parse method to synchronize nested start and end tags - * by calling the custom method synchStartEnd() for each corresponding pair of them - * 'type'=>'start' or 'type'=>'end' are then mandatory for this rule's tokens - * - * @access public - * - * @var boolean - * - */ - var $synch = false; + * Flag indicating to the parse method to synchronize nested start and end tags + * by calling the custom method synchStartEnd() for each corresponding pair of them + * 'type'=>'start' or 'type'=>'end' are then mandatory for this rule's tokens + * The post synchronization function has the followolng interface: + * function synchStartEnd(&$statok, &$endtok, $level, $stapos, $endpos) + * @param &array $statok the param array of start token + * @param &array $endtok the param array of end token + * @param int $level nesting depth + * @param int $stapos the position behind start token in source + * @param int $endpos the position of end token in source (after tag's data) + * @return null or error + * + * @access private + * @var boolean + */ + var $_synch = false; /** - * - * Constructor for this parser rule. - * - * @access public - * - * @param object &$obj The calling "parent" Text_Wiki object. - * - */ - + * Constructor for this parser rule. + * + * @access public + * @param object &$obj The calling "parent" Text_Wiki object. + * + */ function Text_Wiki_Parse_BBCode(&$obj) { parent::Text_Wiki_Parse($obj); - $this->synch = method_exists($this, 'synchStartEnd'); + $this->_synch = method_exists($this, 'synchStartEnd'); } /** - * - * Abstract method to parse source text for matches. - * - * Repeats the parent parse method until done - * Nesting rules process() can set this flag to false for redo - * - * @access public - * - * @see Text_Wiki_Parse::parse() - * - */ -/* + * Abstract method to parse source text for matches. + * + * Repeats the parent parse method until done + * Nesting rules process() can set this flag to false for redo + * Calls the custom post synchronization if exists in the class + * + * @access public + * @see Text_Wiki_Parse::parse() + */ function parse() { - do { - $this->done = true; - parent::parse(); - } while (!$this->done); - } -*/ - function parse() - { - if ($this->synch) { + if ($this->_synch) { $loop = -1; do { $this->done = true; @@ -111,11 +99,13 @@ $statok[$lev++] = $tokno; continue; } - // we assume type is 'end' + if ($this->wiki->tokens[$tokno][1]['type'] != 'end') { + continue; + } $this->synchStartEnd( $this->wiki->tokens[array_pop($statok)][1], $this->wiki->tokens[$tokno][1], - array_pop($stapos), $newpos); + $lev, array_pop($stapos), $newpos); $pos = $newpos + strlen($find); $lev--; }

« previous php.pear.cvs (#33067) next »