mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-13 05:40:42 +01:00
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:
parent
d14f98f635
commit
4420380f38
2 changed files with 14 additions and 13 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/types/optional.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/string_to_number.h"
|
||||
|
@ -62,20 +63,20 @@ std::string join(const std::vector<std::string>& source, char delimiter);
|
|||
|
||||
// Splits the source string into multiple fields separated by delimiter,
|
||||
// with duplicates of delimiter creating empty fields.
|
||||
size_t split(const std::string& source,
|
||||
size_t split(absl::string_view source,
|
||||
char delimiter,
|
||||
std::vector<std::string>* fields);
|
||||
|
||||
// Splits the source string into multiple fields separated by delimiter,
|
||||
// with duplicates of delimiter ignored. Trailing delimiter ignored.
|
||||
size_t tokenize(const std::string& source,
|
||||
size_t tokenize(absl::string_view source,
|
||||
char delimiter,
|
||||
std::vector<std::string>* fields);
|
||||
|
||||
// Extract the first token from source as separated by delimiter, with
|
||||
// duplicates of delimiter ignored. Return false if the delimiter could not be
|
||||
// found, otherwise return true.
|
||||
bool tokenize_first(const std::string& source,
|
||||
bool tokenize_first(absl::string_view source,
|
||||
const char delimiter,
|
||||
std::string* token,
|
||||
std::string* rest);
|
||||
|
|
Loading…
Reference in a new issue