MCPcopy Create free account
hub / github.com/JRickey/BattleShip / parse_frame_list

Function parse_frame_list

port/renderdoc_trigger.cpp:46–85  ·  view source on GitHub ↗

Parse "10,55,100" or "10, 55 ,100" into a set . Skips empty entries and non-numeric tokens silently.

Source from the content-addressed store, hash-verified

44// Parse "10,55,100" or "10, 55 ,100" into a set<unsigned int>.
45// Skips empty entries and non-numeric tokens silently.
46std::set<unsigned int> parse_frame_list(const char *s)
47{
48 std::set<unsigned int> out;
49 if (s == nullptr) {
50 return out;
51 }
52
53 std::string token;
54 auto flush = [&out, &token]() {
55 if (token.empty()) {
56 return;
57 }
58 // Trim whitespace
59 size_t start = token.find_first_not_of(" \t\r\n");
60 size_t end = token.find_last_not_of(" \t\r\n");
61 if (start == std::string::npos) {
62 token.clear();
63 return;
64 }
65 std::string trimmed = token.substr(start, end - start + 1);
66 token.clear();
67
68 // Parse unsigned int
69 char *endp = nullptr;
70 unsigned long v = std::strtoul(trimmed.c_str(), &endp, 10);
71 if (endp != nullptr && *endp == '\0') {
72 out.insert(static_cast<unsigned int>(v));
73 }
74 };
75
76 for (const char *p = s; *p != '\0'; ++p) {
77 if (*p == ',') {
78 flush();
79 } else {
80 token.push_back(*p);
81 }
82 }
83 flush();
84 return out;
85}
86
87} // namespace
88

Callers 1

portRenderDocInitFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected