20#include "../../kernel.hpp"
38 bool bReturningLogicals =
false;
42 while (sLine.find(
'?', nPos) != string::npos)
44 nPos = sLine.find(
'?', nPos);
58 if (vTernary[0].find(
'"') != string::npos)
61 result = (bool)(vTernary[0].length() - 2);
96 if (sString.substr(nPos, 2) ==
"<>")
99 if (sString.substr(nPos, 4) ==
"<wp>")
102 if (sString.substr(nPos, 6) ==
"<this>")
105 if (sString.substr(nPos, 10) ==
"<loadpath>")
108 if (sString.substr(nPos, 10) ==
"<savepath>")
111 if (sString.substr(nPos, 10) ==
"<procpath>")
114 if (sString.substr(nPos, 10) ==
"<plotpath>")
117 if (sString.substr(nPos, 12) ==
"<scriptpath>")
135 bool bReturningLogicals =
false;
140 if (sLine.front() ==
'"' && sLine.back() ==
'"')
143 sLine = sLine.substr(1, sLine.length() - 2);
165 vector<string> vTernary;
166 size_t nTernaryStart = 0;
167 size_t nColonPosition = 0;
169 string sTernary = sLine.substr(nTernaryStart);
170 sLine.erase(nTernaryStart);
173 int nQuestionMarks = 0;
177 for (
size_t i = nPos; i < sTernary.length(); i++)
180 if (!(quotes % 2) && (sTernary[i] ==
'(' || sTernary[i] ==
'[' || sTernary[i] ==
'{'))
184 if (!(quotes % 2) && sTernary[i] ==
'?')
188 if (sTernary[i] ==
'"' && sTernary[i - 1] !=
'\\')
193 if (!(quotes % 2) && sTernary[i] ==
':')
211 vTernary.push_back(sTernary.substr(0, nPos));
212 vTernary.push_back(sTernary.substr(nPos + 1, nColonPosition - 1 - nPos));
213 vTernary.push_back(sTernary.substr(nColonPosition + 1));
215 nPos = nTernaryStart;
231 if (!sString.length())
236 for (
size_t i = 0; i < sString.length(); i++)
239 if (sString[i] ==
'"' && (!i || sString[i - 1] !=
'\\'))
246 if (sString[i] ==
'<')
261 if (sString.substr(i, 2) ==
"&&"
262 || sString.substr(i, 2) ==
"||"
263 || sString.substr(i, 2) ==
"<="
264 || sString.substr(i, 2) ==
">="
265 || sString.substr(i, 2) ==
"!="
266 || sString.substr(i, 2) ==
"=="
269 || sString[i] ==
'>')
296 if (sLine.find(
'"') == string::npos)
298 bReturningLogicals =
true;
311 if (sLine.find(
'(') != string::npos)
315 while (sLine.find(
'(', nPos) != string::npos)
317 nPos = sLine.find(
'(', nPos) + 1;
321 sLine = sLine.substr(0, nPos - 1)
330 if (sLine.find(
"&&") != string::npos)
334 while (sLine.find(
"&&", nPos) != string::npos)
336 nPos = sLine.find(
"&&", nPos) + 2;
343 bReturningLogicals =
true;
345 if (sLeft ==
"true" && sRight ==
"true")
347 else if (sLeft ==
"false" || sRight ==
"false")
351 _parser.
SetExpr(sLeft +
" && " + sRight);
359 if (sLine.find(
"|||") != string::npos)
363 while (sLine.find(
"|||", nPos) != string::npos)
365 nPos = sLine.find(
"|||", nPos) + 3;
372 bReturningLogicals =
true;
374 if ((sLeft ==
"true" && sRight ==
"false") || (sLeft ==
"false" && sRight ==
"true"))
376 else if (sLeft == sRight)
380 _parser.
SetExpr(sLeft +
" ||| " + sRight);
388 if (sLine.find(
"||") != string::npos)
392 while (sLine.find(
"||", nPos) != string::npos)
394 nPos = sLine.find(
"||", nPos) + 2;
401 bReturningLogicals =
true;
403 if (sLeft ==
"true" || sRight ==
"true")
405 else if (sLeft ==
"false" && sRight ==
"false")
409 _parser.
SetExpr(sLeft +
" || " + sRight);
419 for (
size_t i = 0; i < sLine.length(); i++)
421 if (sLine[i] ==
'"' && (!i || sLine[i - 1] !=
'\\'))
426 if (sLine.substr(i, 2) ==
"==")
428 bReturningLogicals =
true;
431 else if (sLine.substr(i, 2) ==
"!=")
433 bReturningLogicals =
true;
436 else if (sLine.substr(i, 2) ==
"<=")
438 bReturningLogicals =
true;
441 else if (sLine.substr(i, 2) ==
">=")
443 bReturningLogicals =
true;
446 else if (sLine[i] ==
'<')
448 bReturningLogicals =
true;
451 else if (sLine[i] ==
'>')
453 bReturningLogicals =
true;
481 for (
unsigned int i = 0; i < sExpr.length(); i++)
483 if (sExpr[i] ==
'"' && (!i || sExpr[i-1] !=
'\\'))
487 if (!(nQuotes % 2) && sExpr[i] ==
'+')
496 if (sLeft ==
"\"\"" && sRight !=
"\"\"")
501 else if (sLeft !=
"\"\"" && sRight ==
"\"\"")
506 else if (sLeft.
back() ==
'"' && sRight.
front() ==
'"')
519 else if (!(nQuotes % 2)
520 && (isdigit(sExpr[i]) || sExpr.compare(i, 3,
"inf") == 0 || sExpr.compare(i, 3,
"nan") == 0))
522 size_t nextPos = sExpr.find_first_not_of(
"0123456789Ee+-infa.", i);
524 if (nextPos == std::string::npos)
529 else if (!(nQuotes % 2) && isalpha(sExpr[i]))
std::string prepareComparisonValues(const std::string &_sLine)
Removes masked strings, strips spaces and removes surrounding quotation marks and concatenates the va...
void concatenateStrings(std::string &sExpr)
This member function performs the actual string concatenation of the passed string expression.
std::string evalStringLogic(std::string sLine, bool &bReturningLogicals)
This member function will evaluate logical string expressions in the passed command line.
size_t detectPathTokens(const std::string &sString, size_t nPos)
This member function is a helper for StringLogicParser::detectStringLogicals().
std::vector< std::string > getStringTernaryExpression(std::string &sLine, size_t &nPos)
This member function is a helper for StringLogicParser::evalStringLogic().
std::string evalStringTernary(std::string sLine)
This member function will evaluate the ternary operator for strings.
bool detectStringLogicals(const std::string &sString)
This member function is may detect logical expressions in the passed string expression.
static NumeReKernel * getInstance()
This static member function returns a a pointer to the singleton instance of the kernel.
void strip()
This member function shrinks the viewed section to remove all leading or trailing whitespace characte...
const char & back() const
This member function provides a const char reference to the last character in the viewed section.
const char & front() const
This member function provides a const char reference to the first character in the viewed section.
std::string to_string() const
This member function returns a copy of the viewed section of the string (via std::string::substr)....
size_t length() const
This member function simply returns the length of the viewed section.
This class is the immutable (const) version of a string view. It can be constructed from a MutableStr...
StringView subview(size_t pos=0, size_t len=std::string::npos) const
This member function creates a new StringView class instance using the selected position and length a...
Common exception class for all exceptions thrown in NumeRe.
void SetExpr(StringView a_sExpr)
Set the expression. Triggers first time calculation thus the creation of the bytecode and scanning of...
value_type Eval()
Single-value wrapper around the vectorized overload of this member function.
Mathematical expressions parser.
unsigned int getMatchingParenthesis(const StringView &)
Returns the position of the closing parenthesis.
void StripSpaces(std::string &)
Removes leading and trailing white spaces and tabulator characters.
string removeMaskedStrings(const string &sString)
This function removes the escape characters from the passed string.
std::string toString(int)
Converts an integer to a string without the Settings bloat.