示例#1
0
 /**
  * Compiles the current text block between two XML tags, creating a
  * complete Opt_Xml_Text node. It looks for the expressions in the
  * curly brackets, extracts them and packs as separate nodes.
  *
  * Moreover, it replaces the entities with the corresponding characters.
  *
  * @internal
  * @param Opt_Xml_Node $current The current XML node.
  * @param String $text The text block between two tags.
  * @param Boolean $noExpressions=false If true, do not look for the expressions.
  * @return Opt_Xml_Node The current XML node.
  */
 protected function _treeTextCompile($current, $text, $noExpressions = false)
 {
     // Yes, we parse entities, but the text itself should not contain
     // any special characters.
     if (strcspn($text, '<>') != strlen($text)) {
         throw new Opt_XmlInvalidCharacter_Exception(htmlspecialchars($text));
     }
     if ($noExpressions) {
         $current = $this->_treeTextAppend($current, $this->_compiler->parseEntities($text));
     }
     preg_match_all($this->_rExpressionTag, $text, $result, PREG_SET_ORDER);
     $resultSize = sizeof($result);
     $offset = 0;
     for ($i = 0; $i < $resultSize; $i++) {
         $id = strpos($text, $result[$i][0], $offset);
         if ($id > $offset) {
             $current = $this->_treeTextAppend($current, $this->_compiler->parseEntities(substr($text, $offset, $id - $offset)));
         }
         $offset = $id + strlen($result[$i][0]);
         $current = $this->_treeTextAppend($current, new Opt_Xml_Expression($this->_compiler->parseEntities($result[$i][2])));
     }
     $i--;
     // Now the remaining content of the file
     if (strlen($text) > $offset) {
         $current = $this->_treeTextAppend($current, $this->_compiler->parseEntities(substr($text, $offset, strlen($text) - $offset)));
     }
     return $current;
 }