MCPcopy Create free account
hub / github.com/VCVRack/Rack / split

Function split

src/string.cpp:304–330  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

302
303
304std::vector<std::string> split(const std::string& s, const std::string& separator, size_t maxTokens) {
305 if (separator.empty())
306 throw Exception("split(): separator cannot be empty string");
307 // Special case of empty string
308 if (s == "")
309 return {};
310 if (maxTokens == 1)
311 return {s};
312
313 std::vector<std::string> v;
314 size_t sepLen = separator.size();
315 size_t start = 0;
316 size_t end;
317 while ((end = s.find(separator, start)) != std::string::npos) {
318 // Add token to vector
319 std::string token = s.substr(start, end - start);
320 v.push_back(token);
321 // Don't include delimiter
322 start = end + sepLen;
323 // Stop searching for tokens if we're at the token limit
324 if (maxTokens == v.size() + 1)
325 break;
326 }
327
328 v.push_back(s.substr(start));
329 return v;
330}
331
332
333std::string formatTime(const char* format, double timestamp) {

Callers 1

VersionMethod · 0.85

Calls 3

ExceptionClass · 0.85
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected