| 79 | std::numeric_limits<int>::max()}; |
| 80 | |
| 81 | static bool FindOperation(const char* expr, size_t a, size_t b, size_t& oa, size_t& ob, TExpressionOperation& oper) { |
| 82 | size_t balance = 0; |
| 83 | bool found = false; |
| 84 | oper = EO_END; |
| 85 | for (size_t i = b; i > a; --i) { |
| 86 | if (expr[i - 1] == '"') { |
| 87 | for (--i; i > a; --i) { |
| 88 | if (expr[i - 1] == '"') { |
| 89 | break; |
| 90 | } |
| 91 | } |
| 92 | } else if (expr[i - 1] == ')') { |
| 93 | ++balance; |
| 94 | } else if (expr[i - 1] == '(') { |
| 95 | if (balance == 0) { |
| 96 | ythrow yexception() << "CalcExpression error: bad brackets balance"; |
| 97 | } |
| 98 | --balance; |
| 99 | } else if (balance == 0) { |
| 100 | for (TExpressionOperation o = EO_BEGIN; OperationsPriority[o] < OperationsPriority[oper]; o = static_cast<TExpressionOperation>(o + 1)) { |
| 101 | TStringBuf suffix(&expr[i - 1], b - i + 1); |
| 102 | if (FastHasPrefix(suffix, OperationsStrings[o])) { |
| 103 | ob = i + OperationsStrings[o].size() - 1; |
| 104 | oper = o; |
| 105 | found = true; |
| 106 | oa = i - 1; |
| 107 | break; |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | if (found && OperationsPriority[oper] == OperationsPriority[EO_BEGIN]) { |
| 112 | break; |
| 113 | } |
| 114 | } |
| 115 | return found; |
| 116 | } |
| 117 | |
| 118 | template <typename T> |
| 119 | T ToNumeric(const TString& str) { |
no test coverage detected