Use string_view as input type for internal string utilities
Bug: None Change-Id: I2bfdaf4e7fac109842cc9fde8dfa28ab4961c3fd Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/232127 Reviewed-by: Harald Alvestrand <hta@webrtc.org> Commit-Queue: Niels Moller <nisse@webrtc.org> Cr-Commit-Position: refs/heads/main@{#35022}
This commit is contained in:
committed by
WebRTC LUCI CQ
parent
d14f98f635
commit
4420380f38
@ -152,7 +152,7 @@ size_t hex_decode_with_delimiter(char* buffer,
|
||||
source.length(), delimiter);
|
||||
}
|
||||
|
||||
size_t tokenize(const std::string& source,
|
||||
size_t tokenize(absl::string_view source,
|
||||
char delimiter,
|
||||
std::vector<std::string>* fields) {
|
||||
fields->clear();
|
||||
@ -160,18 +160,18 @@ size_t tokenize(const std::string& source,
|
||||
for (size_t i = 0; i < source.length(); ++i) {
|
||||
if (source[i] == delimiter) {
|
||||
if (i != last) {
|
||||
fields->push_back(source.substr(last, i - last));
|
||||
fields->emplace_back(source.substr(last, i - last));
|
||||
}
|
||||
last = i + 1;
|
||||
}
|
||||
}
|
||||
if (last != source.length()) {
|
||||
fields->push_back(source.substr(last, source.length() - last));
|
||||
fields->emplace_back(source.substr(last, source.length() - last));
|
||||
}
|
||||
return fields->size();
|
||||
}
|
||||
|
||||
bool tokenize_first(const std::string& source,
|
||||
bool tokenize_first(absl::string_view source,
|
||||
const char delimiter,
|
||||
std::string* token,
|
||||
std::string* rest) {
|
||||
@ -183,12 +183,12 @@ bool tokenize_first(const std::string& source,
|
||||
|
||||
// Look for additional occurrances of delimiter.
|
||||
size_t right_pos = left_pos + 1;
|
||||
while (source[right_pos] == delimiter) {
|
||||
while (right_pos < source.size() && source[right_pos] == delimiter) {
|
||||
right_pos++;
|
||||
}
|
||||
|
||||
*token = source.substr(0, left_pos);
|
||||
*rest = source.substr(right_pos);
|
||||
*token = std::string(source.substr(0, left_pos));
|
||||
*rest = std::string(source.substr(right_pos));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -214,7 +214,7 @@ std::string join(const std::vector<std::string>& source, char delimiter) {
|
||||
return joined_string;
|
||||
}
|
||||
|
||||
size_t split(const std::string& source,
|
||||
size_t split(absl::string_view source,
|
||||
char delimiter,
|
||||
std::vector<std::string>* fields) {
|
||||
RTC_DCHECK(fields);
|
||||
@ -222,11 +222,11 @@ size_t split(const std::string& source,
|
||||
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));
|
||||
fields->emplace_back(source.substr(last, i - last));
|
||||
last = i + 1;
|
||||
}
|
||||
}
|
||||
fields->push_back(source.substr(last, source.length() - last));
|
||||
fields->emplace_back(source.substr(last));
|
||||
return fields->size();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user