MCPcopy Create free account
hub / github.com/chen3feng/toft / SplitStringKeepEmpty

Function SplitStringKeepEmpty

base/string/algorithm.cpp:357–379  ·  view source on GitHub ↗

功能: 把一个字符串划分成多个字符串 * 参数: * 输入参数 const StringPiece& full 主字符串 * 输入参数 const StringPiece& delim 字符串分界符号 * 输出参数 std::vector & result 分解后的结果 */

Source from the content-addressed store, hash-verified

355 * 输出参数 std::vector<std::string>& result 分解后的结果
356 */
357void SplitStringKeepEmpty(
358 const StringPiece& full,
359 char delim,
360 std::vector<std::string>* result)
361{
362 result->clear();
363
364 if (full.empty())
365 return;
366
367 size_t prev_pos = 0;
368 size_t pos;
369 std::string token;
370 while ((pos = full.find(delim, prev_pos)) != std::string::npos)
371 {
372 token.assign(full.data() + prev_pos, pos - prev_pos);
373 result->push_back(token);
374 prev_pos = pos + 1;
375 }
376
377 token.assign(full.data() + prev_pos, full.length() - prev_pos);
378 result->push_back(token);
379}
380
381void SplitStringKeepEmpty(
382 const StringPiece& full,

Callers 2

NormalizeMethod · 0.85
TESTFunction · 0.85

Calls 7

findMethod · 0.80
assignMethod · 0.80
dataMethod · 0.80
push_backMethod · 0.80
clearMethod · 0.45
emptyMethod · 0.45
lengthMethod · 0.45

Tested by 1

TESTFunction · 0.68