mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-12 21:30:45 +01:00
Move StrJoin to rtc_base/strings
A similar function was defined in rtc_base/openssl_adapter. Moving it from net/dcsctp/common/ to rtc_base/strings/. I'm planning to use StrJoin in a video codec test (a follow-up change). Bug: webrtc:14852 Change-Id: Ie657c03e7f9fb52c189c127af6f66ec505b512ae Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/327322 Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Commit-Queue: Sergey Silkin <ssilkin@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/main@{#41166}
This commit is contained in:
parent
02ce5887b6
commit
ebc4d3edd5
20 changed files with 32 additions and 80 deletions
|
@ -132,7 +132,8 @@ docs.
|
|||
WebRTC uses std::string, with content assumed to be UTF-8. Note that this
|
||||
has to be verified whenever accepting external input.
|
||||
|
||||
For concatenation of strings, use rtc::SimpleStringBuilder.
|
||||
For concatenation of strings, use webrtc::StrJoin or rtc::SimpleStringBuilder
|
||||
directly.
|
||||
|
||||
The following string building tools are NOT recommended:
|
||||
* The + operator. See https://abseil.io/tips/3 for why not.
|
||||
|
|
|
@ -29,12 +29,6 @@ rtc_source_set("sequence_numbers") {
|
|||
sources = [ "sequence_numbers.h" ]
|
||||
}
|
||||
|
||||
rtc_source_set("str_join") {
|
||||
deps = [ "../../../rtc_base:stringutils" ]
|
||||
sources = [ "str_join.h" ]
|
||||
absl_deps = [ "//third_party/abseil-cpp/absl/strings" ]
|
||||
}
|
||||
|
||||
if (rtc_include_tests) {
|
||||
rtc_library("dcsctp_common_unittests") {
|
||||
testonly = true
|
||||
|
@ -43,7 +37,6 @@ if (rtc_include_tests) {
|
|||
deps = [
|
||||
":math",
|
||||
":sequence_numbers",
|
||||
":str_join",
|
||||
"../../../api:array_view",
|
||||
"../../../rtc_base:checks",
|
||||
"../../../rtc_base:gunit_helpers",
|
||||
|
@ -52,7 +45,6 @@ if (rtc_include_tests) {
|
|||
sources = [
|
||||
"math_test.cc",
|
||||
"sequence_numbers_test.cc",
|
||||
"str_join_test.cc",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,7 +72,6 @@ rtc_library("parameter") {
|
|||
"../../../rtc_base:stringutils",
|
||||
"../common:internal_types",
|
||||
"../common:math",
|
||||
"../common:str_join",
|
||||
"../public:types",
|
||||
]
|
||||
sources = [
|
||||
|
@ -120,7 +119,6 @@ rtc_library("error_cause") {
|
|||
"../../../rtc_base:stringutils",
|
||||
"../common:internal_types",
|
||||
"../common:math",
|
||||
"../common:str_join",
|
||||
"../packet:bounded_io",
|
||||
"../public:types",
|
||||
]
|
||||
|
@ -172,7 +170,6 @@ rtc_library("chunk") {
|
|||
"../../../rtc_base:logging",
|
||||
"../../../rtc_base:stringutils",
|
||||
"../common:math",
|
||||
"../common:str_join",
|
||||
"../packet:bounded_io",
|
||||
]
|
||||
sources = [
|
||||
|
|
|
@ -18,11 +18,11 @@
|
|||
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/array_view.h"
|
||||
#include "net/dcsctp/common/str_join.h"
|
||||
#include "net/dcsctp/packet/bounded_byte_reader.h"
|
||||
#include "net/dcsctp/packet/bounded_byte_writer.h"
|
||||
#include "net/dcsctp/packet/tlv_trait.h"
|
||||
#include "rtc_base/logging.h"
|
||||
#include "rtc_base/strings/str_join.h"
|
||||
#include "rtc_base/strings/string_builder.h"
|
||||
|
||||
namespace dcsctp {
|
||||
|
|
|
@ -18,11 +18,11 @@
|
|||
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/array_view.h"
|
||||
#include "net/dcsctp/common/str_join.h"
|
||||
#include "net/dcsctp/packet/bounded_byte_reader.h"
|
||||
#include "net/dcsctp/packet/bounded_byte_writer.h"
|
||||
#include "net/dcsctp/packet/tlv_trait.h"
|
||||
#include "rtc_base/logging.h"
|
||||
#include "rtc_base/strings/str_join.h"
|
||||
#include "rtc_base/strings/string_builder.h"
|
||||
|
||||
namespace dcsctp {
|
||||
|
@ -83,7 +83,7 @@ void MissingMandatoryParameterCause::SerializeTo(
|
|||
std::string MissingMandatoryParameterCause::ToString() const {
|
||||
rtc::StringBuilder sb;
|
||||
sb << "Missing Mandatory Parameter, missing_parameter_types="
|
||||
<< StrJoin(missing_parameter_types_, ",");
|
||||
<< webrtc::StrJoin(missing_parameter_types_, ",");
|
||||
return sb.Release();
|
||||
}
|
||||
|
||||
|
|
|
@ -16,10 +16,10 @@
|
|||
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/array_view.h"
|
||||
#include "net/dcsctp/common/str_join.h"
|
||||
#include "net/dcsctp/packet/bounded_byte_reader.h"
|
||||
#include "net/dcsctp/packet/bounded_byte_writer.h"
|
||||
#include "net/dcsctp/packet/tlv_trait.h"
|
||||
#include "rtc_base/strings/str_join.h"
|
||||
#include "rtc_base/strings/string_builder.h"
|
||||
|
||||
namespace dcsctp {
|
||||
|
@ -59,7 +59,7 @@ void SupportedExtensionsParameter::SerializeTo(
|
|||
|
||||
std::string SupportedExtensionsParameter::ToString() const {
|
||||
rtc::StringBuilder sb;
|
||||
sb << "Supported Extensions (" << StrJoin(chunk_types_, ", ") << ")";
|
||||
sb << "Supported Extensions (" << webrtc::StrJoin(chunk_types_, ", ") << ")";
|
||||
return sb.Release();
|
||||
}
|
||||
} // namespace dcsctp
|
||||
|
|
|
@ -95,10 +95,10 @@ rtc_library("reassembly_queue") {
|
|||
"../../../api:array_view",
|
||||
"../../../rtc_base:checks",
|
||||
"../../../rtc_base:logging",
|
||||
"../../../rtc_base:stringutils",
|
||||
"../../../rtc_base/containers:flat_set",
|
||||
"../common:internal_types",
|
||||
"../common:sequence_numbers",
|
||||
"../common:str_join",
|
||||
"../packet:chunk",
|
||||
"../packet:data",
|
||||
"../packet:parameter",
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#include "absl/types/optional.h"
|
||||
#include "api/array_view.h"
|
||||
#include "net/dcsctp/common/sequence_numbers.h"
|
||||
#include "net/dcsctp/common/str_join.h"
|
||||
#include "net/dcsctp/packet/chunk/forward_tsn_common.h"
|
||||
#include "net/dcsctp/packet/data.h"
|
||||
#include "net/dcsctp/packet/parameter/outgoing_ssn_reset_request_parameter.h"
|
||||
|
@ -34,6 +33,7 @@
|
|||
#include "net/dcsctp/rx/reassembly_streams.h"
|
||||
#include "net/dcsctp/rx/traditional_reassembly_streams.h"
|
||||
#include "rtc_base/logging.h"
|
||||
#include "rtc_base/strings/str_join.h"
|
||||
|
||||
namespace dcsctp {
|
||||
namespace {
|
||||
|
|
|
@ -24,8 +24,8 @@ rtc_library("heartbeat_handler") {
|
|||
deps = [
|
||||
":context",
|
||||
"../../../api:array_view",
|
||||
"../../../rtc_base:checks",
|
||||
"../../../api/units:time_delta",
|
||||
"../../../rtc_base:checks",
|
||||
"../../../rtc_base:logging",
|
||||
"../packet:bounded_io",
|
||||
"../packet:chunk",
|
||||
|
@ -53,9 +53,9 @@ rtc_library("stream_reset_handler") {
|
|||
"../../../api/units:time_delta",
|
||||
"../../../rtc_base:checks",
|
||||
"../../../rtc_base:logging",
|
||||
"../../../rtc_base:stringutils",
|
||||
"../../../rtc_base/containers:flat_set",
|
||||
"../common:internal_types",
|
||||
"../common:str_join",
|
||||
"../packet:chunk",
|
||||
"../packet:parameter",
|
||||
"../packet:sctp_packet",
|
||||
|
@ -99,8 +99,8 @@ rtc_library("transmission_control_block") {
|
|||
":packet_sender",
|
||||
":stream_reset_handler",
|
||||
"../../../api:array_view",
|
||||
"../../../api/units:time_delta",
|
||||
"../../../api/task_queue:task_queue",
|
||||
"../../../api/units:time_delta",
|
||||
"../../../rtc_base:checks",
|
||||
"../../../rtc_base:logging",
|
||||
"../../../rtc_base:stringutils",
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
#include "api/array_view.h"
|
||||
#include "api/units/time_delta.h"
|
||||
#include "net/dcsctp/common/internal_types.h"
|
||||
#include "net/dcsctp/common/str_join.h"
|
||||
#include "net/dcsctp/packet/chunk/reconfig_chunk.h"
|
||||
#include "net/dcsctp/packet/parameter/add_incoming_streams_request_parameter.h"
|
||||
#include "net/dcsctp/packet/parameter/add_outgoing_streams_request_parameter.h"
|
||||
|
@ -36,6 +35,7 @@
|
|||
#include "net/dcsctp/timer/timer.h"
|
||||
#include "net/dcsctp/tx/retransmission_queue.h"
|
||||
#include "rtc_base/logging.h"
|
||||
#include "rtc_base/strings/str_join.h"
|
||||
|
||||
namespace dcsctp {
|
||||
namespace {
|
||||
|
|
|
@ -29,9 +29,9 @@ rtc_library("rr_send_queue") {
|
|||
"../../../api:array_view",
|
||||
"../../../rtc_base:checks",
|
||||
"../../../rtc_base:logging",
|
||||
"../../../rtc_base:stringutils",
|
||||
"../../../rtc_base/containers:flat_map",
|
||||
"../common:internal_types",
|
||||
"../common:str_join",
|
||||
"../packet:data",
|
||||
"../public:socket",
|
||||
"../public:types",
|
||||
|
@ -54,9 +54,9 @@ rtc_library("stream_scheduler") {
|
|||
"../../../api:array_view",
|
||||
"../../../rtc_base:checks",
|
||||
"../../../rtc_base:logging",
|
||||
"../../../rtc_base:stringutils",
|
||||
"../../../rtc_base:strong_alias",
|
||||
"../../../rtc_base/containers:flat_set",
|
||||
"../common:str_join",
|
||||
"../packet:chunk",
|
||||
"../packet:data",
|
||||
"../packet:sctp_packet",
|
||||
|
@ -109,11 +109,11 @@ rtc_library("outstanding_data") {
|
|||
"../../../api/units:timestamp",
|
||||
"../../../rtc_base:checks",
|
||||
"../../../rtc_base:logging",
|
||||
"../../../rtc_base:stringutils",
|
||||
"../../../rtc_base/containers:flat_set",
|
||||
"../common:internal_types",
|
||||
"../common:math",
|
||||
"../common:sequence_numbers",
|
||||
"../common:str_join",
|
||||
"../packet:chunk",
|
||||
"../packet:data",
|
||||
"../public:socket",
|
||||
|
@ -142,7 +142,6 @@ rtc_library("retransmission_queue") {
|
|||
"../../../rtc_base:stringutils",
|
||||
"../common:math",
|
||||
"../common:sequence_numbers",
|
||||
"../common:str_join",
|
||||
"../packet:chunk",
|
||||
"../packet:data",
|
||||
"../public:socket",
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#include "api/array_view.h"
|
||||
#include "net/dcsctp/common/math.h"
|
||||
#include "net/dcsctp/common/sequence_numbers.h"
|
||||
#include "net/dcsctp/common/str_join.h"
|
||||
#include "net/dcsctp/packet/chunk/data_chunk.h"
|
||||
#include "net/dcsctp/packet/chunk/forward_tsn_chunk.h"
|
||||
#include "net/dcsctp/packet/chunk/forward_tsn_common.h"
|
||||
|
@ -40,6 +39,7 @@
|
|||
#include "net/dcsctp/tx/send_queue.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/logging.h"
|
||||
#include "rtc_base/strings/str_join.h"
|
||||
#include "rtc_base/strings/string_builder.h"
|
||||
|
||||
namespace dcsctp {
|
||||
|
|
|
@ -21,13 +21,13 @@
|
|||
#include "absl/types/optional.h"
|
||||
#include "api/array_view.h"
|
||||
#include "net/dcsctp/common/internal_types.h"
|
||||
#include "net/dcsctp/common/str_join.h"
|
||||
#include "net/dcsctp/packet/data.h"
|
||||
#include "net/dcsctp/public/dcsctp_message.h"
|
||||
#include "net/dcsctp/public/dcsctp_socket.h"
|
||||
#include "net/dcsctp/public/types.h"
|
||||
#include "net/dcsctp/tx/send_queue.h"
|
||||
#include "rtc_base/logging.h"
|
||||
#include "rtc_base/strings/str_join.h"
|
||||
|
||||
namespace dcsctp {
|
||||
using ::webrtc::TimeDelta;
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#include "absl/algorithm/container.h"
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/array_view.h"
|
||||
#include "net/dcsctp/common/str_join.h"
|
||||
#include "net/dcsctp/packet/data.h"
|
||||
#include "net/dcsctp/public/dcsctp_message.h"
|
||||
#include "net/dcsctp/public/dcsctp_socket.h"
|
||||
|
@ -22,6 +21,7 @@
|
|||
#include "net/dcsctp/tx/send_queue.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/logging.h"
|
||||
#include "rtc_base/strings/str_join.h"
|
||||
|
||||
namespace dcsctp {
|
||||
|
||||
|
|
|
@ -606,6 +606,7 @@ rtc_library("stringutils") {
|
|||
"string_to_number.h",
|
||||
"string_utils.cc",
|
||||
"string_utils.h",
|
||||
"strings/str_join.h",
|
||||
"strings/string_builder.cc",
|
||||
"strings/string_builder.h",
|
||||
"strings/string_format.cc",
|
||||
|
@ -1909,6 +1910,7 @@ if (rtc_include_tests) {
|
|||
"string_encode_unittest.cc",
|
||||
"string_to_number_unittest.cc",
|
||||
"string_utils_unittest.cc",
|
||||
"strings/str_join_unittest.cc",
|
||||
"strings/string_builder_unittest.cc",
|
||||
"strings/string_format_unittest.cc",
|
||||
"strong_alias_unittest.cc",
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
#include "rtc_base/openssl_identity.h"
|
||||
#endif
|
||||
#include "rtc_base/openssl_utility.h"
|
||||
#include "rtc_base/strings/str_join.h"
|
||||
#include "rtc_base/strings/string_builder.h"
|
||||
#include "rtc_base/thread.h"
|
||||
|
||||
|
@ -168,23 +169,6 @@ namespace rtc {
|
|||
|
||||
using ::webrtc::TimeDelta;
|
||||
|
||||
namespace webrtc_openssl_adapter_internal {
|
||||
|
||||
// Simple O(n^2) implementation is sufficient for current use case.
|
||||
std::string StrJoin(const std::vector<std::string>& list, char delimiter) {
|
||||
RTC_CHECK(!list.empty());
|
||||
StringBuilder sb;
|
||||
sb << list[0];
|
||||
for (size_t i = 1; i < list.size(); i++) {
|
||||
sb.AppendFormat("%c", delimiter);
|
||||
sb << list[i];
|
||||
}
|
||||
return sb.Release();
|
||||
}
|
||||
} // namespace webrtc_openssl_adapter_internal
|
||||
|
||||
using webrtc_openssl_adapter_internal::StrJoin;
|
||||
|
||||
bool OpenSSLAdapter::InitializeSSL() {
|
||||
if (!SSL_library_init())
|
||||
return false;
|
||||
|
@ -373,7 +357,7 @@ int OpenSSLAdapter::BeginSSL() {
|
|||
}
|
||||
|
||||
if (!elliptic_curves_.empty()) {
|
||||
SSL_set1_curves_list(ssl_, StrJoin(elliptic_curves_, ':').c_str());
|
||||
SSL_set1_curves_list(ssl_, webrtc::StrJoin(elliptic_curves_, ":").c_str());
|
||||
}
|
||||
|
||||
// Now that the initial config is done, transfer ownership of `bio` to the
|
||||
|
|
|
@ -37,14 +37,6 @@
|
|||
|
||||
namespace rtc {
|
||||
|
||||
namespace webrtc_openssl_adapter_internal {
|
||||
|
||||
// Local definition, since absl::StrJoin is not allow-listed. Declared in header
|
||||
// file only for unittests.
|
||||
std::string StrJoin(const std::vector<std::string>& list, char delimiter);
|
||||
|
||||
} // namespace webrtc_openssl_adapter_internal
|
||||
|
||||
class OpenSSLAdapter final : public SSLAdapter {
|
||||
public:
|
||||
static bool InitializeSSL();
|
||||
|
|
|
@ -116,19 +116,4 @@ TEST(OpenSSLAdapterFactoryTest, CreateWorksWithCustomVerifier) {
|
|||
EXPECT_NE(simple_adapter, nullptr);
|
||||
}
|
||||
|
||||
TEST(StrJoinTest, SingleElement) {
|
||||
EXPECT_EQ(webrtc_openssl_adapter_internal::StrJoin({"a"}, ','), "a");
|
||||
}
|
||||
|
||||
TEST(StrJoinTest, TwoElements) {
|
||||
EXPECT_EQ(webrtc_openssl_adapter_internal::StrJoin({"first", "second"}, ':'),
|
||||
"first:second");
|
||||
}
|
||||
|
||||
TEST(StrJoinTest, WithEmptyElement) {
|
||||
EXPECT_EQ(
|
||||
webrtc_openssl_adapter_internal::StrJoin({"first", "", "second"}, ':'),
|
||||
"first::second");
|
||||
}
|
||||
|
||||
} // namespace rtc
|
||||
|
|
|
@ -7,15 +7,15 @@
|
|||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
#ifndef NET_DCSCTP_COMMON_STR_JOIN_H_
|
||||
#define NET_DCSCTP_COMMON_STR_JOIN_H_
|
||||
#ifndef RTC_BASE_STRINGS_STR_JOIN_H_
|
||||
#define RTC_BASE_STRINGS_STR_JOIN_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "rtc_base/strings/string_builder.h"
|
||||
|
||||
namespace dcsctp {
|
||||
namespace webrtc {
|
||||
|
||||
template <typename Range>
|
||||
std::string StrJoin(const Range& seq, absl::string_view delimiter) {
|
||||
|
@ -51,6 +51,6 @@ std::string StrJoin(const Range& seq,
|
|||
return sb.Release();
|
||||
}
|
||||
|
||||
} // namespace dcsctp
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // NET_DCSCTP_COMMON_STR_JOIN_H_
|
||||
#endif // RTC_BASE_STRINGS_STR_JOIN_H_
|
|
@ -7,15 +7,15 @@
|
|||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
#include "net/dcsctp/common/str_join.h"
|
||||
#include "rtc_base/strings/str_join.h"
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "test/gmock.h"
|
||||
#include "test/gtest.h"
|
||||
|
||||
namespace dcsctp {
|
||||
namespace webrtc {
|
||||
namespace {
|
||||
|
||||
TEST(StrJoinTest, CanJoinStringsFromVector) {
|
||||
|
@ -42,4 +42,4 @@ TEST(StrJoinTest, CanFormatElementsWhileJoining) {
|
|||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace dcsctp
|
||||
} // namespace webrtc
|
Loading…
Reference in a new issue