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}
diff --git a/g3doc/style-guide.md b/g3doc/style-guide.md
index b32163f..8e6570a 100644
--- a/g3doc/style-guide.md
+++ b/g3doc/style-guide.md
@@ -132,7 +132,8 @@
 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.
diff --git a/net/dcsctp/common/BUILD.gn b/net/dcsctp/common/BUILD.gn
index 78fa0d3..d496c64 100644
--- a/net/dcsctp/common/BUILD.gn
+++ b/net/dcsctp/common/BUILD.gn
@@ -29,12 +29,6 @@
   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 @@
     deps = [
       ":math",
       ":sequence_numbers",
-      ":str_join",
       "../../../api:array_view",
       "../../../rtc_base:checks",
       "../../../rtc_base:gunit_helpers",
@@ -52,7 +45,6 @@
     sources = [
       "math_test.cc",
       "sequence_numbers_test.cc",
-      "str_join_test.cc",
     ]
   }
 }
diff --git a/net/dcsctp/packet/BUILD.gn b/net/dcsctp/packet/BUILD.gn
index 7abccc0..a0c9d8d 100644
--- a/net/dcsctp/packet/BUILD.gn
+++ b/net/dcsctp/packet/BUILD.gn
@@ -72,7 +72,6 @@
     "../../../rtc_base:stringutils",
     "../common:internal_types",
     "../common:math",
-    "../common:str_join",
     "../public:types",
   ]
   sources = [
@@ -120,7 +119,6 @@
     "../../../rtc_base:stringutils",
     "../common:internal_types",
     "../common:math",
-    "../common:str_join",
     "../packet:bounded_io",
     "../public:types",
   ]
@@ -172,7 +170,6 @@
     "../../../rtc_base:logging",
     "../../../rtc_base:stringutils",
     "../common:math",
-    "../common:str_join",
     "../packet:bounded_io",
   ]
   sources = [
diff --git a/net/dcsctp/packet/chunk/sack_chunk.cc b/net/dcsctp/packet/chunk/sack_chunk.cc
index d80e430..179f7ea 100644
--- a/net/dcsctp/packet/chunk/sack_chunk.cc
+++ b/net/dcsctp/packet/chunk/sack_chunk.cc
@@ -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 {
diff --git a/net/dcsctp/packet/error_cause/missing_mandatory_parameter_cause.cc b/net/dcsctp/packet/error_cause/missing_mandatory_parameter_cause.cc
index b89f86e..679439d 100644
--- a/net/dcsctp/packet/error_cause/missing_mandatory_parameter_cause.cc
+++ b/net/dcsctp/packet/error_cause/missing_mandatory_parameter_cause.cc
@@ -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 @@
 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();
 }
 
diff --git a/net/dcsctp/packet/parameter/supported_extensions_parameter.cc b/net/dcsctp/packet/parameter/supported_extensions_parameter.cc
index 6a8fb21..87a5bd9b 100644
--- a/net/dcsctp/packet/parameter/supported_extensions_parameter.cc
+++ b/net/dcsctp/packet/parameter/supported_extensions_parameter.cc
@@ -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 @@
 
 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
diff --git a/net/dcsctp/rx/BUILD.gn b/net/dcsctp/rx/BUILD.gn
index f5f5b7e..15b9f60 100644
--- a/net/dcsctp/rx/BUILD.gn
+++ b/net/dcsctp/rx/BUILD.gn
@@ -95,10 +95,10 @@
     "../../../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",
diff --git a/net/dcsctp/rx/reassembly_queue.cc b/net/dcsctp/rx/reassembly_queue.cc
index 5734436..ae67273 100644
--- a/net/dcsctp/rx/reassembly_queue.cc
+++ b/net/dcsctp/rx/reassembly_queue.cc
@@ -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 {
diff --git a/net/dcsctp/socket/BUILD.gn b/net/dcsctp/socket/BUILD.gn
index 9820207..04f61e5 100644
--- a/net/dcsctp/socket/BUILD.gn
+++ b/net/dcsctp/socket/BUILD.gn
@@ -24,8 +24,8 @@
   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 @@
     "../../../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 @@
     ":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",
diff --git a/net/dcsctp/socket/stream_reset_handler.cc b/net/dcsctp/socket/stream_reset_handler.cc
index f81057d..fafb993 100644
--- a/net/dcsctp/socket/stream_reset_handler.cc
+++ b/net/dcsctp/socket/stream_reset_handler.cc
@@ -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 {
diff --git a/net/dcsctp/tx/BUILD.gn b/net/dcsctp/tx/BUILD.gn
index 3183be3..d1fd8ab 100644
--- a/net/dcsctp/tx/BUILD.gn
+++ b/net/dcsctp/tx/BUILD.gn
@@ -29,9 +29,9 @@
     "../../../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 @@
     "../../../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 @@
     "../../../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_base:stringutils",
     "../common:math",
     "../common:sequence_numbers",
-    "../common:str_join",
     "../packet:chunk",
     "../packet:data",
     "../public:socket",
diff --git a/net/dcsctp/tx/retransmission_queue.cc b/net/dcsctp/tx/retransmission_queue.cc
index da06ddc..cd1cc14 100644
--- a/net/dcsctp/tx/retransmission_queue.cc
+++ b/net/dcsctp/tx/retransmission_queue.cc
@@ -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 {
diff --git a/net/dcsctp/tx/rr_send_queue.cc b/net/dcsctp/tx/rr_send_queue.cc
index b889c06..7cbead2 100644
--- a/net/dcsctp/tx/rr_send_queue.cc
+++ b/net/dcsctp/tx/rr_send_queue.cc
@@ -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;
diff --git a/net/dcsctp/tx/stream_scheduler.cc b/net/dcsctp/tx/stream_scheduler.cc
index 6c51e1e..66c4457 100644
--- a/net/dcsctp/tx/stream_scheduler.cc
+++ b/net/dcsctp/tx/stream_scheduler.cc
@@ -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 {
 
diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn
index 9cf0522..899a689 100644
--- a/rtc_base/BUILD.gn
+++ b/rtc_base/BUILD.gn
@@ -606,6 +606,7 @@
     "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 @@
         "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",
diff --git a/rtc_base/openssl_adapter.cc b/rtc_base/openssl_adapter.cc
index c68eb22..e48cdf4 100644
--- a/rtc_base/openssl_adapter.cc
+++ b/rtc_base/openssl_adapter.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 @@
 
 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 @@
   }
 
   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
diff --git a/rtc_base/openssl_adapter.h b/rtc_base/openssl_adapter.h
index 558a040..4c05471 100644
--- a/rtc_base/openssl_adapter.h
+++ b/rtc_base/openssl_adapter.h
@@ -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();
diff --git a/rtc_base/openssl_adapter_unittest.cc b/rtc_base/openssl_adapter_unittest.cc
index ce351dc..5b59a80 100644
--- a/rtc_base/openssl_adapter_unittest.cc
+++ b/rtc_base/openssl_adapter_unittest.cc
@@ -116,19 +116,4 @@
   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
diff --git a/net/dcsctp/common/str_join.h b/rtc_base/strings/str_join.h
similarity index 87%
rename from net/dcsctp/common/str_join.h
rename to rtc_base/strings/str_join.h
index 0451782..762e63a 100644
--- a/net/dcsctp/common/str_join.h
+++ b/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.
  */
-#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 @@
   return sb.Release();
 }
 
-}  // namespace dcsctp
+}  // namespace webrtc
 
-#endif  // NET_DCSCTP_COMMON_STR_JOIN_H_
+#endif  // RTC_BASE_STRINGS_STR_JOIN_H_
diff --git a/net/dcsctp/common/str_join_test.cc b/rtc_base/strings/str_join_unittest.cc
similarity index 91%
rename from net/dcsctp/common/str_join_test.cc
rename to rtc_base/strings/str_join_unittest.cc
index dbfd92c..a4ac021 100644
--- a/net/dcsctp/common/str_join_test.cc
+++ b/rtc_base/strings/str_join_unittest.cc
@@ -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 @@
 }
 
 }  // namespace
-}  // namespace dcsctp
+}  // namespace webrtc