Replace starts_with and ends_with with Abseil
Bug: None Change-Id: I7eae3db1aeb81f0f1d37ff50d5c85c16ecb1f366 Reviewed-on: https://webrtc-review.googlesource.com/c/114221 Commit-Queue: Steve Anton <steveanton@webrtc.org> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Cr-Commit-Position: refs/heads/master@{#26032}
This commit is contained in:
@ -49,7 +49,6 @@
|
||||
#include "rtc_base/numerics/safe_conversions.h"
|
||||
#include "rtc_base/stringencode.h"
|
||||
#include "rtc_base/strings/string_builder.h"
|
||||
#include "rtc_base/stringutils.h"
|
||||
#include "rtc_base/trace_event.h"
|
||||
#include "system_wrappers/include/clock.h"
|
||||
#include "system_wrappers/include/field_trial.h"
|
||||
@ -2225,7 +2224,7 @@ RTCError PeerConnection::ApplyLocalDescription(
|
||||
if (data_content) {
|
||||
const cricket::DataContentDescription* data_desc =
|
||||
data_content->media_description()->as_data();
|
||||
if (rtc::starts_with(data_desc->protocol().data(),
|
||||
if (absl::StartsWith(data_desc->protocol(),
|
||||
cricket::kMediaProtocolRtpPrefix)) {
|
||||
UpdateLocalRtpDataChannels(data_desc->streams());
|
||||
}
|
||||
@ -2625,7 +2624,7 @@ RTCError PeerConnection::ApplyRemoteDescription(
|
||||
|
||||
// Update the DataChannels with the information from the remote peer.
|
||||
if (data_desc) {
|
||||
if (rtc::starts_with(data_desc->protocol().data(),
|
||||
if (absl::StartsWith(data_desc->protocol(),
|
||||
cricket::kMediaProtocolRtpPrefix)) {
|
||||
UpdateRemoteRtpDataChannels(GetActiveStreams(data_desc));
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/strings/match.h"
|
||||
#include "api/audio_codecs/audio_decoder_factory.h"
|
||||
#include "api/audio_codecs/audio_encoder_factory.h"
|
||||
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
|
||||
@ -37,7 +38,6 @@
|
||||
#include "rtc_base/gunit.h"
|
||||
#include "rtc_base/refcountedobject.h"
|
||||
#include "rtc_base/scoped_ref_ptr.h"
|
||||
#include "rtc_base/stringutils.h"
|
||||
#include "rtc_base/thread.h"
|
||||
#include "rtc_base/trace_event.h"
|
||||
#include "rtc_base/virtualsocketserver.h"
|
||||
@ -876,12 +876,12 @@ TEST_F(RTCStatsIntegrationTest, GetStatsReferencedIds) {
|
||||
if (!member->is_defined())
|
||||
continue;
|
||||
if (member->type() == RTCStatsMemberInterface::kString) {
|
||||
if (rtc::ends_with(member->name(), "Id")) {
|
||||
if (absl::EndsWith(member->name(), "Id")) {
|
||||
const auto& id = member->cast_to<const RTCStatsMember<std::string>>();
|
||||
expected_ids.insert(&(*id));
|
||||
}
|
||||
} else if (member->type() == RTCStatsMemberInterface::kSequenceString) {
|
||||
if (rtc::ends_with(member->name(), "Ids")) {
|
||||
if (absl::EndsWith(member->name(), "Ids")) {
|
||||
const auto& ids =
|
||||
member->cast_to<const RTCStatsMember<std::vector<std::string>>>();
|
||||
for (const std::string& id : *ids)
|
||||
|
@ -1110,6 +1110,7 @@ rtc_source_set("gunit_helpers") {
|
||||
":rtc_base_tests_utils",
|
||||
":stringutils",
|
||||
"../test:test_support",
|
||||
"//third_party/abseil-cpp/absl/strings",
|
||||
]
|
||||
}
|
||||
|
||||
|
@ -12,17 +12,18 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "rtc_base/stringutils.h"
|
||||
#include "absl/strings/match.h"
|
||||
|
||||
::testing::AssertionResult AssertStartsWith(const char* str_expr,
|
||||
::testing::AssertionResult AssertStartsWith(const char* text_expr,
|
||||
const char* prefix_expr,
|
||||
const std::string& str,
|
||||
const std::string& prefix) {
|
||||
if (rtc::starts_with(str.c_str(), prefix.c_str())) {
|
||||
absl::string_view text,
|
||||
absl::string_view prefix) {
|
||||
if (absl::StartsWith(text, prefix)) {
|
||||
return ::testing::AssertionSuccess();
|
||||
} else {
|
||||
return ::testing::AssertionFailure()
|
||||
<< str_expr << "\nwhich is\n\"" << str << "\"\ndoes not start with\n"
|
||||
<< text_expr << "\nwhich is\n\"" << text
|
||||
<< "\"\ndoes not start with\n"
|
||||
<< prefix_expr << "\nwhich is\n\"" << prefix << "\"";
|
||||
}
|
||||
}
|
||||
|
@ -153,11 +153,11 @@
|
||||
} else \
|
||||
GTEST_CONCAT_TOKEN_(gunit_label_, __LINE__) : ASSERT_EQ(v1, v2)
|
||||
|
||||
// Usage: EXPECT_PRED_FORMAT2(AssertStartsWith, str, "prefix");
|
||||
testing::AssertionResult AssertStartsWith(const char* str_expr,
|
||||
// Usage: EXPECT_PRED_FORMAT2(AssertStartsWith, text, "prefix");
|
||||
testing::AssertionResult AssertStartsWith(const char* text_expr,
|
||||
const char* prefix_expr,
|
||||
const std::string& str,
|
||||
const std::string& prefix);
|
||||
absl::string_view text,
|
||||
absl::string_view prefix);
|
||||
|
||||
// Usage: EXPECT_PRED_FORMAT2(AssertStringContains, str, "substring");
|
||||
testing::AssertionResult AssertStringContains(const char* str_expr,
|
||||
|
@ -42,22 +42,6 @@ void replace_substrs(const char* search,
|
||||
}
|
||||
}
|
||||
|
||||
bool starts_with(const char* s1, const char* s2) {
|
||||
return strncmp(s1, s2, strlen(s2)) == 0;
|
||||
}
|
||||
|
||||
bool ends_with(const char* s1, const char* s2) {
|
||||
size_t s1_length = strlen(s1);
|
||||
size_t s2_length = strlen(s2);
|
||||
|
||||
if (s2_length > s1_length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* start = s1 + (s1_length - s2_length);
|
||||
return strncmp(start, s2, s2_length) == 0;
|
||||
}
|
||||
|
||||
static const char kWhitespace[] = " \n\r\t";
|
||||
|
||||
std::string string_trim(const std::string& s) {
|
||||
|
@ -100,12 +100,6 @@ void replace_substrs(const char* search,
|
||||
size_t replace_len,
|
||||
std::string* s);
|
||||
|
||||
// True iff s1 starts with s2.
|
||||
bool starts_with(const char* s1, const char* s2);
|
||||
|
||||
// True iff s1 ends with s2.
|
||||
bool ends_with(const char* s1, const char* s2);
|
||||
|
||||
// Remove leading and trailing whitespaces.
|
||||
std::string string_trim(const std::string& s);
|
||||
|
||||
|
@ -22,26 +22,6 @@ TEST(string_trim_Test, Trimming) {
|
||||
EXPECT_EQ("", string_trim(""));
|
||||
}
|
||||
|
||||
TEST(string_startsTest, StartsWith) {
|
||||
EXPECT_TRUE(starts_with("foobar", "foo"));
|
||||
EXPECT_TRUE(starts_with("foobar", "foobar"));
|
||||
EXPECT_TRUE(starts_with("foobar", ""));
|
||||
EXPECT_TRUE(starts_with("", ""));
|
||||
EXPECT_FALSE(starts_with("foobar", "bar"));
|
||||
EXPECT_FALSE(starts_with("foobar", "foobarbaz"));
|
||||
EXPECT_FALSE(starts_with("", "f"));
|
||||
}
|
||||
|
||||
TEST(string_endsTest, EndsWith) {
|
||||
EXPECT_TRUE(ends_with("foobar", "bar"));
|
||||
EXPECT_TRUE(ends_with("foobar", "foobar"));
|
||||
EXPECT_TRUE(ends_with("foobar", ""));
|
||||
EXPECT_TRUE(ends_with("", ""));
|
||||
EXPECT_FALSE(ends_with("foobar", "foo"));
|
||||
EXPECT_FALSE(ends_with("foobar", "foobarbaz"));
|
||||
EXPECT_FALSE(ends_with("", "f"));
|
||||
}
|
||||
|
||||
TEST(string_toHexTest, ToHex) {
|
||||
EXPECT_EQ(ToHex(0), "0");
|
||||
EXPECT_EQ(ToHex(0X1243E), "1243e");
|
||||
|
@ -69,6 +69,7 @@ rtc_static_library("video_file_reader") {
|
||||
"../api/video:video_frame_i420",
|
||||
"../rtc_base:checks",
|
||||
"../rtc_base:rtc_base_approved",
|
||||
"//third_party/abseil-cpp/absl/strings",
|
||||
"//third_party/abseil-cpp/absl/types:optional",
|
||||
]
|
||||
}
|
||||
@ -83,6 +84,7 @@ rtc_static_library("video_file_writer") {
|
||||
"../api/video:video_frame",
|
||||
"../api/video:video_frame_i420",
|
||||
"../rtc_base:rtc_base_approved",
|
||||
"//third_party/abseil-cpp/absl/strings",
|
||||
"//third_party/abseil-cpp/absl/types:optional",
|
||||
]
|
||||
}
|
||||
@ -128,6 +130,7 @@ rtc_executable("frame_analyzer") {
|
||||
"../rtc_base:ptr_util",
|
||||
"../rtc_base:stringutils",
|
||||
"../test:perf_test",
|
||||
"//third_party/abseil-cpp/absl/strings",
|
||||
]
|
||||
}
|
||||
|
||||
|
@ -14,9 +14,9 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/strings/match.h"
|
||||
#include "rtc_base/scoped_ref_ptr.h"
|
||||
#include "rtc_base/strings/string_builder.h"
|
||||
#include "rtc_base/stringutils.h"
|
||||
#include "rtc_tools/frame_analyzer/video_color_aligner.h"
|
||||
#include "rtc_tools/frame_analyzer/video_geometry_aligner.h"
|
||||
#include "rtc_tools/frame_analyzer/video_quality_analysis.h"
|
||||
@ -112,8 +112,8 @@ int main(int argc, char* argv[]) {
|
||||
const std::string test_file_name = parser.GetFlag("test_file");
|
||||
|
||||
// .yuv files require explicit resolution.
|
||||
if ((rtc::ends_with(reference_file_name.c_str(), ".yuv") ||
|
||||
rtc::ends_with(test_file_name.c_str(), ".yuv")) &&
|
||||
if ((absl::EndsWith(reference_file_name, ".yuv") ||
|
||||
absl::EndsWith(test_file_name, ".yuv")) &&
|
||||
(width <= 0 || height <= 0)) {
|
||||
fprintf(stderr,
|
||||
"Error: You need to specify width and height when using .yuv "
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/strings/match.h"
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/video/i420_buffer.h"
|
||||
#include "rtc_base/checks.h"
|
||||
@ -21,7 +22,6 @@
|
||||
#include "rtc_base/refcountedobject.h"
|
||||
#include "rtc_base/string_to_number.h"
|
||||
#include "rtc_base/stringencode.h"
|
||||
#include "rtc_base/stringutils.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
@ -270,9 +270,9 @@ rtc::scoped_refptr<Video> OpenYuvFile(const std::string& file_name,
|
||||
rtc::scoped_refptr<Video> OpenYuvOrY4mFile(const std::string& file_name,
|
||||
int width,
|
||||
int height) {
|
||||
if (rtc::ends_with(file_name.c_str(), ".yuv"))
|
||||
if (absl::EndsWith(file_name, ".yuv"))
|
||||
return OpenYuvFile(file_name, width, height);
|
||||
if (rtc::ends_with(file_name.c_str(), ".y4m"))
|
||||
if (absl::EndsWith(file_name, ".y4m"))
|
||||
return OpenY4mFile(file_name);
|
||||
|
||||
RTC_LOG(LS_ERROR) << "Video file does not end in either .yuv or .y4m: "
|
||||
|
@ -14,9 +14,9 @@
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
|
||||
#include "absl/strings/match.h"
|
||||
#include "api/video/video_frame_buffer.h"
|
||||
#include "rtc_base/logging.h"
|
||||
#include "rtc_base/stringutils.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
@ -30,7 +30,7 @@ void WriteVideoToFile(const rtc::scoped_refptr<Video>& video,
|
||||
return;
|
||||
}
|
||||
|
||||
bool isY4m = rtc::ends_with(file_name.c_str(), ".y4m");
|
||||
bool isY4m = absl::EndsWith(file_name, ".y4m");
|
||||
if (isY4m) {
|
||||
fprintf(output_file, "YUV4MPEG2 W%d H%d F%d:1 C420\n", video->width(),
|
||||
video->height(), fps);
|
||||
|
Reference in New Issue
Block a user