Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 294B41008D for ; Tue, 9 Jul 2013 08:27:25 +0000 (UTC) Received: (qmail 72196 invoked by uid 500); 9 Jul 2013 08:27:24 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 72083 invoked by uid 500); 9 Jul 2013 08:27:24 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 72059 invoked by uid 99); 9 Jul 2013 08:27:22 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 Jul 2013 08:27:22 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 9887B889266; Tue, 9 Jul 2013 08:27:22 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: davsclaus@apache.org To: commits@camel.apache.org Date: Tue, 09 Jul 2013 08:27:23 -0000 Message-Id: <87e48ed796784d9797dd1cb153baa911@git.apache.org> In-Reply-To: <126eff60ef1b4ab9b53b7c1efd8f8dc1@git.apache.org> References: <126eff60ef1b4ab9b53b7c1efd8f8dc1@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/2] git commit: CAMEL-6414: The unary operators in Simple is now only applied on functions CAMEL-6414: The unary operators in Simple is now only applied on functions Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/deb4a1e7 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/deb4a1e7 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/deb4a1e7 Branch: refs/heads/camel-2.11.x Commit: deb4a1e7ba343d143e74ec8b315d8e6c1d3466fa Parents: e75fc01 Author: Claus Ibsen Authored: Tue Jul 9 10:22:30 2013 +0200 Committer: Claus Ibsen Committed: Tue Jul 9 10:27:01 2013 +0200 ---------------------------------------------------------------------- .../camel/language/simple/SimpleTokenizer.java | 35 ++++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/deb4a1e7/camel-core/src/main/java/org/apache/camel/language/simple/SimpleTokenizer.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/language/simple/SimpleTokenizer.java b/camel-core/src/main/java/org/apache/camel/language/simple/SimpleTokenizer.java index 9d59507..cd38aea 100644 --- a/camel-core/src/main/java/org/apache/camel/language/simple/SimpleTokenizer.java +++ b/camel-core/src/main/java/org/apache/camel/language/simple/SimpleTokenizer.java @@ -230,20 +230,35 @@ public final class SimpleTokenizer { private static boolean acceptToken(SimpleTokenType token, String text, String expression, int index) { if (token.isUnary() && text.startsWith(token.getValue())) { - // special check for unary as the previous must be a function end, and the next a whitespace - // to ensure unary operators is only applied on functions as intended - int len = token.getValue().length(); - char previous = ' '; - if (index > 0) { - previous = expression.charAt(index - 1); + SimpleTokenType functionEndToken = getFunctionEndToken(); + if (functionEndToken != null) { + int endLen = functionEndToken.getValue().length(); + + // special check for unary as the previous must be a function end, and the next a whitespace + // to ensure unary operators is only applied on functions as intended + int len = token.getValue().length(); + + String previous = ""; + if (index - endLen >= 0) { + previous = expression.substring(index - endLen, index); + } + String after = text.substring(len); + boolean whiteSpace = ObjectHelper.isEmpty(after) || after.startsWith(" "); + boolean functionEnd = previous.equals(functionEndToken.getValue()); + return functionEnd && whiteSpace; } - String after = text.substring(len); - boolean whiteSpace = ObjectHelper.isEmpty(after) || after.startsWith(" "); - boolean functionEnd = previous == '}'; - return functionEnd && whiteSpace; } return text.startsWith(token.getValue()); } + private static SimpleTokenType getFunctionEndToken() { + for (SimpleTokenType token : KNOWN_TOKENS) { + if (token.isFunctionEnd()) { + return token; + } + } + return null; + } + }