MCPcopy Create free account
hub / github.com/Snapchat/Valdi / parse

Method parse

valdi/src/valdi/runtime/Context/ViewNodePath.cpp:20–51  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18ViewNodePath::ViewNodePath(std::vector<ViewNodePathEntry> entries) : _entries(std::move(entries)) {}
19
20Result<ViewNodePath> ViewNodePath::parse(const std::string_view& str) {
21 std::vector<ViewNodePathEntry> entries;
22
23 TextParser parser(str);
24
25 while (!parser.isAtEnd()) {
26 if (!entries.empty()) {
27 if (!parser.tryParse('.') && !parser.tryParse(':')) {
28 parser.setErrorAtCurrentPosition("Missing dot or colon separator");
29 return parser.getError();
30 }
31 }
32
33 auto identifier = parser.parseIdentifier();
34 if (!identifier) {
35 return parser.getError();
36 }
37
38 int itemIndex = 0;
39 if (parser.tryParse('[')) {
40 auto itemIndexResult = parser.parseInt();
41 if (!itemIndexResult || !parser.parse(']')) {
42 return parser.getError();
43 }
44 itemIndex = itemIndexResult.value();
45 }
46
47 entries.emplace_back(StringCache::getGlobal().makeString(identifier.value()), itemIndex);
48 }
49
50 return ViewNodePath(std::move(entries));
51}
52
53const std::vector<ViewNodePathEntry>& ViewNodePath::getEntries() const {
54 return _entries;

Callers

nothing calls this directly

Calls 11

getGlobalFunction · 0.85
makeStringMethod · 0.80
ViewNodePathClass · 0.70
valueMethod · 0.65
isAtEndMethod · 0.45
emptyMethod · 0.45
tryParseMethod · 0.45
getErrorMethod · 0.45
parseIdentifierMethod · 0.45
parseIntMethod · 0.45

Tested by

no test coverage detected