Introduce a variant of rtc::split that returns a vector of string_view
Intended to be compatible with absl::StrSplit, but without the binary cost of that dependency. Bug: webrtc:13579 Change-Id: I167726903d74b8d5f299886cfb3e5d60610ddb93 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/247185 Reviewed-by: Ali Tofigh <alito@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Commit-Queue: Niels Moller <nisse@webrtc.org> Cr-Commit-Position: refs/heads/main@{#35780}
This commit is contained in:

committed by
WebRTC LUCI CQ

parent
3a88dd99c7
commit
2d3186e001
@ -214,19 +214,27 @@ std::string join(const std::vector<std::string>& source, char delimiter) {
|
||||
return joined_string;
|
||||
}
|
||||
|
||||
std::vector<absl::string_view> split(absl::string_view source, char delimiter) {
|
||||
std::vector<absl::string_view> fields;
|
||||
size_t last = 0;
|
||||
for (size_t i = 0; i < source.length(); ++i) {
|
||||
if (source[i] == delimiter) {
|
||||
fields.push_back(source.substr(last, i - last));
|
||||
last = i + 1;
|
||||
}
|
||||
}
|
||||
fields.push_back(source.substr(last));
|
||||
return fields;
|
||||
}
|
||||
|
||||
size_t split(absl::string_view source,
|
||||
char delimiter,
|
||||
std::vector<std::string>* fields) {
|
||||
RTC_DCHECK(fields);
|
||||
fields->clear();
|
||||
size_t last = 0;
|
||||
for (size_t i = 0; i < source.length(); ++i) {
|
||||
if (source[i] == delimiter) {
|
||||
fields->emplace_back(source.substr(last, i - last));
|
||||
last = i + 1;
|
||||
}
|
||||
for (const absl::string_view field_view : split(source, delimiter)) {
|
||||
fields->emplace_back(field_view);
|
||||
}
|
||||
fields->emplace_back(source.substr(last));
|
||||
return fields->size();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user