MCPcopy Create free account
hub / github.com/cvmfs/cvmfs / SplitStringBounded

Function SplitStringBounded

cvmfs/util/string.cc:311–340  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

309}
310
311vector<string> SplitStringBounded(unsigned max_chunks, const string &str,
312 char delim) {
313 vector<string> result;
314
315 // edge case... one chunk is always the whole string
316 if (1 == max_chunks) {
317 result.push_back(str);
318 return result;
319 }
320
321 // split the string
322 const unsigned size = str.size();
323 unsigned marker = 0;
324 unsigned chunks = 1;
325 unsigned i;
326 for (i = 0; i < size; ++i) {
327 if (str[i] == delim) {
328 result.push_back(str.substr(marker, i - marker));
329 marker = i + 1;
330
331 // we got what we want... good bye
332 if (++chunks == max_chunks)
333 break;
334 }
335 }
336
337 // push the remainings of the string and return
338 result.push_back(str.substr(marker));
339 return result;
340}
341
342vector<string> SplitStringMultiChar(const string &str, const string &delim) {
343 size_t pos_start = 0, pos_end = 0, delim_len = delim.length();

Callers 5

CheckGraftMethod · 0.85
SplitStringFunction · 0.85
MainMethod · 0.85
MainMethod · 0.85
TEST_FFunction · 0.85

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected