private function _ParseExpression() { $arrTokens = Toolset_Tokenizer::Tokanize($this->strInFix); if (!isset($arrTokens)) { throw new Exception("Unable to tokanize the expression!"); } if (count($arrTokens) <= 0) { throw new Exception("Unable to tokanize the expression!"); } //print_r($arrTokens); $myarrPostFix = $this->_InFixToPostFix($arrTokens); if (!isset($myarrPostFix)) { throw new Exception("Unable to convert the expression to postfix form!"); } if (count($myarrPostFix) <= 0) { throw new Exception("Unable to convert the expression to postfix form!"); } //print_r($myarrPostFix); return $myarrPostFix; }
/** * Uses the Toolset_Tokenizer to break down the expression, replace problematic operators by their text-only * equivalents and glue the expression back together. * * Side-effects: Loses custom whitespace characters. All operators (except parentheses) will be surrounded by spaces * while everywhere else the whitespace characters will be trimmed. * * Note: If an invalid expression is provided, it doesn't do anything with it. * * @param string $expression Condition expression. * @return string Equivalent expression but without <, <=, etc. * @since 2.0 */ protected function transform_operators_to_text_equivalents($expression) { try { // The expression may come directly from parse_str() which may add backslashes to quotes. The tokenizer // wouldn't survive that. $expression = stripslashes($expression); $toolset_bootstrap = Toolset_Common_Bootstrap::getInstance(); $toolset_bootstrap->register_parser(); $tokenizer = new Toolset_Tokenizer(); $tokens = $tokenizer->Tokanize($expression); $token_value_replacements = array('<' => 'lt', '>' => 'gt', '<=' => 'lte', '>=' => 'gte', '<>' => 'ne', '=' => 'eq'); $result = ''; foreach ($tokens as $token) { if ($token->isCompOp) { $token->val = wpcf_getarr($token_value_replacements, $token->val, $token->val); } if ($token->isCompOp || $token->isArithmeticOp || $token->isLogicOp) { $result .= ' ' . $token->val . ' '; } else { if ($token->isStringLiteral) { $result .= '\'' . $token->val . '\''; } else { $result .= $token->val; } } } return $result; } catch (Exception $e) { // Most probably we were unable to tokenize the expression. We give up. return $expression; } }