cvs: pear /Text_Wiki/Text Wiki.php

From: Date: Sun, 05 Mar 2006 06:50:13 +0000
Subject: cvs: pear /Text_Wiki/Text Wiki.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-38914@lists.php.net to get a copy of this message
justinpatrin Sun Mar 5 06:50:13 2006 UTC Modified files: /pear/Text_Wiki/Text Wiki.php Log: Set $wiki->newRendering to use new experimental preg_replace_callback rendering method http://cvs.php.net/viewcvs.cgi/pear/Text_Wiki/Text/Wiki.php?r1=1.46&r2=1.47&diff_format=u Index: pear/Text_Wiki/Text/Wiki.php diff -u pear/Text_Wiki/Text/Wiki.php:1.46 pear/Text_Wiki/Text/Wiki.php:1.47 --- pear/Text_Wiki/Text/Wiki.php:1.46 Fri Mar 3 17:54:06 2006 +++ pear/Text_Wiki/Text/Wiki.php Sun Mar 5 06:50:13 2006 @@ -9,7 +9,7 @@ * @package Text_Wiki * @author Paul M. Jones <pmjones@php.net> * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 - * @version CVS: $Id: Wiki.php,v 1.46 2006/03/03 17:54:06 toggg Exp $ + * @version CVS: $Id: Wiki.php,v 1.47 2006/03/05 06:50:13 justinpatrin Exp $ * @link http://pear.php.net/package/Text_Wiki */ @@ -969,46 +969,52 @@ $this->loadRenderObj($format, $rule); } - // pass through the parsed source text character by character - $k = strlen($this->source); - for ($i = 0; $i < $k; $i++) { - - // the current character - $char = $this->source{$i}; - - // are alredy in a delimited section? - if ($in_delim) { - - // yes; are we ending the section? - if ($char == $this->delim) { - - // yes, get the replacement text for the delimited - // token number and unset the flag. - $key = (int)$key; - $rule = $this->tokens[$key][0]; - $opts = $this->tokens[$key][1]; - $output .= $this->renderObj[$rule]->token($opts); - $in_delim = false; + if (isset($this->newRendering)) { + $output = preg_replace_callback('/'.$this->delim.'(\d+)'.$this->delim.'/', + array(&$this, '_renderToken'), + $this->source); + } else { + // pass through the parsed source text character by character + $k = strlen($this->source); + for ($i = 0; $i < $k; $i++) { - } else { + // the current character + $char = $this->source{$i}; - // no, add to the dlimited token key number - $key .= $char; + // are alredy in a delimited section? + if ($in_delim) { - } + // yes; are we ending the section? + if ($char == $this->delim) { - } else { + // yes, get the replacement text for the delimited + // token number and unset the flag. + $key = (int)$key; + $rule = $this->tokens[$key][0]; + $opts = $this->tokens[$key][1]; + $output .= $this->renderObj[$rule]->token($opts); + $in_delim = false; + + } else { + + // no, add to the dlimited token key number + $key .= $char; + + } - // not currently in a delimited section. - // are we starting into a delimited section? - if ($char == $this->delim) { - // yes, reset the previous key and - // set the flag. - $key = ''; - $in_delim = true; } else { - // no, add to the output as-is - $output .= $char; + + // not currently in a delimited section. + // are we starting into a delimited section? + if ($char == $this->delim) { + // yes, reset the previous key and + // set the flag. + $key = ''; + $in_delim = true; + } else { + // no, add to the output as-is + $output .= $char; + } } } } @@ -1022,6 +1028,17 @@ return $output; } + /** + * Renders a token, for use only as an internal callback + * + * @param array Matches from preg_rpelace_callback, [1] is the token number + * @return string The rendered text for the token + * @access private + */ + function _renderToken($matches) { + return $this->renderObj[$this->tokens[$matches[1]][0]]->token($this->tokens[$matches[1]][1]); + } + /** *

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