← All changes
|
vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/FormulaParser.php
+482
-490
3.1.2
→
3.0.10
View file →
| @@ -1,33 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | - | |
| 3 | -/* | |
| 4 | -PARTLY BASED ON: | |
| 5 | - Copyright (c) 2007 E. W. Bachtal, Inc. | |
| 6 | - | |
| 7 | - Permission is hereby granted, free of charge, to any person obtaining a copy of this software | |
| 8 | - and associated documentation files (the "Software"), to deal in the Software without restriction, | |
| 9 | - including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
| 10 | - and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, | |
| 11 | - subject to the following conditions: | |
| 12 | - | |
| 13 | - The above copyright notice and this permission notice shall be included in all copies or substantial | |
| 14 | - portions of the Software. | |
| 15 | - | |
| 16 | - The software is provided "as is", without warranty of any kind, express or implied, including but not | |
| 17 | - limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In | |
| 18 | - no event shall the authors or copyright holders be liable for any claim, damages or other liability, | |
| 19 | - whether in an action of contract, tort or otherwise, arising from, out of or in connection with the | |
| 20 | - software or the use or other dealings in the software. | |
| 21 | - | |
| 22 | - http://ewbi.blogs.com/develops/2007/03/excel_formula_p.html | |
| 23 | - http://ewbi.blogs.com/develops/2004/12/excel_formula_p.html | |
| 24 | -*/ | |
| 25 | - | |
| 26 | 2 | /** |
| 27 | - * PHPExcel_Calculation_FormulaParser | |
| 3 | + * PHPExcel | |
| 28 | 4 | * |
| 29 | - * Copyright (c) 2006 - 2015 PHPExcel | |
| 5 | + * Copyright (c) 2006 - 2014 PHPExcel | |
| 30 | 6 | * |
| 31 | 7 | * This library is free software; you can redistribute it and/or |
| 32 | 8 | * modify it under the terms of the GNU Lesser General Public |
| 33 | 9 | * License as published by the Free Software Foundation; either |
| @@ -43,65 +19,94 @@ | ||
| 43 | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 44 | 20 | * |
| 45 | 21 | * @category PHPExcel |
| 46 | 22 | * @package PHPExcel_Calculation |
| 47 | - * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel) | |
| 48 | - * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL | |
| 23 | + * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) | |
| 24 | + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL | |
| 49 | 25 | * @version ##VERSION##, ##DATE## |
| 50 | 26 | */ |
| 51 | 27 | |
| 52 | 28 | |
| 53 | -class PHPExcel_Calculation_FormulaParser | |
| 54 | -{ | |
| 55 | - /* Character constants */ | |
| 56 | - const QUOTE_DOUBLE = '"'; | |
| 57 | - const QUOTE_SINGLE = '\''; | |
| 58 | - const BRACKET_CLOSE = ']'; | |
| 59 | - const BRACKET_OPEN = '['; | |
| 60 | - const BRACE_OPEN = '{'; | |
| 61 | - const BRACE_CLOSE = '}'; | |
| 62 | - const PAREN_OPEN = '('; | |
| 63 | - const PAREN_CLOSE = ')'; | |
| 64 | - const SEMICOLON = ';'; | |
| 65 | - const WHITESPACE = ' '; | |
| 66 | - const COMMA = ','; | |
| 67 | - const ERROR_START = '#'; | |
| 29 | +/* | |
| 30 | +PARTLY BASED ON: | |
| 31 | + Copyright (c) 2007 E. W. Bachtal, Inc. | |
| 68 | 32 | |
| 69 | - const OPERATORS_SN = "+-"; | |
| 70 | - const OPERATORS_INFIX = "+-*/^&=><"; | |
| 71 | - const OPERATORS_POSTFIX = "%"; | |
| 33 | + Permission is hereby granted, free of charge, to any person obtaining a copy of this software | |
| 34 | + and associated documentation files (the "Software"), to deal in the Software without restriction, | |
| 35 | + including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
| 36 | + and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, | |
| 37 | + subject to the following conditions: | |
| 72 | 38 | |
| 73 | - /** | |
| 74 | - * Formula | |
| 75 | - * | |
| 76 | - * @var string | |
| 77 | - */ | |
| 78 | - private $formula; | |
| 39 | + The above copyright notice and this permission notice shall be included in all copies or substantial | |
| 40 | + portions of the Software. | |
| 79 | 41 | |
| 80 | - /** | |
| 81 | - * Tokens | |
| 82 | - * | |
| 83 | - * @var PHPExcel_Calculation_FormulaToken[] | |
| 84 | - */ | |
| 85 | - private $tokens = array(); | |
| 42 | + The software is provided "as is", without warranty of any kind, express or implied, including but not | |
| 43 | + limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In | |
| 44 | + no event shall the authors or copyright holders be liable for any claim, damages or other liability, | |
| 45 | + whether in an action of contract, tort or otherwise, arising from, out of or in connection with the | |
| 46 | + software or the use or other dealings in the software. | |
| 86 | 47 | |
| 48 | + http://ewbi.blogs.com/develops/2007/03/excel_formula_p.html | |
| 49 | + http://ewbi.blogs.com/develops/2004/12/excel_formula_p.html | |
| 50 | +*/ | |
| 51 | + | |
| 52 | +/** | |
| 53 | + * PHPExcel_Calculation_FormulaParser | |
| 54 | + * | |
| 55 | + * @category PHPExcel | |
| 56 | + * @package PHPExcel_Calculation | |
| 57 | + * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) | |
| 58 | + */ | |
| 59 | +class PHPExcel_Calculation_FormulaParser { | |
| 60 | + /* Character constants */ | |
| 61 | + const QUOTE_DOUBLE = '"'; | |
| 62 | + const QUOTE_SINGLE = '\''; | |
| 63 | + const BRACKET_CLOSE = ']'; | |
| 64 | + const BRACKET_OPEN = '['; | |
| 65 | + const BRACE_OPEN = '{'; | |
| 66 | + const BRACE_CLOSE = '}'; | |
| 67 | + const PAREN_OPEN = '('; | |
| 68 | + const PAREN_CLOSE = ')'; | |
| 69 | + const SEMICOLON = ';'; | |
| 70 | + const WHITESPACE = ' '; | |
| 71 | + const COMMA = ','; | |
| 72 | + const ERROR_START = '#'; | |
| 73 | + | |
| 74 | + const OPERATORS_SN = "+-"; | |
| 75 | + const OPERATORS_INFIX = "+-*/^&=><"; | |
| 76 | + const OPERATORS_POSTFIX = "%"; | |
| 77 | + | |
| 78 | + /** | |
| 79 | + * Formula | |
| 80 | + * | |
| 81 | + * @var string | |
| 82 | + */ | |
| 83 | + private $_formula; | |
| 84 | + | |
| 85 | + /** | |
| 86 | + * Tokens | |
| 87 | + * | |
| 88 | + * @var PHPExcel_Calculation_FormulaToken[] | |
| 89 | + */ | |
| 90 | + private $_tokens = array(); | |
| 91 | + | |
| 87 | 92 | /** |
| 88 | 93 | * Create a new PHPExcel_Calculation_FormulaParser |
| 89 | 94 | * |
| 90 | - * @param string $pFormula Formula to parse | |
| 91 | - * @throws PHPExcel_Calculation_Exception | |
| 95 | + * @param string $pFormula Formula to parse | |
| 96 | + * @throws PHPExcel_Calculation_Exception | |
| 92 | 97 | */ |
| 93 | 98 | public function __construct($pFormula = '') |
| 94 | 99 | { |
| 95 | - // Check parameters | |
| 96 | - if (is_null($pFormula)) { | |
| 97 | - throw new PHPExcel_Calculation_Exception("Invalid parameter passed: formula"); | |
| 98 | - } | |
| 100 | + // Check parameters | |
| 101 | + if (is_null($pFormula)) { | |
| 102 | + throw new PHPExcel_Calculation_Exception("Invalid parameter passed: formula"); | |
| 103 | + } | |
| 99 | 104 | |
| 100 | - // Initialise values | |
| 101 | - $this->formula = trim($pFormula); | |
| 102 | - // Parse! | |
| 103 | - $this->parseToTokens(); | |
| 105 | + // Initialise values | |
| 106 | + $this->_formula = trim($pFormula); | |
| 107 | + // Parse! | |
| 108 | + $this->_parseToTokens(); | |
| 104 | 109 | } |
| 105 | 110 | |
| 106 | 111 | /** |
| 107 | 112 | * Get Formula |
| @@ -107,27 +112,25 @@ | ||
| 107 | 112 | * Get Formula |
| 108 | 113 | * |
| 109 | 114 | * @return string |
| 110 | 115 | */ |
| 111 | - public function getFormula() | |
| 112 | - { | |
| 113 | - return $this->formula; | |
| 116 | + public function getFormula() { | |
| 117 | + return $this->_formula; | |
| 114 | 118 | } |
| 115 | 119 | |
| 116 | 120 | /** |
| 117 | 121 | * Get Token |
| 118 | 122 | * |
| 119 | - * @param int $pId Token id | |
| 120 | - * @return string | |
| 123 | + * @param int $pId Token id | |
| 124 | + * @return string | |
| 121 | 125 | * @throws PHPExcel_Calculation_Exception |
| 122 | 126 | */ |
| 123 | - public function getToken($pId = 0) | |
| 124 | - { | |
| 125 | - if (isset($this->tokens[$pId])) { | |
| 126 | - return $this->tokens[$pId]; | |
| 127 | - } else { | |
| 128 | - throw new PHPExcel_Calculation_Exception("Token with id $pId does not exist."); | |
| 129 | - } | |
| 127 | + public function getToken($pId = 0) { | |
| 128 | + if (isset($this->_tokens[$pId])) { | |
| 129 | + return $this->_tokens[$pId]; | |
| 130 | + } else { | |
| 131 | + throw new PHPExcel_Calculation_Exception("Token with id $pId does not exist."); | |
| 132 | + } | |
| 130 | 133 | } |
| 131 | 134 | |
| 132 | 135 | /** |
| 133 | 136 | * Get Token count |
| @@ -133,11 +136,10 @@ | ||
| 133 | 136 | * Get Token count |
| 134 | 137 | * |
| 135 | 138 | * @return string |
| 136 | 139 | */ |
| 137 | - public function getTokenCount() | |
| 138 | - { | |
| 139 | - return count($this->tokens); | |
| 140 | + public function getTokenCount() { | |
| 141 | + return count($this->_tokens); | |
| 140 | 142 | } |
| 141 | 143 | |
| 142 | 144 | /** |
| 143 | 145 | * Get Tokens |
| @@ -143,480 +145,470 @@ | ||
| 143 | 145 | * Get Tokens |
| 144 | 146 | * |
| 145 | 147 | * @return PHPExcel_Calculation_FormulaToken[] |
| 146 | 148 | */ |
| 147 | - public function getTokens() | |
| 148 | - { | |
| 149 | - return $this->tokens; | |
| 149 | + public function getTokens() { | |
| 150 | + return $this->_tokens; | |
| 150 | 151 | } |
| 151 | 152 | |
| 152 | 153 | /** |
| 153 | 154 | * Parse to tokens |
| 154 | 155 | */ |
| 155 | - private function parseToTokens() | |
| 156 | - { | |
| 157 | - // No attempt is made to verify formulas; assumes formulas are derived from Excel, where | |
| 158 | - // they can only exist if valid; stack overflows/underflows sunk as nulls without exceptions. | |
| 156 | + private function _parseToTokens() { | |
| 157 | + // No attempt is made to verify formulas; assumes formulas are derived from Excel, where | |
| 158 | + // they can only exist if valid; stack overflows/underflows sunk as nulls without exceptions. | |
| 159 | 159 | |
| 160 | - // Check if the formula has a valid starting = | |
| 161 | - $formulaLength = strlen($this->formula); | |
| 162 | - if ($formulaLength < 2 || $this->formula{0} != '=') { | |
| 163 | - return; | |
| 164 | - } | |
| 160 | + // Check if the formula has a valid starting = | |
| 161 | + $formulaLength = strlen($this->_formula); | |
| 162 | + if ($formulaLength < 2 || $this->_formula{0} != '=') return; | |
| 165 | 163 | |
| 166 | - // Helper variables | |
| 167 | - $tokens1 = $tokens2 = $stack = array(); | |
| 168 | - $inString = $inPath = $inRange = $inError = false; | |
| 169 | - $token = $previousToken = $nextToken = null; | |
| 164 | + // Helper variables | |
| 165 | + $tokens1 = $tokens2 = $stack = array(); | |
| 166 | + $inString = $inPath = $inRange = $inError = false; | |
| 167 | + $token = $previousToken = $nextToken = null; | |
| 170 | 168 | |
| 171 | - $index = 1; | |
| 172 | - $value = ''; | |
| 169 | + $index = 1; | |
| 170 | + $value = ''; | |
| 173 | 171 | |
| 174 | - $ERRORS = array("#NULL!", "#DIV/0!", "#VALUE!", "#REF!", "#NAME?", "#NUM!", "#N/A"); | |
| 175 | - $COMPARATORS_MULTI = array(">=", "<=", "<>"); | |
| 172 | + $ERRORS = array("#NULL!", "#DIV/0!", "#VALUE!", "#REF!", "#NAME?", "#NUM!", "#N/A"); | |
| 173 | + $COMPARATORS_MULTI = array(">=", "<=", "<>"); | |
| 176 | 174 | |
| 177 | - while ($index < $formulaLength) { | |
| 178 | - // state-dependent character evaluation (order is important) | |
| 175 | + while ($index < $formulaLength) { | |
| 176 | + // state-dependent character evaluation (order is important) | |
| 179 | 177 | |
| 180 | - // double-quoted strings | |
| 181 | - // embeds are doubled | |
| 182 | - // end marks token | |
| 183 | - if ($inString) { | |
| 184 | - if ($this->formula{$index} == PHPExcel_Calculation_FormulaParser::QUOTE_DOUBLE) { | |
| 185 | - if ((($index + 2) <= $formulaLength) && ($this->formula{$index + 1} == PHPExcel_Calculation_FormulaParser::QUOTE_DOUBLE)) { | |
| 186 | - $value .= PHPExcel_Calculation_FormulaParser::QUOTE_DOUBLE; | |
| 187 | - ++$index; | |
| 188 | - } else { | |
| 189 | - $inString = false; | |
| 190 | - $tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_TEXT); | |
| 191 | - $value = ""; | |
| 192 | - } | |
| 193 | - } else { | |
| 194 | - $value .= $this->formula{$index}; | |
| 195 | - } | |
| 196 | - ++$index; | |
| 197 | - continue; | |
| 198 | - } | |
| 178 | + // double-quoted strings | |
| 179 | + // embeds are doubled | |
| 180 | + // end marks token | |
| 181 | + if ($inString) { | |
| 182 | + if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::QUOTE_DOUBLE) { | |
| 183 | + if ((($index + 2) <= $formulaLength) && ($this->_formula{$index + 1} == PHPExcel_Calculation_FormulaParser::QUOTE_DOUBLE)) { | |
| 184 | + $value .= PHPExcel_Calculation_FormulaParser::QUOTE_DOUBLE; | |
| 185 | + ++$index; | |
| 186 | + } else { | |
| 187 | + $inString = false; | |
| 188 | + $tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_TEXT); | |
| 189 | + $value = ""; | |
| 190 | + } | |
| 191 | + } else { | |
| 192 | + $value .= $this->_formula{$index}; | |
| 193 | + } | |
| 194 | + ++$index; | |
| 195 | + continue; | |
| 196 | + } | |
| 199 | 197 | |
| 200 | - // single-quoted strings (links) | |
| 201 | - // embeds are double | |
| 202 | - // end does not mark a token | |
| 203 | - if ($inPath) { | |
| 204 | - if ($this->formula{$index} == PHPExcel_Calculation_FormulaParser::QUOTE_SINGLE) { | |
| 205 | - if ((($index + 2) <= $formulaLength) && ($this->formula{$index + 1} == PHPExcel_Calculation_FormulaParser::QUOTE_SINGLE)) { | |
| 206 | - $value .= PHPExcel_Calculation_FormulaParser::QUOTE_SINGLE; | |
| 207 | - ++$index; | |
| 208 | - } else { | |
| 209 | - $inPath = false; | |
| 210 | - } | |
| 211 | - } else { | |
| 212 | - $value .= $this->formula{$index}; | |
| 213 | - } | |
| 214 | - ++$index; | |
| 215 | - continue; | |
| 216 | - } | |
| 198 | + // single-quoted strings (links) | |
| 199 | + // embeds are double | |
| 200 | + // end does not mark a token | |
| 201 | + if ($inPath) { | |
| 202 | + if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::QUOTE_SINGLE) { | |
| 203 | + if ((($index + 2) <= $formulaLength) && ($this->_formula{$index + 1} == PHPExcel_Calculation_FormulaParser::QUOTE_SINGLE)) { | |
| 204 | + $value .= PHPExcel_Calculation_FormulaParser::QUOTE_SINGLE; | |
| 205 | + ++$index; | |
| 206 | + } else { | |
| 207 | + $inPath = false; | |
| 208 | + } | |
| 209 | + } else { | |
| 210 | + $value .= $this->_formula{$index}; | |
| 211 | + } | |
| 212 | + ++$index; | |
| 213 | + continue; | |
| 214 | + } | |
| 217 | 215 | |
| 218 | - // bracked strings (R1C1 range index or linked workbook name) | |
| 219 | - // no embeds (changed to "()" by Excel) | |
| 220 | - // end does not mark a token | |
| 221 | - if ($inRange) { | |
| 222 | - if ($this->formula{$index} == PHPExcel_Calculation_FormulaParser::BRACKET_CLOSE) { | |
| 223 | - $inRange = false; | |
| 224 | - } | |
| 225 | - $value .= $this->formula{$index}; | |
| 226 | - ++$index; | |
| 227 | - continue; | |
| 228 | - } | |
| 216 | + // bracked strings (R1C1 range index or linked workbook name) | |
| 217 | + // no embeds (changed to "()" by Excel) | |
| 218 | + // end does not mark a token | |
| 219 | + if ($inRange) { | |
| 220 | + if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::BRACKET_CLOSE) { | |
| 221 | + $inRange = false; | |
| 222 | + } | |
| 223 | + $value .= $this->_formula{$index}; | |
| 224 | + ++$index; | |
| 225 | + continue; | |
| 226 | + } | |
| 229 | 227 | |
| 230 | - // error values | |
| 231 | - // end marks a token, determined from absolute list of values | |
| 232 | - if ($inError) { | |
| 233 | - $value .= $this->formula{$index}; | |
| 234 | - ++$index; | |
| 235 | - if (in_array($value, $ERRORS)) { | |
| 236 | - $inError = false; | |
| 237 | - $tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_ERROR); | |
| 238 | - $value = ""; | |
| 239 | - } | |
| 240 | - continue; | |
| 241 | - } | |
| 228 | + // error values | |
| 229 | + // end marks a token, determined from absolute list of values | |
| 230 | + if ($inError) { | |
| 231 | + $value .= $this->_formula{$index}; | |
| 232 | + ++$index; | |
| 233 | + if (in_array($value, $ERRORS)) { | |
| 234 | + $inError = false; | |
| 235 | + $tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_ERROR); | |
| 236 | + $value = ""; | |
| 237 | + } | |
| 238 | + continue; | |
| 239 | + } | |
| 242 | 240 | |
| 243 | - // scientific notation check | |
| 244 | - if (strpos(PHPExcel_Calculation_FormulaParser::OPERATORS_SN, $this->formula{$index}) !== false) { | |
| 245 | - if (strlen($value) > 1) { | |
| 246 | - if (preg_match("/^[1-9]{1}(\.[0-9]+)?E{1}$/", $this->formula{$index}) != 0) { | |
| 247 | - $value .= $this->formula{$index}; | |
| 248 | - ++$index; | |
| 249 | - continue; | |
| 250 | - } | |
| 251 | - } | |
| 252 | - } | |
| 241 | + // scientific notation check | |
| 242 | + if (strpos(PHPExcel_Calculation_FormulaParser::OPERATORS_SN, $this->_formula{$index}) !== false) { | |
| 243 | + if (strlen($value) > 1) { | |
| 244 | + if (preg_match("/^[1-9]{1}(\.[0-9]+)?E{1}$/", $this->_formula{$index}) != 0) { | |
| 245 | + $value .= $this->_formula{$index}; | |
| 246 | + ++$index; | |
| 247 | + continue; | |
| 248 | + } | |
| 249 | + } | |
| 250 | + } | |
| 253 | 251 | |
| 254 | - // independent character evaluation (order not important) | |
| 252 | + // independent character evaluation (order not important) | |
| 255 | 253 | |
| 256 | - // establish state-dependent character evaluations | |
| 257 | - if ($this->formula{$index} == PHPExcel_Calculation_FormulaParser::QUOTE_DOUBLE) { | |
| 258 | - if (strlen($value > 0)) { | |
| 259 | - // unexpected | |
| 260 | - $tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_UNKNOWN); | |
| 261 | - $value = ""; | |
| 262 | - } | |
| 263 | - $inString = true; | |
| 264 | - ++$index; | |
| 265 | - continue; | |
| 266 | - } | |
| 254 | + // establish state-dependent character evaluations | |
| 255 | + if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::QUOTE_DOUBLE) { | |
| 256 | + if (strlen($value > 0)) { // unexpected | |
| 257 | + $tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_UNKNOWN); | |
| 258 | + $value = ""; | |
| 259 | + } | |
| 260 | + $inString = true; | |
| 261 | + ++$index; | |
| 262 | + continue; | |
| 263 | + } | |
| 267 | 264 | |
| 268 | - if ($this->formula{$index} == PHPExcel_Calculation_FormulaParser::QUOTE_SINGLE) { | |
| 269 | - if (strlen($value) > 0) { | |
| 270 | - // unexpected | |
| 271 | - $tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_UNKNOWN); | |
| 272 | - $value = ""; | |
| 273 | - } | |
| 274 | - $inPath = true; | |
| 275 | - ++$index; | |
| 276 | - continue; | |
| 277 | - } | |
| 265 | + if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::QUOTE_SINGLE) { | |
| 266 | + if (strlen($value) > 0) { // unexpected | |
| 267 | + $tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_UNKNOWN); | |
| 268 | + $value = ""; | |
| 269 | + } | |
| 270 | + $inPath = true; | |
| 271 | + ++$index; | |
| 272 | + continue; | |
| 273 | + } | |
| 278 | 274 | |
| 279 | - if ($this->formula{$index} == PHPExcel_Calculation_FormulaParser::BRACKET_OPEN) { | |
| 280 | - $inRange = true; | |
| 281 | - $value .= PHPExcel_Calculation_FormulaParser::BRACKET_OPEN; | |
| 282 | - ++$index; | |
| 283 | - continue; | |
| 284 | - } | |
| 275 | + if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::BRACKET_OPEN) { | |
| 276 | + $inRange = true; | |
| 277 | + $value .= PHPExcel_Calculation_FormulaParser::BRACKET_OPEN; | |
| 278 | + ++$index; | |
| 279 | + continue; | |
| 280 | + } | |
| 285 | 281 | |
| 286 | - if ($this->formula{$index} == PHPExcel_Calculation_FormulaParser::ERROR_START) { | |
| 287 | - if (strlen($value) > 0) { | |
| 288 | - // unexpected | |
| 289 | - $tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_UNKNOWN); | |
| 290 | - $value = ""; | |
| 291 | - } | |
| 292 | - $inError = true; | |
| 293 | - $value .= PHPExcel_Calculation_FormulaParser::ERROR_START; | |
| 294 | - ++$index; | |
| 295 | - continue; | |
| 296 | - } | |
| 282 | + if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::ERROR_START) { | |
| 283 | + if (strlen($value) > 0) { // unexpected | |
| 284 | + $tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_UNKNOWN); | |
| 285 | + $value = ""; | |
| 286 | + } | |
| 287 | + $inError = true; | |
| 288 | + $value .= PHPExcel_Calculation_FormulaParser::ERROR_START; | |
| 289 | + ++$index; | |
| 290 | + continue; | |
| 291 | + } | |
| 297 | 292 | |
| 298 | - // mark start and end of arrays and array rows | |
| 299 | - if ($this->formula{$index} == PHPExcel_Calculation_FormulaParser::BRACE_OPEN) { | |
| 300 | - if (strlen($value) > 0) { | |
| 301 | - // unexpected | |
| 302 | - $tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_UNKNOWN); | |
| 303 | - $value = ""; | |
| 304 | - } | |
| 293 | + // mark start and end of arrays and array rows | |
| 294 | + if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::BRACE_OPEN) { | |
| 295 | + if (strlen($value) > 0) { // unexpected | |
| 296 | + $tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_UNKNOWN); | |
| 297 | + $value = ""; | |
| 298 | + } | |
| 305 | 299 | |
| 306 | - $tmp = new PHPExcel_Calculation_FormulaToken("ARRAY", PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_START); | |
| 307 | - $tokens1[] = $tmp; | |
| 308 | - $stack[] = clone $tmp; | |
| 300 | + $tmp = new PHPExcel_Calculation_FormulaToken("ARRAY", PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_START); | |
| 301 | + $tokens1[] = $tmp; | |
| 302 | + $stack[] = clone $tmp; | |
| 309 | 303 | |
| 310 | - $tmp = new PHPExcel_Calculation_FormulaToken("ARRAYROW", PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_START); | |
| 311 | - $tokens1[] = $tmp; | |
| 312 | - $stack[] = clone $tmp; | |
| 304 | + $tmp = new PHPExcel_Calculation_FormulaToken("ARRAYROW", PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_START); | |
| 305 | + $tokens1[] = $tmp; | |
| 306 | + $stack[] = clone $tmp; | |
| 313 | 307 | |
| 314 | - ++$index; | |
| 315 | - continue; | |
| 316 | - } | |
| 308 | + ++$index; | |
| 309 | + continue; | |
| 310 | + } | |
| 317 | 311 | |
| 318 | - if ($this->formula{$index} == PHPExcel_Calculation_FormulaParser::SEMICOLON) { | |
| 319 | - if (strlen($value) > 0) { | |
| 320 | - $tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND); | |
| 321 | - $value = ""; | |
| 322 | - } | |
| 312 | + if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::SEMICOLON) { | |
| 313 | + if (strlen($value) > 0) { | |
| 314 | + $tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND); | |
| 315 | + $value = ""; | |
| 316 | + } | |
| 323 | 317 | |
| 324 | - $tmp = array_pop($stack); | |
| 325 | - $tmp->setValue(""); | |
| 326 | - $tmp->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP); | |
| 327 | - $tokens1[] = $tmp; | |
| 318 | + $tmp = array_pop($stack); | |
| 319 | + $tmp->setValue(""); | |
| 320 | + $tmp->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP); | |
| 321 | + $tokens1[] = $tmp; | |
| 328 | 322 | |
| 329 | - $tmp = new PHPExcel_Calculation_FormulaToken(",", PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_ARGUMENT); | |
| 330 | - $tokens1[] = $tmp; | |
| 323 | + $tmp = new PHPExcel_Calculation_FormulaToken(",", PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_ARGUMENT); | |
| 324 | + $tokens1[] = $tmp; | |
| 331 | 325 | |
| 332 | - $tmp = new PHPExcel_Calculation_FormulaToken("ARRAYROW", PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_START); | |
| 333 | - $tokens1[] = $tmp; | |
| 334 | - $stack[] = clone $tmp; | |
| 326 | + $tmp = new PHPExcel_Calculation_FormulaToken("ARRAYROW", PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_START); | |
| 327 | + $tokens1[] = $tmp; | |
| 328 | + $stack[] = clone $tmp; | |
| 335 | 329 | |
| 336 | - ++$index; | |
| 337 | - continue; | |
| 338 | - } | |
| 330 | + ++$index; | |
| 331 | + continue; | |
| 332 | + } | |
| 339 | 333 | |
| 340 | - if ($this->formula{$index} == PHPExcel_Calculation_FormulaParser::BRACE_CLOSE) { | |
| 341 | - if (strlen($value) > 0) { | |
| 342 | - $tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND); | |
| 343 | - $value = ""; | |
| 344 | - } | |
| 334 | + if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::BRACE_CLOSE) { | |
| 335 | + if (strlen($value) > 0) { | |
| 336 | + $tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND); | |
| 337 | + $value = ""; | |
| 338 | + } | |
| 345 | 339 | |
| 346 | - $tmp = array_pop($stack); | |
| 347 | - $tmp->setValue(""); | |
| 348 | - $tmp->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP); | |
| 349 | - $tokens1[] = $tmp; | |
| 340 | + $tmp = array_pop($stack); | |
| 341 | + $tmp->setValue(""); | |
| 342 | + $tmp->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP); | |
| 343 | + $tokens1[] = $tmp; | |
| 350 | 344 | |
| 351 | - $tmp = array_pop($stack); | |
| 352 | - $tmp->setValue(""); | |
| 353 | - $tmp->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP); | |
| 354 | - $tokens1[] = $tmp; | |
| 345 | + $tmp = array_pop($stack); | |
| 346 | + $tmp->setValue(""); | |
| 347 | + $tmp->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP); | |
| 348 | + $tokens1[] = $tmp; | |
| 355 | 349 | |
| 356 | - ++$index; | |
| 357 | - continue; | |
| 358 | - } | |
| 350 | + ++$index; | |
| 351 | + continue; | |
| 352 | + } | |
| 359 | 353 | |
| 360 | - // trim white-space | |
| 361 | - if ($this->formula{$index} == PHPExcel_Calculation_FormulaParser::WHITESPACE) { | |
| 362 | - if (strlen($value) > 0) { | |
| 363 | - $tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND); | |
| 364 | - $value = ""; | |
| 365 | - } | |
| 366 | - $tokens1[] = new PHPExcel_Calculation_FormulaToken("", PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_WHITESPACE); | |
| 367 | - ++$index; | |
| 368 | - while (($this->formula{$index} == PHPExcel_Calculation_FormulaParser::WHITESPACE) && ($index < $formulaLength)) { | |
| 369 | - ++$index; | |
| 370 | - } | |
| 371 | - continue; | |
| 372 | - } | |
| 354 | + // trim white-space | |
| 355 | + if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::WHITESPACE) { | |
| 356 | + if (strlen($value) > 0) { | |
| 357 | + $tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND); | |
| 358 | + $value = ""; | |
| 359 | + } | |
| 360 | + $tokens1[] = new PHPExcel_Calculation_FormulaToken("", PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_WHITESPACE); | |
| 361 | + ++$index; | |
| 362 | + while (($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::WHITESPACE) && ($index < $formulaLength)) { | |
| 363 | + ++$index; | |
| 364 | + } | |
| 365 | + continue; | |
| 366 | + } | |
| 373 | 367 | |
| 374 | - // multi-character comparators | |
| 375 | - if (($index + 2) <= $formulaLength) { | |
| 376 | - if (in_array(substr($this->formula, $index, 2), $COMPARATORS_MULTI)) { | |
| 377 | - if (strlen($value) > 0) { | |
| 378 | - $tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND); | |
| 379 | - $value = ""; | |
| 380 | - } | |
| 381 | - $tokens1[] = new PHPExcel_Calculation_FormulaToken(substr($this->formula, $index, 2), PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORINFIX, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_LOGICAL); | |
| 382 | - $index += 2; | |
| 383 | - continue; | |
| 384 | - } | |
| 385 | - } | |
| 368 | + // multi-character comparators | |
| 369 | + if (($index + 2) <= $formulaLength) { | |
| 370 | + if (in_array(substr($this->_formula, $index, 2), $COMPARATORS_MULTI)) { | |
| 371 | + if (strlen($value) > 0) { | |
| 372 | + $tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND); | |
| 373 | + $value = ""; | |
| 374 | + } | |
| 375 | + $tokens1[] = new PHPExcel_Calculation_FormulaToken(substr($this->_formula, $index, 2), PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORINFIX, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_LOGICAL); | |
| 376 | + $index += 2; | |
| 377 | + continue; | |
| 378 | + } | |
| 379 | + } | |
| 386 | 380 | |
| 387 | - // standard infix operators | |
| 388 | - if (strpos(PHPExcel_Calculation_FormulaParser::OPERATORS_INFIX, $this->formula{$index}) !== false) { | |
| 389 | - if (strlen($value) > 0) { | |
| 390 | - $tokens1[] =new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND); | |
| 391 | - $value = ""; | |
| 392 | - } | |
| 393 | - $tokens1[] = new PHPExcel_Calculation_FormulaToken($this->formula{$index}, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORINFIX); | |
| 394 | - ++$index; | |
| 395 | - continue; | |
| 396 | - } | |
| 381 | + // standard infix operators | |
| 382 | + if (strpos(PHPExcel_Calculation_FormulaParser::OPERATORS_INFIX, $this->_formula{$index}) !== false) { | |
| 383 | + if (strlen($value) > 0) { | |
| 384 | + $tokens1[] =new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND); | |
| 385 | + $value = ""; | |
| 386 | + } | |
| 387 | + $tokens1[] = new PHPExcel_Calculation_FormulaToken($this->_formula{$index}, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORINFIX); | |
| 388 | + ++$index; | |
| 389 | + continue; | |
| 390 | + } | |
| 397 | 391 | |
| 398 | - // standard postfix operators (only one) | |
| 399 | - if (strpos(PHPExcel_Calculation_FormulaParser::OPERATORS_POSTFIX, $this->formula{$index}) !== false) { | |
| 400 | - if (strlen($value) > 0) { | |
| 401 | - $tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND); | |
| 402 | - $value = ""; | |
| 403 | - } | |
| 404 | - $tokens1[] = new PHPExcel_Calculation_FormulaToken($this->formula{$index}, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORPOSTFIX); | |
| 405 | - ++$index; | |
| 406 | - continue; | |
| 407 | - } | |
| 392 | + // standard postfix operators (only one) | |
| 393 | + if (strpos(PHPExcel_Calculation_FormulaParser::OPERATORS_POSTFIX, $this->_formula{$index}) !== false) { | |
| 394 | + if (strlen($value) > 0) { | |
| 395 | + $tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND); | |
| 396 | + $value = ""; | |
| 397 | + } | |
| 398 | + $tokens1[] = new PHPExcel_Calculation_FormulaToken($this->_formula{$index}, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORPOSTFIX); | |
| 399 | + ++$index; | |
| 400 | + continue; | |
| 401 | + } | |
| 408 | 402 | |
| 409 | - // start subexpression or function | |
| 410 | - if ($this->formula{$index} == PHPExcel_Calculation_FormulaParser::PAREN_OPEN) { | |
| 411 | - if (strlen($value) > 0) { | |
| 412 | - $tmp = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_START); | |
| 413 | - $tokens1[] = $tmp; | |
| 414 | - $stack[] = clone $tmp; | |
| 415 | - $value = ""; | |
| 416 | - } else { | |
| 417 | - $tmp = new PHPExcel_Calculation_FormulaToken("", PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_SUBEXPRESSION, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_START); | |
| 418 | - $tokens1[] = $tmp; | |
| 419 | - $stack[] = clone $tmp; | |
| 420 | - } | |
| 421 | - ++$index; | |
| 422 | - continue; | |
| 423 | - } | |
| 403 | + // start subexpression or function | |
| 404 | + if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::PAREN_OPEN) { | |
| 405 | + if (strlen($value) > 0) { | |
| 406 | + $tmp = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_START); | |
| 407 | + $tokens1[] = $tmp; | |
| 408 | + $stack[] = clone $tmp; | |
| 409 | + $value = ""; | |
| 410 | + } else { | |
| 411 | + $tmp = new PHPExcel_Calculation_FormulaToken("", PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_SUBEXPRESSION, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_START); | |
| 412 | + $tokens1[] = $tmp; | |
| 413 | + $stack[] = clone $tmp; | |
| 414 | + } | |
| 415 | + ++$index; | |
| 416 | + continue; | |
| 417 | + } | |
| 424 | 418 | |
| 425 | - // function, subexpression, or array parameters, or operand unions | |
| 426 | - if ($this->formula{$index} == PHPExcel_Calculation_FormulaParser::COMMA) { | |
| 427 | - if (strlen($value) > 0) { | |
| 428 | - $tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND); | |
| 429 | - $value = ""; | |
| 430 | - } | |
| 419 | + // function, subexpression, or array parameters, or operand unions | |
| 420 | + if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::COMMA) { | |
| 421 | + if (strlen($value) > 0) { | |
| 422 | + $tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND); | |
| 423 | + $value = ""; | |
| 424 | + } | |
| 431 | 425 | |
| 432 | - $tmp = array_pop($stack); | |
| 433 | - $tmp->setValue(""); | |
| 434 | - $tmp->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP); | |
| 435 | - $stack[] = $tmp; | |
| 426 | + $tmp = array_pop($stack); | |
| 427 | + $tmp->setValue(""); | |
| 428 | + $tmp->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP); | |
| 429 | + $stack[] = $tmp; | |
| 436 | 430 | |
| 437 | - if ($tmp->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION) { | |
| 438 | - $tokens1[] = new PHPExcel_Calculation_FormulaToken(",", PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORINFIX, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_UNION); | |
| 439 | - } else { | |
| 440 | - $tokens1[] = new PHPExcel_Calculation_FormulaToken(",", PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_ARGUMENT); | |
| 441 | - } | |
| 442 | - ++$index; | |
| 443 | - continue; | |
| 444 | - } | |
| 431 | + if ($tmp->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION) { | |
| 432 | + $tokens1[] = new PHPExcel_Calculation_FormulaToken(",", PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORINFIX, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_UNION); | |
| 433 | + } else { | |
| 434 | + $tokens1[] = new PHPExcel_Calculation_FormulaToken(",", PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_ARGUMENT); | |
| 435 | + } | |
| 436 | + ++$index; | |
| 437 | + continue; | |
| 438 | + } | |
| 445 | 439 | |
| 446 | - // stop subexpression | |
| 447 | - if ($this->formula{$index} == PHPExcel_Calculation_FormulaParser::PAREN_CLOSE) { | |
| 448 | - if (strlen($value) > 0) { | |
| 449 | - $tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND); | |
| 450 | - $value = ""; | |
| 451 | - } | |
| 440 | + // stop subexpression | |
| 441 | + if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::PAREN_CLOSE) { | |
| 442 | + if (strlen($value) > 0) { | |
| 443 | + $tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND); | |
| 444 | + $value = ""; | |
| 445 | + } | |
| 452 | 446 | |
| 453 | - $tmp = array_pop($stack); | |
| 454 | - $tmp->setValue(""); | |
| 455 | - $tmp->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP); | |
| 456 | - $tokens1[] = $tmp; | |
| 447 | + $tmp = array_pop($stack); | |
| 448 | + $tmp->setValue(""); | |
| 449 | + $tmp->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP); | |
| 450 | + $tokens1[] = $tmp; | |
| 457 | 451 | |
| 458 | - ++$index; | |
| 459 | - continue; | |
| 460 | - } | |
| 452 | + ++$index; | |
| 453 | + continue; | |
| 454 | + } | |
| 461 | 455 | |
| 462 | - // token accumulation | |
| 463 | - $value .= $this->formula{$index}; | |
| 464 | - ++$index; | |
| 465 | - } | |
| 456 | + // token accumulation | |
| 457 | + $value .= $this->_formula{$index}; | |
| 458 | + ++$index; | |
| 459 | + } | |
| 466 | 460 | |
| 467 | - // dump remaining accumulation | |
| 468 | - if (strlen($value) > 0) { | |
| 469 | - $tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND); | |
| 470 | - } | |
| 461 | + // dump remaining accumulation | |
| 462 | + if (strlen($value) > 0) { | |
| 463 | + $tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND); | |
| 464 | + } | |
| 471 | 465 | |
| 472 | - // move tokenList to new set, excluding unnecessary white-space tokens and converting necessary ones to intersections | |
| 473 | - $tokenCount = count($tokens1); | |
| 474 | - for ($i = 0; $i < $tokenCount; ++$i) { | |
| 475 | - $token = $tokens1[$i]; | |
| 476 | - if (isset($tokens1[$i - 1])) { | |
| 477 | - $previousToken = $tokens1[$i - 1]; | |
| 478 | - } else { | |
| 479 | - $previousToken = null; | |
| 480 | - } | |
| 481 | - if (isset($tokens1[$i + 1])) { | |
| 482 | - $nextToken = $tokens1[$i + 1]; | |
| 483 | - } else { | |
| 484 | - $nextToken = null; | |
| 485 | - } | |
| 466 | + // move tokenList to new set, excluding unnecessary white-space tokens and converting necessary ones to intersections | |
| 467 | + $tokenCount = count($tokens1); | |
| 468 | + for ($i = 0; $i < $tokenCount; ++$i) { | |
| 469 | + $token = $tokens1[$i]; | |
| 470 | + if (isset($tokens1[$i - 1])) { | |
| 471 | + $previousToken = $tokens1[$i - 1]; | |
| 472 | + } else { | |
| 473 | + $previousToken = null; | |
| 474 | + } | |
| 475 | + if (isset($tokens1[$i + 1])) { | |
| 476 | + $nextToken = $tokens1[$i + 1]; | |
| 477 | + } else { | |
| 478 | + $nextToken = null; | |
| 479 | + } | |
| 486 | 480 | |
| 487 | - if (is_null($token)) { | |
| 488 | - continue; | |
| 489 | - } | |
| 481 | + if (is_null($token)) { | |
| 482 | + continue; | |
| 483 | + } | |
| 490 | 484 | |
| 491 | - if ($token->getTokenType() != PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_WHITESPACE) { | |
| 492 | - $tokens2[] = $token; | |
| 493 | - continue; | |
| 494 | - } | |
| 485 | + if ($token->getTokenType() != PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_WHITESPACE) { | |
| 486 | + $tokens2[] = $token; | |
| 487 | + continue; | |
| 488 | + } | |
| 495 | 489 | |
| 496 | - if (is_null($previousToken)) { | |
| 497 | - continue; | |
| 498 | - } | |
| 490 | + if (is_null($previousToken)) { | |
| 491 | + continue; | |
| 492 | + } | |
| 499 | 493 | |
| 500 | - if (! ( | |
| 501 | - (($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION) && ($previousToken->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP)) || | |
| 502 | - (($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_SUBEXPRESSION) && ($previousToken->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP)) || | |
| 503 | - ($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND) | |
| 504 | - ) ) { | |
| 505 | - continue; | |
| 506 | - } | |
| 494 | + if (! ( | |
| 495 | + (($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION) && ($previousToken->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP)) || | |
| 496 | + (($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_SUBEXPRESSION) && ($previousToken->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP)) || | |
| 497 | + ($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND) | |
| 498 | + ) ) { | |
| 499 | + continue; | |
| 500 | + } | |
| 507 | 501 | |
| 508 | - if (is_null($nextToken)) { | |
| 509 | - continue; | |
| 510 | - } | |
| 502 | + if (is_null($nextToken)) { | |
| 503 | + continue; | |
| 504 | + } | |
| 511 | 505 | |
| 512 | - if (! ( | |
| 513 | - (($nextToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION) && ($nextToken->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_START)) || | |
| 514 | - (($nextToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_SUBEXPRESSION) && ($nextToken->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_START)) || | |
| 515 | - ($nextToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND) | |
| 516 | - ) ) { | |
| 517 | - continue; | |
| 518 | - } | |
| 506 | + if (! ( | |
| 507 | + (($nextToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION) && ($nextToken->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_START)) || | |
| 508 | + (($nextToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_SUBEXPRESSION) && ($nextToken->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_START)) || | |
| 509 | + ($nextToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND) | |
| 510 | + ) ) { | |
| 511 | + continue; | |
| 512 | + } | |
| 519 | 513 | |
| 520 | - $tokens2[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORINFIX, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_INTERSECTION); | |
| 521 | - } | |
| 514 | + $tokens2[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORINFIX, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_INTERSECTION); | |
| 515 | + } | |
| 522 | 516 | |
| 523 | - // move tokens to final list, switching infix "-" operators to prefix when appropriate, switching infix "+" operators | |
| 524 | - // to noop when appropriate, identifying operand and infix-operator subtypes, and pulling "@" from function names | |
| 525 | - $this->tokens = array(); | |
| 517 | + // move tokens to final list, switching infix "-" operators to prefix when appropriate, switching infix "+" operators | |
| 518 | + // to noop when appropriate, identifying operand and infix-operator subtypes, and pulling "@" from function names | |
| 519 | + $this->_tokens = array(); | |
| 526 | 520 | |
| 527 | - $tokenCount = count($tokens2); | |
| 528 | - for ($i = 0; $i < $tokenCount; ++$i) { | |
| 529 | - $token = $tokens2[$i]; | |
| 530 | - if (isset($tokens2[$i - 1])) { | |
| 531 | - $previousToken = $tokens2[$i - 1]; | |
| 532 | - } else { | |
| 533 | - $previousToken = null; | |
| 534 | - } | |
| 535 | - if (isset($tokens2[$i + 1])) { | |
| 536 | - $nextToken = $tokens2[$i + 1]; | |
| 537 | - } else { | |
| 538 | - $nextToken = null; | |
| 539 | - } | |
| 521 | + $tokenCount = count($tokens2); | |
| 522 | + for ($i = 0; $i < $tokenCount; ++$i) { | |
| 523 | + $token = $tokens2[$i]; | |
| 524 | + if (isset($tokens2[$i - 1])) { | |
| 525 | + $previousToken = $tokens2[$i - 1]; | |
| 526 | + } else { | |
| 527 | + $previousToken = null; | |
| 528 | + } | |
| 529 | + if (isset($tokens2[$i + 1])) { | |
| 530 | + $nextToken = $tokens2[$i + 1]; | |
| 531 | + } else { | |
| 532 | + $nextToken = null; | |
| 533 | + } | |
| 540 | 534 | |
| 541 | - if (is_null($token)) { | |
| 542 | - continue; | |
| 543 | - } | |
| 535 | + if (is_null($token)) { | |
| 536 | + continue; | |
| 537 | + } | |
| 544 | 538 | |
| 545 | - if ($token->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORINFIX && $token->getValue() == "-") { | |
| 546 | - if ($i == 0) { | |
| 547 | - $token->setTokenType(PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORPREFIX); | |
| 548 | - } elseif ((($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION) && | |
| 549 | - ($previousToken->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP)) || | |
| 550 | - (($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_SUBEXPRESSION) && | |
| 551 | - ($previousToken->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP)) || | |
| 552 | - ($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORPOSTFIX) || | |
| 553 | - ($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND)) { | |
| 554 | - $token->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_MATH); | |
| 555 | - } else { | |
| 556 | - $token->setTokenType(PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORPREFIX); | |
| 557 | - } | |
| 539 | + if ($token->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORINFIX && $token->getValue() == "-") { | |
| 540 | + if ($i == 0) { | |
| 541 | + $token->setTokenType(PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORPREFIX); | |
| 542 | + } else if ( | |
| 543 | + (($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION) && ($previousToken->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP)) || | |
| 544 | + (($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_SUBEXPRESSION) && ($previousToken->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP)) || | |
| 545 | + ($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORPOSTFIX) || | |
| 546 | + ($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND) | |
| 547 | + ) { | |
| 548 | + $token->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_MATH); | |
| 549 | + } else { | |
| 550 | + $token->setTokenType(PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORPREFIX); | |
| 551 | + } | |
| 558 | 552 | |
| 559 | - $this->tokens[] = $token; | |
| 560 | - continue; | |
| 561 | - } | |
| 553 | + $this->_tokens[] = $token; | |
| 554 | + continue; | |
| 555 | + } | |
| 562 | 556 | |
| 563 | - if ($token->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORINFIX && $token->getValue() == "+") { | |
| 564 | - if ($i == 0) { | |
| 565 | - continue; | |
| 566 | - } elseif ((($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION) && | |
| 567 | - ($previousToken->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP)) || | |
| 568 | - (($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_SUBEXPRESSION) && | |
| 569 | - ($previousToken->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP)) || | |
| 570 | - ($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORPOSTFIX) || | |
| 571 | - ($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND)) { | |
| 572 | - $token->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_MATH); | |
| 573 | - } else { | |
| 574 | - continue; | |
| 575 | - } | |
| 557 | + if ($token->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORINFIX && $token->getValue() == "+") { | |
| 558 | + if ($i == 0) { | |
| 559 | + continue; | |
| 560 | + } else if ( | |
| 561 | + (($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION) && ($previousToken->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP)) || | |
| 562 | + (($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_SUBEXPRESSION) && ($previousToken->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP)) || | |
| 563 | + ($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORPOSTFIX) || | |
| 564 | + ($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND) | |
| 565 | + ) { | |
| 566 | + $token->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_MATH); | |
| 567 | + } else { | |
| 568 | + continue; | |
| 569 | + } | |
| 576 | 570 | |
| 577 | - $this->tokens[] = $token; | |
| 578 | - continue; | |
| 579 | - } | |
| 571 | + $this->_tokens[] = $token; | |
| 572 | + continue; | |
| 573 | + } | |
| 580 | 574 | |
| 581 | - if ($token->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORINFIX && | |
| 582 | - $token->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_NOTHING) { | |
| 583 | - if (strpos("<>=", substr($token->getValue(), 0, 1)) !== false) { | |
| 584 | - $token->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_LOGICAL); | |
| 585 | - } elseif ($token->getValue() == "&") { | |
| 586 | - $token->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_CONCATENATION); | |
| 587 | - } else { | |
| 588 | - $token->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_MATH); | |
| 589 | - } | |
| 575 | + if ($token->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORINFIX && $token->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_NOTHING) { | |
| 576 | + if (strpos("<>=", substr($token->getValue(), 0, 1)) !== false) { | |
| 577 | + $token->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_LOGICAL); | |
| 578 | + } else if ($token->getValue() == "&") { | |
| 579 | + $token->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_CONCATENATION); | |
| 580 | + } else { | |
| 581 | + $token->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_MATH); | |
| 582 | + } | |
| 590 | 583 | |
| 591 | - $this->tokens[] = $token; | |
| 592 | - continue; | |
| 593 | - } | |
| 584 | + $this->_tokens[] = $token; | |
| 585 | + continue; | |
| 586 | + } | |
| 594 | 587 | |
| 595 | - if ($token->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND && | |
| 596 | - $token->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_NOTHING) { | |
| 597 | - if (!is_numeric($token->getValue())) { | |
| 598 | - if (strtoupper($token->getValue()) == "TRUE" || strtoupper($token->getValue() == "FALSE")) { | |
| 599 | - $token->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_LOGICAL); | |
| 600 | - } else { | |
| 601 | - $token->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_RANGE); | |
| 602 | - } | |
| 603 | - } else { | |
| 604 | - $token->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_NUMBER); | |
| 605 | - } | |
| 588 | + if ($token->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND && $token->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_NOTHING) { | |
| 589 | + if (!is_numeric($token->getValue())) { | |
| 590 | + if (strtoupper($token->getValue()) == "TRUE" || strtoupper($token->getValue() == "FALSE")) { | |
| 591 | + $token->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_LOGICAL); | |
| 592 | + } else { | |
| 593 | + $token->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_RANGE); | |
| 594 | + } | |
| 595 | + } else { | |
| 596 | + $token->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_NUMBER); | |
| 597 | + } | |
| 606 | 598 | |
| 607 | - $this->tokens[] = $token; | |
| 608 | - continue; | |
| 609 | - } | |
| 599 | + $this->_tokens[] = $token; | |
| 600 | + continue; | |
| 601 | + } | |
| 610 | 602 | |
| 611 | - if ($token->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION) { | |
| 612 | - if (strlen($token->getValue() > 0)) { | |
| 613 | - if (substr($token->getValue(), 0, 1) == "@") { | |
| 614 | - $token->setValue(substr($token->getValue(), 1)); | |
| 615 | - } | |
| 616 | - } | |
| 617 | - } | |
| 603 | + if ($token->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION) { | |
| 604 | + if (strlen($token->getValue() > 0)) { | |
| 605 | + if (substr($token->getValue(), 0, 1) == "@") { | |
| 606 | + $token->setValue(substr($token->getValue(), 1)); | |
| 607 | + } | |
| 608 | + } | |
| 609 | + } | |
| 618 | 610 | |
| 619 | - $this->tokens[] = $token; | |
| 620 | - } | |
| 611 | + $this->_tokens[] = $token; | |
| 612 | + } | |
| 621 | 613 | } |
| 622 | 614 | } |