MCPcopy Create free account
hub / github.com/apache/trafficserver / operator()

Method operator()

src/tsutil/ts_unit_parser.cc:33–65  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31{
32
33auto
34UnitParser::operator()(swoc::TextView const &src) const noexcept -> Rv<value_type>
35{
36 value_type zret = 0;
37 TextView text = src; // Keep @a src around to report error offsets.
38
39 while (text.ltrim_if(&isspace)) {
40 TextView parsed;
41 auto n = swoc::svtou(text, &parsed);
42 if (parsed.empty()) {
43 return Errata("Required count not found at offset {}", text.data() - src.data());
44 } else if (n == std::numeric_limits<decltype(n)>::max()) {
45 return Errata("Count at offset {} was out of bounds", text.data() - src.data());
46 }
47 text.remove_prefix(parsed.size());
48 auto ptr = text.ltrim_if(&isspace).data(); // save for error reporting.
49 // Everything up to the next digit or whitespace.
50 auto unit = text.clip_prefix_of([](char c) { return !(isspace(c) || isdigit(c)); });
51 if (unit.empty()) {
52 if (_unit_required_p) {
53 return Errata("Required unit not found at offset {}", ptr - src.data());
54 }
55 } else {
56 auto mult = _units[unit]; // What's the multiplier?
57 if (mult == 0) {
58 return Errata("Unknown unit \"{}\" at offset {}", unit, ptr - src.data());
59 }
60 n *= mult;
61 }
62 zret += n;
63 }
64 return zret;
65}
66
67// Concrete unit parsers.
68

Callers

nothing calls this directly

Calls 7

svtouFunction · 0.85
ErrataClass · 0.85
clip_prefix_ofMethod · 0.80
emptyMethod · 0.45
dataMethod · 0.45
remove_prefixMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected