功能: 把一个字符串划分成多个字符串 * 参数: * 输入参数 const StringPiece& full 主字符串 * 输入参数 const StringPiece& delim 字符串分界符号 * 输出参数 std::vector & result 分解后的结果 */
| 355 | * 输出参数 std::vector<std::string>& result 分解后的结果 |
| 356 | */ |
| 357 | void 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 | |
| 381 | void SplitStringKeepEmpty( |
| 382 | const StringPiece& full, |