forked from baidu/Familia
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.cpp
More file actions
23 lines (20 loc) · 729 Bytes
/
util.cpp
File metadata and controls
23 lines (20 loc) · 729 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Copyright (c) 2017, Baidu.com, Inc. All Rights Reserved
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "familia/util.h"
namespace familia {
void split(std::vector<std::string>& result, const std::string& text, char separator) {
size_t start = 0;
size_t end = 0;
if (text.empty()) {
return;
}
while ((end = text.find(separator, start)) != std::string::npos) {
std::string substr = text.substr(start, end - start);
result.push_back(std::move(substr));
start = end + 1;
}
// NOTE: 如果输入没有分割字符,则返回原输入
result.push_back(text.substr(start));
}
} // namespace familia