-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
update logic of REST_StringHelper::isAExpression() #188
Closed
Closed
Changes from 2 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
6491041
update logic of expression identification.
nkx111 a31104f
StringToLong(): handles correctly scientific notation
nkx111 6603cda
update TRestStringHelper
73dc883
update TRestStringHelper
5e9c15c
fix line endings
a4efadd
using const string
ce7f6dd
Merge branch 'master' into nkx111-patch-3
jgalan 8a4fc35
TRestThread no longer inherites from TRestMetadata; added compression…
nkx111 9323726
TrestAnalysisTree now supports operation under chain mode
nkx111 645a1b3
TRestProcessRunner updated to auto split files
nkx111 1bf1808
TRestRun supported to read splitted data files
nkx111 84fd1a0
restRoot supported to read splitted data files
nkx111 783e6df
TRestReflector::Converter adds both ROOT def type(Long64_t) and stand…
nkx111 89b3aef
fixing g4 selection pipeline
nkx111 0519166
ci: ctest job is after build, to avoid PCM warning
nkx111 7062418
TRestDataBase: updated IsZombie() logic
nkx111 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,28 +21,56 @@ using namespace std; | |
/// \brief Returns 1 only if valid mathematical expression keywords (or numbers) | ||
/// are found in the string **in**. If not it returns 0. | ||
/// | ||
/// By logic, mathematical expressions must have: +-*/e^% in the middle, or % in the end, or math functions in the beginning. | ||
/// despite those symbols, the string should be purely numeric. | ||
/// example: | ||
/// 1+1 : expression | ||
/// sin(1.5) : expression | ||
/// 123456789 : not expression, It is a pure number that can be directly parsed. | ||
Int_t REST_StringHelper::isAExpression(string in) { | ||
string temp = in; | ||
vector<string> replace{"sqrt", "log", "exp", "gaus", "cos", "sin", "tan", "atan", "acos", "asin"}; | ||
for (int i = 0; i < replace.size(); i++) { | ||
temp = Replace(temp, replace[i], "0", 0); | ||
bool symbol = false; | ||
bool numeric = false; | ||
|
||
if (in.length() < 2) // minimum expression: 3% | ||
return 0; | ||
|
||
vector<string> funcs{"sqrt", "log", "exp", "gaus", "cos", "sin", "tan", "atan", "acos", "asin"}; | ||
for (int i = 0; i < funcs.size(); i++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if (in.find(funcs[i]) != std::string::npos) { | ||
symbol = true; | ||
break; | ||
} | ||
} | ||
|
||
if (temp.length() == 0) | ||
return 0; | ||
else if (temp.length() == 1) { | ||
if (temp.find_first_not_of("0123456789") == std::string::npos) { | ||
return 1; | ||
} else { | ||
return 0; | ||
if (!symbol) { | ||
int pos = in.find_first_of("+-*/e^%"); | ||
if (pos > 0 && pos < in.size() - 1) { | ||
symbol = true; | ||
} | ||
} | ||
|
||
if (!symbol) { | ||
int pos = in.find_first_of("%"); | ||
if (pos == in.size() - 1) { | ||
symbol = true; | ||
} | ||
} | ||
|
||
if (symbol) { | ||
string temp = in; | ||
for (int i = 0; i < funcs.size(); i++) { | ||
temp = Replace(temp, funcs[i], "0", 0); | ||
} | ||
} else { | ||
if (temp.find_first_not_of("-0123456789e+*/.,)( ^%") == std::string::npos) { | ||
if (temp.find("/") == 0 || temp.find("./") == 0 || temp.find("../") == 0) | ||
return 0; // identify path | ||
return 1; | ||
} | ||
} | ||
else | ||
{ | ||
return 0; | ||
} | ||
|
||
return 0; | ||
} | ||
|
@@ -507,6 +535,10 @@ Bool_t REST_StringHelper::StringToBool(std::string in) { | |
} | ||
|
||
Long64_t REST_StringHelper::StringToLong(std::string in) { | ||
if (in.find_first_of("eE") != string::npos) { | ||
// in case for scientific numbers | ||
return (Long64_t)StringToDouble(in); | ||
} | ||
stringstream strIn; | ||
strIn << in; | ||
long long llNum; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
REST_StringHelper::isAExpression(const string& in)