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}
This commit is contained in:
Ali Tofigh 2022-07-22 22:10:49 +02:00 committed by WebRTC LUCI CQ
parent eeb79b834d
commit 98bfd99151
11 changed files with 24 additions and 25 deletions

View File

@ -41,7 +41,7 @@ namespace {
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

View File

@ -175,7 +175,7 @@ EncoderInfoSettings::EncoderInfoSettings(absl::string_view name)
[](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";

View File

@ -130,7 +130,7 @@ std::string AddTrailingPathDelimiterIfNeeded(absl::string_view directory) {
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 {};

View File

@ -344,14 +344,14 @@ void LogMessage::UpdateMinLogSeverity()
}
#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 @@ void LogMessage::OutputToDebug(absl::string_view str,
#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 @@ void LogMessage::OutputToDebug(absl::string_view str,
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 @@ void LogMessage::OutputToDebug(absl::string_view str,
}
#endif // WEBRTC_ANDROID
if (log_to_stderr) {
fprintf(stderr, "%s", str_str.c_str());
fprintf(stderr, "%s", msg_str.c_str());
fflush(stderr);
}
}

View File

@ -41,7 +41,7 @@ const char* inet_ntop(int af, const void* src, char* dst, socklen_t size) {
}
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

View File

@ -175,7 +175,7 @@ bool SSLIdentity::PemToDer(absl::string_view pem_type,
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 @@ bool SSLIdentity::PemToDer(absl::string_view pem_type,
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;

View File

@ -25,7 +25,7 @@ absl::optional<signed_type> ParseSigned(absl::string_view str, int base) {
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 @@ absl::optional<unsigned_type> ParseUnsigned(absl::string_view str, int base) {
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 @@ absl::optional<T> ParseFloatingPoint(absl::string_view str) {
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);

View File

@ -243,7 +243,7 @@ bool GetDoubleFromJsonArray(const Json::Value& in, size_t n, double* out) {
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;
}

View File

@ -28,7 +28,7 @@ namespace {
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);

View File

@ -136,7 +136,7 @@ absl::optional<std::vector<std::string>> ReadDirectory(absl::string_view path) {
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 @@ absl::optional<std::vector<std::string>> ReadDirectory(absl::string_view path) {
}
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) {

View File

@ -34,7 +34,7 @@ namespace test {
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;
}