64{
66 TString parStr(expression);
67
68 TRegexp specialChars("[+-/*%&=!><()|]+");
69 int lastIdx = -1;
70 do {
71
72 lastIdx = parStr.Index(specialChars, lastIdx+1);
73 if (lastIdx >= 0) {
74 bool needsReplacement = false;
75 if (lastIdx > 0) {
76
77 char isEscape = parStr[lastIdx-1];
78 if (isEscape == '\\') {
79
80
81 parStr = parStr.Remove(lastIdx-1, 1);
82 expr = expr.Remove(lastIdx-1, 1);
83 needsReplacement = false;
84 lastIdx--;
85 } else {
86 needsReplacement = true;
87 }
88 } else {
89
90 needsReplacement = true;
91 }
92
93 if (needsReplacement) {
94
95 parStr = parStr.Replace(lastIdx, 1, " ");
96 }
97 }
98 } while (lastIdx >= 0);
99
100 TMsgLogger mylogger( "RegularFormula" );
102 mylogger <<
kINFO <<
"Please be aware that Cling errors are expected and aren't inherently a problem" <<
GEndl;
103
104 TFormula analyzer("analyzer","1");
105 TObjArray* parArr = parStr.Tokenize(" ");
106 for (
int count(0),
i(0);
i<parArr->GetEntries(); ++
i) {
107 TString myPar = ((TObjString*)parArr->At(i))->GetString();
108 if ( 0==analyzer.Compile(myPar.Data()) ||
109 0==analyzer.Compile(Form("%s(1)",myPar.Data())) ) {
110 continue;
111 } else {
112 std::list<TString>::iterator itrF = std::find(
m_par.begin(),
m_par.end(),myPar);
113 if (itrF==
m_par.end()) {
114 expr = expr.ReplaceAll(myPar,Form(
"[%d]",
count));
115 m_par.push_back(myPar);
117 }
118 }
119 }
120 delete parArr;
121
122 mylogger <<
kINFO <<
"Number of interpreted input parameters : " <<
m_par.size() <<
GEndl;
123 mylogger <<
kINFO <<
"Parsed regular expression : " << expr <<
GEndl;
124}
int count(std::string s, const std::string ®x)
count how many occurances of a regx are in a string