[ Index ]
 

Code source de Horde 3.1.3

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/Text/ -> reST.php (source)

   1  <?php
   2  /**
   3   * The Text_reST:: class represents a parse node of a reStructuredText
   4   * document and provides an API for parsing reStructuredText documents.
   5   *
   6   * $Horde: framework/Text_reST/reST.php,v 1.5.10.7 2006/01/01 21:28:38 jan Exp $
   7   *
   8   * Copyright 2003-2006 Jason M. Felice <jfelice@cronosys.com>
   9   *
  10   * See the enclosed file COPYING for license information (LGPL). If you did not
  11   * receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  12   *
  13   * @author  Jason M. Felice <jfelice@cronosys.com>
  14   * @package Text_reST
  15   */
  16  class Text_reST {
  17  
  18      /**
  19       * The parse node type.
  20       *
  21       * @access private
  22       * @var string
  23       */
  24      var $_type;
  25  
  26      /**
  27       * An array of the parse node's children.
  28       *
  29       * @access private
  30       * @var string
  31       */
  32      var $_children = array();
  33  
  34      /**
  35       * A hash of parse node properties.
  36       *
  37       * @access private
  38       * @var array
  39       */
  40      var $_properties = array();
  41  
  42      /**
  43       * Constructor.
  44       *
  45       * @param string $type  This is the node type.  The default is 'Document'.
  46       */
  47      function Text_reST($type = 'Document')
  48      {
  49          $this->_type = $type;
  50      }
  51  
  52      /**
  53       * Appends a child parse node to this parse node.
  54       *
  55       * @param string|Text_reST &$child  This is the string or object child
  56       *                                  to append to this parse node.
  57       */
  58      function appendChild(&$child)
  59      {
  60          $n = count($this->_children);
  61          if (is_string($child) && $n > 0 && is_string($this->_children[$n - 1])) {
  62              $this->_children[$n - 1] .= $child;
  63          } elseif (is_string($child)) {
  64              $this->_children[] = $child;
  65          } else {
  66              $this->_children[] = &$child;
  67          }
  68      }
  69  
  70      /**
  71       * Sets the value of a parse node property.
  72       *
  73       * @param string $name   The property's name.
  74       * @param string $value  The property's value.
  75       */
  76      function setProperty($name, $value)
  77      {
  78          $this->_properties[$name] = $value;
  79      }
  80  
  81      /**
  82       * Retrieves the value of a parse node property.
  83       *
  84       * @param string $name  The property's name.
  85       *
  86       * @return string  The property's value.
  87       */
  88      function getProperty($name)
  89      {
  90          if (!array_key_exists($name, $this->_properties)) {
  91              return null;
  92          }
  93          return $this->_properties[$name];
  94      }
  95  
  96      /**
  97       * Dumps this parse node and its children.
  98       * This method is for debugging purposes.
  99       *
 100       * @param integer $level  This is the indent level of this parse node.
 101       */
 102      function dump($level = 0)
 103      {
 104          for ($i = 0; $i < $level; $i++) {
 105              echo '  ';
 106          }
 107          echo $this->_type, '::';
 108          ksort($this->_properties);
 109          foreach ($this->_properties as $name => $value) {
 110              echo ' ', $name, '="', preg_replace('/["\\\\]/', '\\$1', $value),
 111                  '"';
 112          }
 113          echo "\n";
 114          foreach ($this->_children as $child) {
 115              if (is_string($child)) {
 116                  for ($i = 0; $i < ($level + 1); $i++) {
 117                      echo '  ';
 118                  }
 119                  echo '"', preg_replace('/["\\\\]/', '\\$1', $child), "\"\n";
 120              } else {
 121                  $child->dump($level + 1);
 122              }
 123          }
 124      }
 125  
 126      /**
 127       * Parses a reStructuredText document.
 128       *
 129       * @static
 130       *
 131       * @param string $text  This is the text of the document we want to parse.
 132       *
 133       * @return Text_reST  The parsed document or PEAR_Error on failure.
 134       */
 135      function &parse($text)
 136      {
 137          require_once dirname(__FILE__) . '/reST/Parser.php';
 138          $parser = &new Text_reST_Parser();
 139          return $parser->parse($text);
 140      }
 141  
 142  }


Généré le : Sun Feb 25 18:01:28 2007 par Balluche grâce à PHPXref 0.7