diff options
author | Derek Allard <derek.allard@ellislab.com> | 2008-11-13 23:59:24 +0100 |
---|---|---|
committer | Derek Allard <derek.allard@ellislab.com> | 2008-11-13 23:59:24 +0100 |
commit | 2067d1a727e7eb5e5ffb40e967f3d1fc4c8a41b2 (patch) | |
tree | a95e01024205837e9580757350d04b233e82503f /system/libraries/Parser.php | |
parent | dd9f932556d3cd45a1d06cc478f40d06b7649a69 (diff) |
Changing EOL style to LF
Diffstat (limited to 'system/libraries/Parser.php')
-rw-r--r-- | system/libraries/Parser.php | 344 |
1 files changed, 172 insertions, 172 deletions
diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index e276a0d07..3d379b221 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -1,173 +1,173 @@ -<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
-/**
- * CodeIgniter
- *
- * An open source application development framework for PHP 4.3.2 or newer
- *
- * @package CodeIgniter
- * @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008, EllisLab, Inc.
- * @license http://codeigniter.com/user_guide/license.html
- * @link http://codeigniter.com
- * @since Version 1.0
- * @filesource
- */
-
-// ------------------------------------------------------------------------
-
-/**
- * Parser Class
- *
- * @package CodeIgniter
- * @subpackage Libraries
- * @category Parser
- * @author ExpressionEngine Dev Team
- * @link http://codeigniter.com/user_guide/libraries/parser.html
- */
-class CI_Parser {
-
- var $l_delim = '{';
- var $r_delim = '}';
- var $object;
-
- /**
- * Parse a template
- *
- * Parses pseudo-variables contained in the specified template,
- * replacing them with the data in the second param
- *
- * @access public
- * @param string
- * @param array
- * @param bool
- * @return string
- */
- function parse($template, $data, $return = FALSE)
- {
- $CI =& get_instance();
- $template = $CI->load->view($template, $data, TRUE);
-
- if ($template == '')
- {
- return FALSE;
- }
-
- foreach ($data as $key => $val)
- {
- if (is_array($val))
- {
- $template = $this->_parse_pair($key, $val, $template);
- }
- else
- {
- $template = $this->_parse_single($key, (string)$val, $template);
- }
- }
-
- if ($return == FALSE)
- {
- $CI->output->append_output($template);
- }
-
- return $template;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Set the left/right variable delimiters
- *
- * @access public
- * @param string
- * @param string
- * @return void
- */
- function set_delimiters($l = '{', $r = '}')
- {
- $this->l_delim = $l;
- $this->r_delim = $r;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Parse a single key/value
- *
- * @access private
- * @param string
- * @param string
- * @param string
- * @return string
- */
- function _parse_single($key, $val, $string)
- {
- return str_replace($this->l_delim.$key.$this->r_delim, $val, $string);
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Parse a tag pair
- *
- * Parses tag pairs: {some_tag} string... {/some_tag}
- *
- * @access private
- * @param string
- * @param array
- * @param string
- * @return string
- */
- function _parse_pair($variable, $data, $string)
- {
- if (FALSE === ($match = $this->_match_pair($string, $variable)))
- {
- return $string;
- }
-
- $str = '';
- foreach ($data as $row)
- {
- $temp = $match['1'];
- foreach ($row as $key => $val)
- {
- if ( ! is_array($val))
- {
- $temp = $this->_parse_single($key, $val, $temp);
- }
- else
- {
- $temp = $this->_parse_pair($key, $val, $temp);
- }
- }
-
- $str .= $temp;
- }
-
- return str_replace($match['0'], $str, $string);
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Matches a variable pair
- *
- * @access private
- * @param string
- * @param string
- * @return mixed
- */
- function _match_pair($string, $variable)
- {
- if ( ! preg_match("|".$this->l_delim . $variable . $this->r_delim."(.+?)".$this->l_delim . '/' . $variable . $this->r_delim."|s", $string, $match))
- {
- return FALSE;
- }
-
- return $match;
- }
-
-}
-// END Parser Class
-
-/* End of file Parser.php */
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); +/** + * CodeIgniter + * + * An open source application development framework for PHP 4.3.2 or newer + * + * @package CodeIgniter + * @author ExpressionEngine Dev Team + * @copyright Copyright (c) 2008, EllisLab, Inc. + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com + * @since Version 1.0 + * @filesource + */ + +// ------------------------------------------------------------------------ + +/** + * Parser Class + * + * @package CodeIgniter + * @subpackage Libraries + * @category Parser + * @author ExpressionEngine Dev Team + * @link http://codeigniter.com/user_guide/libraries/parser.html + */ +class CI_Parser { + + var $l_delim = '{'; + var $r_delim = '}'; + var $object; + + /** + * Parse a template + * + * Parses pseudo-variables contained in the specified template, + * replacing them with the data in the second param + * + * @access public + * @param string + * @param array + * @param bool + * @return string + */ + function parse($template, $data, $return = FALSE) + { + $CI =& get_instance(); + $template = $CI->load->view($template, $data, TRUE); + + if ($template == '') + { + return FALSE; + } + + foreach ($data as $key => $val) + { + if (is_array($val)) + { + $template = $this->_parse_pair($key, $val, $template); + } + else + { + $template = $this->_parse_single($key, (string)$val, $template); + } + } + + if ($return == FALSE) + { + $CI->output->append_output($template); + } + + return $template; + } + + // -------------------------------------------------------------------- + + /** + * Set the left/right variable delimiters + * + * @access public + * @param string + * @param string + * @return void + */ + function set_delimiters($l = '{', $r = '}') + { + $this->l_delim = $l; + $this->r_delim = $r; + } + + // -------------------------------------------------------------------- + + /** + * Parse a single key/value + * + * @access private + * @param string + * @param string + * @param string + * @return string + */ + function _parse_single($key, $val, $string) + { + return str_replace($this->l_delim.$key.$this->r_delim, $val, $string); + } + + // -------------------------------------------------------------------- + + /** + * Parse a tag pair + * + * Parses tag pairs: {some_tag} string... {/some_tag} + * + * @access private + * @param string + * @param array + * @param string + * @return string + */ + function _parse_pair($variable, $data, $string) + { + if (FALSE === ($match = $this->_match_pair($string, $variable))) + { + return $string; + } + + $str = ''; + foreach ($data as $row) + { + $temp = $match['1']; + foreach ($row as $key => $val) + { + if ( ! is_array($val)) + { + $temp = $this->_parse_single($key, $val, $temp); + } + else + { + $temp = $this->_parse_pair($key, $val, $temp); + } + } + + $str .= $temp; + } + + return str_replace($match['0'], $str, $string); + } + + // -------------------------------------------------------------------- + + /** + * Matches a variable pair + * + * @access private + * @param string + * @param string + * @return mixed + */ + function _match_pair($string, $variable) + { + if ( ! preg_match("|".$this->l_delim . $variable . $this->r_delim."(.+?)".$this->l_delim . '/' . $variable . $this->r_delim."|s", $string, $match)) + { + return FALSE; + } + + return $match; + } + +} +// END Parser Class + +/* End of file Parser.php */ /* Location: ./system/libraries/Parser.php */
\ No newline at end of file |