MCPcopy Create free account
hub / github.com/catboost/catboost / FindOperation

Function FindOperation

library/cpp/expression/expression.cpp:81–116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

79 std::numeric_limits<int>::max()};
80
81static 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
118template <typename T>
119T ToNumeric(const TString& str) {

Callers 2

CalcExpressionFunction · 0.85
BuildExpressionMethod · 0.85

Calls 2

FastHasPrefixFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected