From acd57def4871dac8c6c1c6ebb642534d307ac518 Mon Sep 17 00:00:00 2001
From: Lorenzo Moneta <Lorenzo.Moneta@cern.ch>
Date: Tue, 21 Jul 2015 13:08:51 +0200
Subject: [PATCH] Add support for "--" as "- -" (ROOT-7471)

---
 hist/hist/src/TFormula.cxx  |  4 ++++
 test/TFormulaParsingTests.h | 17 +++++++++++++++--
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/hist/hist/src/TFormula.cxx b/hist/hist/src/TFormula.cxx
index 7b7950d9765..9fc7e219741 100644
--- a/hist/hist/src/TFormula.cxx
+++ b/hist/hist/src/TFormula.cxx
@@ -1177,7 +1177,10 @@ void TFormula::PreProcessFormula(TString &formula)
    HandlePolN(formula);
    HandleParametrizedFunctions(formula);
    HandleExponentiation(formula);
+   // "++" wil be dealt with Handle Linear 
    HandleLinear(formula);
+   // special case for "--"
+   formula.ReplaceAll("--","- -");
 }
 Bool_t TFormula::PrepareFormula(TString &formula)
 {
@@ -1269,6 +1272,7 @@ void TFormula::ExtractFunctors(TString &formula)
          continue;
       }
 
+
       //std::cout << "investigating character : " << i << " " << formula[i] << " of formula " << formula << std::endl;
       // look for variable and function names. They  start in C++ with alphanumeric characters
       if(isalpha(formula[i]) && !IsOperator(formula[i]))  // not really needed to check if operator (if isalpha is not an operator)
diff --git a/test/TFormulaParsingTests.h b/test/TFormulaParsingTests.h
index 735414bffc3..efc7dec836b 100644
--- a/test/TFormulaParsingTests.h
+++ b/test/TFormulaParsingTests.h
@@ -477,8 +477,8 @@ bool test28() {
 }
 
 bool test29() {
-   bool ok = true; 
    // test hexadecimal numbers 
+   bool ok = true; 
    TF1 f1("f1","x+[0]*0xaf");
    f1.SetParameter(0,2);
    ok &= (f1.Eval(3) == (3.+2*175.) );
@@ -492,7 +492,18 @@ bool test29() {
    return ok; 
 
 }
-   
+
+bool test30() {
+// handle -- (++ is in linear expressions)
+   bool ok = true;    
+   TF1 f1("f1","x--[0]");
+   f1.SetParameter(0,2);
+   ok &= (f1.Eval(3) == 5. );
+
+   return ok; 
+
+}
+
 
    
 void PrintError(int itest)  { 
@@ -540,6 +551,8 @@ int runTests(bool debug = false) {
    IncrTest(itest); if (!test26() ) { PrintError(itest); }
    IncrTest(itest); if (!test27() ) { PrintError(itest); }
    IncrTest(itest); if (!test28() ) { PrintError(itest); }
+   IncrTest(itest); if (!test29() ) { PrintError(itest); }
+   IncrTest(itest); if (!test30() ) { PrintError(itest); }
 
    std::cout << ".\n";
     
-- 
GitLab