Adopt absl::string_view in rtc_base/string_encode.*
Bug: webrtc:13579
Change-Id: If52108d151a12bde0e8d552ce7940948c08cef3a
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/256812
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Niels Moller <nisse@webrtc.org>
Reviewed-by: Jakob Ivarsson‎ <jakobi@webrtc.org>
Reviewed-by: Per Kjellander <perkj@webrtc.org>
Commit-Queue: Ali Tofigh <alito@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#36424}
diff --git a/rtc_base/string_encode.h b/rtc_base/string_encode.h
index 87c5bc8..1901505 100644
--- a/rtc_base/string_encode.h
+++ b/rtc_base/string_encode.h
@@ -19,6 +19,7 @@
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
+#include "api/array_view.h"
#include "rtc_base/checks.h"
#include "rtc_base/string_to_number.h"
@@ -29,29 +30,18 @@
//////////////////////////////////////////////////////////////////////
std::string hex_encode(absl::string_view str);
-std::string hex_encode(const char* source, size_t srclen);
-std::string hex_encode_with_delimiter(const char* source,
- size_t srclen,
- char delimiter);
+std::string hex_encode_with_delimiter(absl::string_view source, char delimiter);
// hex_decode converts ascii hex to binary.
-size_t hex_decode(char* buffer,
- size_t buflen,
- const char* source,
- size_t srclen);
+size_t hex_decode(ArrayView<char> buffer, absl::string_view source);
// hex_decode, assuming that there is a delimiter between every byte
// pair.
// `delimiter` == 0 means no delimiter
// If the buffer is too short or the data is invalid, we return 0.
-size_t hex_decode_with_delimiter(char* buffer,
- size_t buflen,
- const char* source,
- size_t srclen,
+size_t hex_decode_with_delimiter(ArrayView<char> buffer,
+ absl::string_view source,
char delimiter);
-
-// Helper functions for hex_decode.
-size_t hex_decode(char* buffer, size_t buflen, absl::string_view source);
size_t hex_decode_with_delimiter(char* buffer,
size_t buflen,
absl::string_view source,
@@ -88,8 +78,10 @@
// TODO(jonasolsson): Remove these when absl::StrCat becomes available.
std::string ToString(bool b);
-std::string ToString(const char* s);
std::string ToString(absl::string_view s);
+// The const char* overload is needed for correct overload resolution because of
+// the const void* version of ToString() below.
+std::string ToString(const char* s);
std::string ToString(short s);
std::string ToString(unsigned short s);
@@ -109,7 +101,7 @@
typename std::enable_if<std::is_arithmetic<T>::value &&
!std::is_same<T, bool>::value,
int>::type = 0>
-static bool FromString(const std::string& s, T* t) {
+static bool FromString(absl::string_view s, T* t) {
RTC_DCHECK(t);
absl::optional<T> result = StringToNumber<T>(s);
@@ -119,10 +111,10 @@
return result.has_value();
}
-bool FromString(const std::string& s, bool* b);
+bool FromString(absl::string_view s, bool* b);
template <typename T>
-static inline T FromString(const std::string& str) {
+static inline T FromString(absl::string_view str) {
T val;
FromString(str, &val);
return val;