Use consistent syntax for constructing std::strings from absl::string_views Bug: webrtc:13579 Change-Id: Ifaf9901972a39217accd9ef0111f01de9f074058 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/269080 Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org> Commit-Queue: Ali Tofigh <alito@webrtc.org> Cr-Commit-Position: refs/heads/main@{#37602}
diff --git a/rtc_base/checks.cc b/rtc_base/checks.cc index d6974d7..b22dbd4 100644 --- a/rtc_base/checks.cc +++ b/rtc_base/checks.cc
@@ -41,7 +41,7 @@ RTC_NORETURN void WriteFatalLogAndAbort(absl::string_view output) { #if defined(WEBRTC_ANDROID) - std::string output_str = std::string(output); + std::string output_str(output); __android_log_print(ANDROID_LOG_ERROR, RTC_LOG_TAG_ANDROID, "%s\n", output_str.c_str()); #endif
diff --git a/rtc_base/experiments/encoder_info_settings.cc b/rtc_base/experiments/encoder_info_settings.cc index a74eb50..8af52d6 100644 --- a/rtc_base/experiments/encoder_info_settings.cc +++ b/rtc_base/experiments/encoder_info_settings.cc
@@ -175,7 +175,7 @@ [](BitrateLimit* b) { return &b->max_bitrate_bps; })}, {}); - std::string name_str = std::string(name); + std::string name_str(name); if (field_trial::FindFullName(name_str).empty()) { // Encoder name not found, use common string applying to all encoders. name_str = "WebRTC-GetEncoderInfoOverride";
diff --git a/rtc_base/file_rotating_stream.cc b/rtc_base/file_rotating_stream.cc index c529b5b..c56396f 100644 --- a/rtc_base/file_rotating_stream.cc +++ b/rtc_base/file_rotating_stream.cc
@@ -130,7 +130,7 @@ std::vector<std::string> GetFilesWithPrefix(absl::string_view directory, absl::string_view prefix) { RTC_DCHECK(absl::EndsWith(directory, "/")); - std::string directory_str = std::string(directory); + std::string directory_str(directory); DIR* dir = ::opendir(directory_str.c_str()); if (dir == nullptr) return {};
diff --git a/rtc_base/logging.cc b/rtc_base/logging.cc index acf4263..30b3b97 100644 --- a/rtc_base/logging.cc +++ b/rtc_base/logging.cc
@@ -344,14 +344,14 @@ } #if defined(WEBRTC_ANDROID) -void LogMessage::OutputToDebug(absl::string_view str, +void LogMessage::OutputToDebug(absl::string_view msg, LoggingSeverity severity, const char* tag) { #else -void LogMessage::OutputToDebug(absl::string_view str, +void LogMessage::OutputToDebug(absl::string_view msg, LoggingSeverity severity) { #endif - std::string str_str = std::string(str); + std::string msg_str(msg); bool log_to_stderr = log_to_stderr_; #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) && defined(NDEBUG) // On the Mac, all stderr output goes to the Console log and causes clutter. @@ -376,13 +376,13 @@ #if defined(WEBRTC_WIN) // Always log to the debugger. // Perhaps stderr should be controlled by a preference, as on Mac? - OutputDebugStringA(str_str.c_str()); + OutputDebugStringA(msg_str.c_str()); if (log_to_stderr) { // This handles dynamically allocated consoles, too. if (HANDLE error_handle = ::GetStdHandle(STD_ERROR_HANDLE)) { log_to_stderr = false; DWORD written = 0; - ::WriteFile(error_handle, str.data(), static_cast<DWORD>(str.size()), + ::WriteFile(error_handle, msg.data(), static_cast<DWORD>(msg.size()), &written, 0); } } @@ -411,19 +411,19 @@ prio = ANDROID_LOG_UNKNOWN; } - int size = str.size(); + int size = msg.size(); int line = 0; int idx = 0; const int max_lines = size / kMaxLogLineSize + 1; if (max_lines == 1) { - __android_log_print(prio, tag, "%.*s", size, str_str.c_str()); + __android_log_print(prio, tag, "%.*s", size, msg_str.c_str()); } else { while (size > 0) { const int len = std::min(size, kMaxLogLineSize); - // Use the size of the string in the format (str may have \0 in the + // Use the size of the string in the format (msg may have \0 in the // middle). __android_log_print(prio, tag, "[%d/%d] %.*s", line + 1, max_lines, len, - str_str.c_str() + idx); + msg_str.c_str() + idx); idx += len; size -= len; ++line; @@ -431,7 +431,7 @@ } #endif // WEBRTC_ANDROID if (log_to_stderr) { - fprintf(stderr, "%s", str_str.c_str()); + fprintf(stderr, "%s", msg_str.c_str()); fflush(stderr); } }
diff --git a/rtc_base/net_helpers.cc b/rtc_base/net_helpers.cc index f092989..73fe862 100644 --- a/rtc_base/net_helpers.cc +++ b/rtc_base/net_helpers.cc
@@ -41,7 +41,7 @@ } int inet_pton(int af, absl::string_view src, void* dst) { - std::string src_str = std::string(src); + std::string src_str(src); #if defined(WEBRTC_WIN) return win32_inet_pton(af, src_str.c_str(), dst); #else
diff --git a/rtc_base/ssl_identity.cc b/rtc_base/ssl_identity.cc index 984979a..3b4232b 100644 --- a/rtc_base/ssl_identity.cc +++ b/rtc_base/ssl_identity.cc
@@ -175,7 +175,7 @@ std::string* der) { // Find the inner body. We need this to fulfill the contract of returning // pem_length. - std::string pem_type_str = std::string(pem_type); + std::string pem_type_str(pem_type); size_t header = pem_string.find("-----BEGIN " + pem_type_str + "-----"); if (header == absl::string_view::npos) { return false; @@ -188,8 +188,7 @@ if (trailer == absl::string_view::npos) { return false; } - std::string inner = - std::string(pem_string.substr(body + 1, trailer - (body + 1))); + std::string inner(pem_string.substr(body + 1, trailer - (body + 1))); *der = Base64::Decode(inner, Base64::DO_PARSE_WHITE | Base64::DO_PAD_ANY | Base64::DO_TERM_BUFFER); return true;
diff --git a/rtc_base/string_to_number.cc b/rtc_base/string_to_number.cc index 5ed6407..1209ece 100644 --- a/rtc_base/string_to_number.cc +++ b/rtc_base/string_to_number.cc
@@ -25,7 +25,7 @@ return absl::nullopt; if (isdigit(static_cast<unsigned char>(str[0])) || str[0] == '-') { - std::string str_str = std::string(str); + std::string str_str(str); char* end = nullptr; errno = 0; const signed_type value = std::strtoll(str_str.c_str(), &end, base); @@ -43,7 +43,7 @@ return absl::nullopt; if (isdigit(static_cast<unsigned char>(str[0])) || str[0] == '-') { - std::string str_str = std::string(str); + std::string str_str(str); // Explicitly discard negative values. std::strtoull parsing causes unsigned // wraparound. We cannot just reject values that start with -, though, since // -0 is perfectly fine, as is -0000000000000000000000000000000. @@ -86,7 +86,7 @@ if (str[0] == '\0') return absl::nullopt; - std::string str_str = std::string(str); + std::string str_str(str); char* end = nullptr; errno = 0; const T value = StrToT<T>(str_str.c_str(), &end);
diff --git a/rtc_base/strings/json.cc b/rtc_base/strings/json.cc index af8ba18..5cf153c 100644 --- a/rtc_base/strings/json.cc +++ b/rtc_base/strings/json.cc
@@ -243,7 +243,7 @@ bool GetValueFromJsonObject(const Json::Value& in, absl::string_view k, Json::Value* out) { - std::string k_str = std::string(k); + std::string k_str(k); if (!in.isObject() || !in.isMember(k_str)) { return false; }
diff --git a/rtc_base/system/file_wrapper.cc b/rtc_base/system/file_wrapper.cc index 1979e6f..f7befc6 100644 --- a/rtc_base/system/file_wrapper.cc +++ b/rtc_base/system/file_wrapper.cc
@@ -28,7 +28,7 @@ FILE* FileOpen(absl::string_view file_name_utf8, bool read_only, int* error) { RTC_CHECK_EQ(file_name_utf8.find_first_of('\0'), absl::string_view::npos) << "Invalid filename, containing NUL character"; - std::string file_name = std::string(file_name_utf8); + std::string file_name(file_name_utf8); #if defined(_WIN32) int len = MultiByteToWideChar(CP_UTF8, 0, file_name.c_str(), -1, nullptr, 0); std::wstring wstr(len, 0);
diff --git a/test/testsupport/file_utils.cc b/test/testsupport/file_utils.cc index 3d462d4..ff0d5a8 100644 --- a/test/testsupport/file_utils.cc +++ b/test/testsupport/file_utils.cc
@@ -136,7 +136,7 @@ if (path.length() == 0) return absl::optional<std::vector<std::string>>(); - std::string path_str = std::string(path); + std::string path_str(path); #if defined(WEBRTC_WIN) // Append separator character if needed. @@ -186,7 +186,7 @@ } bool CreateDir(absl::string_view directory_name) { - std::string directory_name_str = std::string(directory_name); + std::string directory_name_str(directory_name); struct stat path_info = {0}; // Check if the path exists already: if (stat(directory_name_str.c_str(), &path_info) == 0) {
diff --git a/test/testsupport/file_utils_unittest.cc b/test/testsupport/file_utils_unittest.cc index 1e454e3..b9de01d 100644 --- a/test/testsupport/file_utils_unittest.cc +++ b/test/testsupport/file_utils_unittest.cc
@@ -34,7 +34,7 @@ namespace { std::string Path(absl::string_view path) { - std::string result = std::string(path); + std::string result(path); std::replace(result.begin(), result.end(), '/', kPathDelimiter[0]); return result; }