MCPcopy Create free account
hub / github.com/apache/trafficserver / evaluateBignum

Function evaluateBignum

plugins/prefetch/evaluate.cc:173–222  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

171}
172
173String
174evaluateBignum(const StringView view)
175{
176 String result("0");
177
178 StringView v = view;
179
180 uint32_t fwide = 0;
181 StringView::size_type pos = v.find_first_of(':');
182 if (v.npos != pos) {
183 std::from_chars(v.begin(), v.begin() + pos, fwide);
184 PrefetchDebug("statement: '%.*s', formatting length: %" PRIu32, (int)pos, v.data(), fwide);
185 v = v.substr(pos + 1);
186 }
187
188 pos = v.find_first_of("+-");
189 if (v.npos == pos) {
190 if (is_valid_digits(v)) {
191 result.assign(v);
192 }
193 } else {
194 StringView vleft = v.substr(0, pos);
195 if (!is_valid_digits(vleft)) {
196 vleft = svzero;
197 }
198 StringView vrite = v.substr(pos + 1);
199 if (!is_valid_digits(vrite)) {
200 vrite = svzero;
201 }
202 if ('+' == v[pos]) {
203 PrefetchDebug("Adding %.*s and %.*s", (int)vleft.length(), vleft.data(), (int)vrite.length(), vrite.data());
204 result = add(vleft, vrite);
205 } else {
206 PrefetchDebug("Subbing %.*s and %.*s", (int)vleft.length(), vleft.data(), (int)vrite.length(), vrite.data());
207 result = sub(vleft, vrite);
208 }
209 }
210
211 // wipe out leading zeros
212 while (1 < result.length() && fwide < result.length() && '0' == result.front()) {
213 result.erase(0, 1);
214 }
215
216 // Left pad out with zeros
217 if (result.length() < fwide) {
218 result.insert(0, fwide - result.length(), '0');
219 }
220
221 return result;
222}
223} // namespace
224
225/**

Callers 1

evaluateFunction · 0.85

Calls 10

is_valid_digitsFunction · 0.85
addFunction · 0.85
subFunction · 0.85
beginMethod · 0.45
dataMethod · 0.45
substrMethod · 0.45
assignMethod · 0.45
lengthMethod · 0.45
eraseMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected