Re: Simple math request
messju mohr <[email protected]>
| Newsgroups | gmane.comp.php.smarty.devel |
|---|---|
| Message-ID | <[email protected]> |
On Thu, Apr 15, 2004 at 12:09:21PM +0200, messju mohr wrote:
> On Tue, Apr 06, 2004 at 02:33:16PM +0400, Konstantin A. Pelepelin wrote:
> > Hi!
> >
> > {$var-5} works, but {5-$var} or {-$var) doesn't.
> > {assign var='var2' value=$var-5} works, but value=5-$var or value=-$var
> > doesn't (value=-$var can accidentally work because of string
> > interpretation).
> >
> > Is it possible to implement at least in parameters?
hmm,
I have this diff against Smarty_Compiler.class.php
Index: libs/Smarty_Compiler.class.php
===================================================================
RCS file: /repository/smarty/libs/Smarty_Compiler.class.php,v
retrieving revision 1.320
diff -u -r1.320 Smarty_Compiler.class.php
--- libs/Smarty_Compiler.class.php 16 Apr 2004 10:31:43 -0000 1.320
+++ libs/Smarty_Compiler.class.php 16 Apr 2004 18:47:38 -0000
@@ -115,7 +115,7 @@
$this->_dvar_math_var_regexp = '[\$\w\.\+\-\*\/\%\d\>\[\]]';
$this->_dvar_guts_regexp = '\w+(?:' . $this->_var_bracket_regexp
. ')*(?:\.\$?\w+(?:' . $this->_var_bracket_regexp . ')*)*(?:' . $this->_dvar_math_regexp . '(?:' . $this->_num_const_regexp . '|' . $this->_dvar_math_var_regexp . ')*)?';
- $this->_dvar_regexp = '\$' . $this->_dvar_guts_regexp;
+ $this->_dvar_regexp = '(?:\$\w|[-+.0-9])' . $this->_dvar_guts_regexp;
// matches config vars:
// #foo#
I only tested it superficially. I'm not sure if it interferes with any
current constructs badly. If somebody is interested, please test and
give feedback.
greetings
messju
> that'd be nice. unfortunately _parse_var() is an ugly kludge (IMHO -
> at least the simple-math related parts are, if not the whole
> thing). It wouldn't be easy to add what you request but it would be a
> good addition and raise consistency.
>
> greetings
> messju
>
>
> > WBR,
> > Konstantin A. Pelepelin
>
> --
> Smarty Development Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
--
Smarty Development Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php