Replace _stricmp with absl::EqualsIgnoreCase

All uses check only for equality.

Bug: webrtc:6424
Change-Id: I8755dde02370c89dbc2226bb703664c9e4f88bdb
Reviewed-on: https://webrtc-review.googlesource.com/c/106383
Commit-Queue: Niels Moller <nisse@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25274}
diff --git a/BUILD.gn b/BUILD.gn
index 107cde7..e7d4aa9 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -434,7 +434,11 @@
     "api/video:video_bitrate_allocation",
     "rtc_base:checks",
     "rtc_base:deprecation",
+
+    # TODO(nisse): Delete both of these together with STR_CASE_CMP and
+    # STR_NCASE_CMP.
     "rtc_base:stringutils",
+    "//third_party/abseil-cpp/absl/strings",
   ]
 
   if (!build_with_chromium && is_clang) {
diff --git a/DEPS b/DEPS
index 2beee0b..ddafdfd 100644
--- a/DEPS
+++ b/DEPS
@@ -1416,9 +1416,11 @@
   "+test",
   "+rtc_tools",
 
-  # Abseil whitelist. Keep this in sync with abseil-in-webrtc-md.
+  # Abseil whitelist. Keep this in sync with abseil-in-webrtc.md.
   "+absl/container/inlined_vector.h",
   "+absl/memory/memory.h",
+  "+absl/strings/ascii.h",
+  "+absl/strings/match.h",
   "+absl/strings/string_view.h",
   "+absl/types/optional.h",
   "+absl/types/variant.h",
diff --git a/abseil-in-webrtc.md b/abseil-in-webrtc.md
index 04ae8d2..ae9facf 100644
--- a/abseil-in-webrtc.md
+++ b/abseil-in-webrtc.md
@@ -15,6 +15,7 @@
 * `absl::make_unique` and `absl::WrapUnique`
 * `absl::optional` and related stuff from `absl/types/optional.h`.
 * `absl::string_view`
+* The functions in `absl/strings/ascii.h` and `absl/strings/match.h`
 * `absl::variant` and related stuff from `absl/types/variant.h`.
 
 ## **Disallowed**
diff --git a/api/video_codecs/BUILD.gn b/api/video_codecs/BUILD.gn
index 6bf1a04..3e07298 100644
--- a/api/video_codecs/BUILD.gn
+++ b/api/video_codecs/BUILD.gn
@@ -39,6 +39,7 @@
     "../video:encoded_image",
     "../video:video_bitrate_allocation",
     "../video:video_frame",
+    "//third_party/abseil-cpp/absl/strings",
     "//third_party/abseil-cpp/absl/types:optional",
   ]
 }
diff --git a/api/video_codecs/video_codec.cc b/api/video_codecs/video_codec.cc
index d36535b..60cfab0 100644
--- a/api/video_codecs/video_codec.cc
+++ b/api/video_codecs/video_codec.cc
@@ -16,9 +16,9 @@
 #include <string>
 #include <type_traits>
 
+#include "absl/strings/match.h"
 #include "rtc_base/checks.h"
 #include "rtc_base/strings/string_builder.h"
-#include "rtc_base/stringutils.h"
 
 namespace webrtc {
 
@@ -118,8 +118,9 @@
 static const char* kPayloadNameGeneric = "Generic";
 static const char* kPayloadNameMultiplex = "Multiplex";
 
+// TODO(nisse): Delete this wrapper.
 static bool CodecNamesEq(const char* name1, const char* name2) {
-  return _stricmp(name1, name2) == 0;
+  return absl::EqualsIgnoreCase(name1, name2);
 }
 
 const char* CodecTypeToPayloadString(VideoCodecType type) {
diff --git a/common_types.h b/common_types.h
index 99c4064..37e6e25 100644
--- a/common_types.h
+++ b/common_types.h
@@ -15,7 +15,8 @@
 #include <string.h>
 #include <string>
 #include <vector>
-
+// TODO(nisse): Delete include together with STR_CASE_CMP
+#include "absl/strings/match.h"
 #include "api/array_view.h"
 // TODO(sprang): Remove this include when all usage includes it directly.
 #include "api/video/video_bitrate_allocation.h"
@@ -30,13 +31,15 @@
 
 #define RTP_PAYLOAD_NAME_SIZE 32u
 
-#if defined(WEBRTC_WIN) || defined(WIN32)
 // Compares two strings without regard to case.
-#define STR_CASE_CMP(s1, s2) ::_stricmp(s1, s2)
+// TODO(nisse): Delete, implementation using EqualsIgnoreCase is misleading
+// since this can't be used for sorting.
+#define STR_CASE_CMP(s1, s2) (absl::EqualsIgnoreCase(s1, s2) ? 0 : 1)
+
+#if defined(WEBRTC_WIN) || defined(WIN32)
 // Compares characters of two strings without regard to case.
 #define STR_NCASE_CMP(s1, s2, n) ::_strnicmp(s1, s2, n)
 #else
-#define STR_CASE_CMP(s1, s2) ::strcasecmp(s1, s2)
 #define STR_NCASE_CMP(s1, s2, n) ::strncasecmp(s1, s2, n)
 #endif
 
diff --git a/media/BUILD.gn b/media/BUILD.gn
index 3bac86b..c01660f 100644
--- a/media/BUILD.gn
+++ b/media/BUILD.gn
@@ -139,6 +139,7 @@
     "../rtc_base:rtc_base_approved",
     "../rtc_base/system:rtc_export",
     "../rtc_base/third_party/sigslot",
+    "//third_party/abseil-cpp/absl/strings",
     "//third_party/abseil-cpp/absl/types:optional",
   ]
 
@@ -328,6 +329,7 @@
     "../rtc_base:stringutils",
     "../rtc_base/experiments:normalize_simulcast_size_experiment",
     "../system_wrappers",
+    "//third_party/abseil-cpp/absl/strings",
     "//third_party/abseil-cpp/absl/types:optional",
   ]
 }
diff --git a/media/base/codec.cc b/media/base/codec.cc
index caf3212..56a918d 100644
--- a/media/base/codec.cc
+++ b/media/base/codec.cc
@@ -12,13 +12,13 @@
 
 #include <algorithm>
 
+#include "absl/strings/match.h"
 #include "media/base/h264_profile_level_id.h"
 #include "media/base/vp9_profile.h"
 #include "rtc_base/checks.h"
 #include "rtc_base/logging.h"
 #include "rtc_base/stringencode.h"
 #include "rtc_base/strings/string_builder.h"
-#include "rtc_base/stringutils.h"
 
 namespace cricket {
 
@@ -26,8 +26,8 @@
 FeedbackParams::~FeedbackParams() = default;
 
 bool FeedbackParam::operator==(const FeedbackParam& other) const {
-  return _stricmp(other.id().c_str(), id().c_str()) == 0 &&
-         _stricmp(other.param().c_str(), param().c_str()) == 0;
+  return absl::EqualsIgnoreCase(other.id(), id()) &&
+         absl::EqualsIgnoreCase(other.param(), param());
 }
 
 bool FeedbackParams::operator==(const FeedbackParams& other) const {
@@ -97,7 +97,7 @@
   const int kMaxStaticPayloadId = 95;
   return (id <= kMaxStaticPayloadId || codec.id <= kMaxStaticPayloadId)
              ? (id == codec.id)
-             : (_stricmp(name.c_str(), codec.name.c_str()) == 0);
+             : (absl::EqualsIgnoreCase(name, codec.name));
 }
 
 bool Codec::GetParam(const std::string& name, std::string* out) const {
@@ -235,7 +235,7 @@
 VideoCodec& VideoCodec::operator=(VideoCodec&& c) = default;
 
 void VideoCodec::SetDefaultParameters() {
-  if (_stricmp(kH264CodecName, name.c_str()) == 0) {
+  if (absl::EqualsIgnoreCase(kH264CodecName, name)) {
     // This default is set for all H.264 codecs created because
     // that was the default before packetization mode support was added.
     // TODO(hta): Move this to the places that create VideoCodecs from
@@ -285,16 +285,16 @@
 
 VideoCodec::CodecType VideoCodec::GetCodecType() const {
   const char* payload_name = name.c_str();
-  if (_stricmp(payload_name, kRedCodecName) == 0) {
+  if (absl::EqualsIgnoreCase(payload_name, kRedCodecName)) {
     return CODEC_RED;
   }
-  if (_stricmp(payload_name, kUlpfecCodecName) == 0) {
+  if (absl::EqualsIgnoreCase(payload_name, kUlpfecCodecName)) {
     return CODEC_ULPFEC;
   }
-  if (_stricmp(payload_name, kFlexfecCodecName) == 0) {
+  if (absl::EqualsIgnoreCase(payload_name, kFlexfecCodecName)) {
     return CODEC_FLEXFEC;
   }
-  if (_stricmp(payload_name, kRtxCodecName) == 0) {
+  if (absl::EqualsIgnoreCase(payload_name, kRtxCodecName)) {
     return CODEC_RTX;
   }
 
@@ -362,12 +362,13 @@
       FeedbackParam(kRtcpFbParamTransportCc, kParamValueEmpty));
 }
 
+// TODO(nisse): Delete these wrappers.
 bool CodecNamesEq(const std::string& name1, const std::string& name2) {
   return CodecNamesEq(name1.c_str(), name2.c_str());
 }
 
 bool CodecNamesEq(const char* name1, const char* name2) {
-  return _stricmp(name1, name2) == 0;
+  return absl::EqualsIgnoreCase(name1, name2);
 }
 
 const VideoCodec* FindMatchingCodec(
diff --git a/media/base/fakemediaengine.cc b/media/base/fakemediaengine.cc
index ca58612..6a26fcc 100644
--- a/media/base/fakemediaengine.cc
+++ b/media/base/fakemediaengine.cc
@@ -12,6 +12,7 @@
 
 #include <utility>
 
+#include "absl/strings/match.h"
 #include "rtc_base/checks.h"
 
 namespace cricket {
@@ -128,7 +129,7 @@
   for (std::vector<AudioCodec>::const_iterator it = send_codecs_.begin();
        it != send_codecs_.end(); ++it) {
     // Find the DTMF telephone event "codec".
-    if (_stricmp(it->name.c_str(), "telephone-event") == 0) {
+    if (absl::EqualsIgnoreCase(it->name, "telephone-event")) {
       return true;
     }
   }
diff --git a/media/base/rtpdataengine.cc b/media/base/rtpdataengine.cc
index fc2b731..87c3668 100644
--- a/media/base/rtpdataengine.cc
+++ b/media/base/rtpdataengine.cc
@@ -12,6 +12,7 @@
 
 #include <map>
 
+#include "absl/strings/match.h"
 #include "media/base/codec.h"
 #include "media/base/mediaconstants.h"
 #include "media/base/rtputils.h"
@@ -21,7 +22,6 @@
 #include "rtc_base/helpers.h"
 #include "rtc_base/logging.h"
 #include "rtc_base/sanitizer.h"
-#include "rtc_base/stringutils.h"
 
 namespace cricket {
 
@@ -47,7 +47,7 @@
 static const DataCodec* FindCodecByName(const std::vector<DataCodec>& codecs,
                                         const std::string& name) {
   for (const DataCodec& codec : codecs) {
-    if (_stricmp(name.c_str(), codec.name.c_str()) == 0)
+    if (absl::EqualsIgnoreCase(name, codec.name))
       return &codec;
   }
   return nullptr;
diff --git a/media/engine/payload_type_mapper.cc b/media/engine/payload_type_mapper.cc
index 5d2fb67..80faa1b 100644
--- a/media/engine/payload_type_mapper.cc
+++ b/media/engine/payload_type_mapper.cc
@@ -12,6 +12,7 @@
 
 #include <utility>
 
+#include "absl/strings/ascii.h"
 #include "api/audio_codecs/audio_format.h"
 #include "common_types.h"  // NOLINT(build/include)
 #include "media/base/mediaconstants.h"
@@ -140,7 +141,8 @@
     const webrtc::SdpAudioFormat& b) const {
   if (a.clockrate_hz == b.clockrate_hz) {
     if (a.num_channels == b.num_channels) {
-      int name_cmp = STR_CASE_CMP(a.name.c_str(), b.name.c_str());
+      int name_cmp =
+          absl::AsciiStrToLower(a.name).compare(absl::AsciiStrToLower(b.name));
       if (name_cmp == 0)
         return a.parameters < b.parameters;
       return name_cmp < 0;
diff --git a/media/engine/webrtcvoiceengine.cc b/media/engine/webrtcvoiceengine.cc
index b71354f..aa0e140 100644
--- a/media/engine/webrtcvoiceengine.cc
+++ b/media/engine/webrtcvoiceengine.cc
@@ -19,6 +19,7 @@
 #include <utility>
 #include <vector>
 
+#include "absl/strings/match.h"
 #include "api/audio_codecs/audio_codec_pair_id.h"
 #include "api/call/audio_sink.h"
 #include "media/base/audiosource.h"
@@ -40,7 +41,6 @@
 #include "rtc_base/race_checker.h"
 #include "rtc_base/strings/audio_format_to_string.h"
 #include "rtc_base/strings/string_builder.h"
-#include "rtc_base/stringutils.h"
 #include "rtc_base/third_party/base64/base64.h"
 #include "rtc_base/trace_event.h"
 #include "system_wrappers/include/field_trial.h"
@@ -109,7 +109,7 @@
 }
 
 bool IsCodec(const AudioCodec& codec, const char* ref_name) {
-  return (_stricmp(codec.name.c_str(), ref_name) == 0);
+  return absl::EqualsIgnoreCase(codec.name, ref_name);
 }
 
 bool FindCodec(const std::vector<AudioCodec>& codecs,
diff --git a/p2p/BUILD.gn b/p2p/BUILD.gn
index 48b8159..252d182 100644
--- a/p2p/BUILD.gn
+++ b/p2p/BUILD.gn
@@ -101,6 +101,7 @@
     "../system_wrappers:field_trial",
     "../system_wrappers:metrics",
     "//third_party/abseil-cpp/absl/memory",
+    "//third_party/abseil-cpp/absl/strings",
     "//third_party/abseil-cpp/absl/types:optional",
   ]
 
diff --git a/p2p/base/port.cc b/p2p/base/port.cc
index ac7521e..f5c8433 100644
--- a/p2p/base/port.cc
+++ b/p2p/base/port.cc
@@ -17,6 +17,7 @@
 #include <vector>
 
 #include "absl/memory/memory.h"
+#include "absl/strings/match.h"
 #include "p2p/base/portallocator.h"
 #include "rtc_base/checks.h"
 #include "rtc_base/crc32.h"
@@ -27,7 +28,6 @@
 #include "rtc_base/network.h"
 #include "rtc_base/numerics/safe_minmax.h"
 #include "rtc_base/stringencode.h"
-#include "rtc_base/stringutils.h"
 #include "rtc_base/third_party/base64/base64.h"
 
 namespace {
@@ -183,7 +183,7 @@
 
 bool StringToProto(const char* value, ProtocolType* proto) {
   for (size_t i = 0; i <= PROTO_LAST; ++i) {
-    if (_stricmp(PROTO_NAMES[i], value) == 0) {
+    if (absl::EqualsIgnoreCase(PROTO_NAMES[i], value)) {
       *proto = static_cast<ProtocolType>(i);
       return true;
     }
diff --git a/p2p/base/transportdescription.cc b/p2p/base/transportdescription.cc
index ad29a11..377a4c3 100644
--- a/p2p/base/transportdescription.cc
+++ b/p2p/base/transportdescription.cc
@@ -10,9 +10,9 @@
 
 #include "p2p/base/transportdescription.h"
 
+#include "absl/strings/match.h"
 #include "p2p/base/p2pconstants.h"
 #include "rtc_base/arraysize.h"
-#include "rtc_base/stringutils.h"
 
 namespace cricket {
 
@@ -22,7 +22,7 @@
       CONNECTIONROLE_ACTPASS_STR, CONNECTIONROLE_HOLDCONN_STR};
 
   for (size_t i = 0; i < arraysize(roles); ++i) {
-    if (_stricmp(roles[i], role_str.c_str()) == 0) {
+    if (absl::EqualsIgnoreCase(roles[i], role_str)) {
       *role = static_cast<ConnectionRole>(CONNECTIONROLE_ACTIVE + i);
       return true;
     }
diff --git a/pc/BUILD.gn b/pc/BUILD.gn
index bac1ffd..b8542d9 100644
--- a/pc/BUILD.gn
+++ b/pc/BUILD.gn
@@ -87,6 +87,7 @@
     "../rtc_base/third_party/sigslot",
     "../system_wrappers:metrics",
     "//third_party/abseil-cpp/absl/memory",
+    "//third_party/abseil-cpp/absl/strings",
     "//third_party/abseil-cpp/absl/types:optional",
   ]
 
diff --git a/pc/channelmanager.cc b/pc/channelmanager.cc
index e976cbc..31920d9 100644
--- a/pc/channelmanager.cc
+++ b/pc/channelmanager.cc
@@ -14,10 +14,10 @@
 #include <utility>
 
 #include "absl/memory/memory.h"
+#include "absl/strings/match.h"
 #include "media/base/rtpdataengine.h"
 #include "rtc_base/checks.h"
 #include "rtc_base/logging.h"
-#include "rtc_base/stringutils.h"
 #include "rtc_base/trace_event.h"
 
 namespace cricket {
@@ -95,7 +95,7 @@
   std::vector<VideoCodec> video_codecs = media_engine_->video_codecs();
   for (const auto& video_codec : video_codecs) {
     if (!enable_rtx_ &&
-        _stricmp(kRtxCodecName, video_codec.name.c_str()) == 0) {
+        absl::EqualsIgnoreCase(kRtxCodecName, video_codec.name)) {
       continue;
     }
     codecs->push_back(video_codec);
diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn
index 2b13212..36e4f57 100644
--- a/rtc_base/BUILD.gn
+++ b/rtc_base/BUILD.gn
@@ -704,6 +704,7 @@
     "third_party/base64",
     "third_party/sigslot",
     "//third_party/abseil-cpp/absl/memory",
+    "//third_party/abseil-cpp/absl/strings",
     "//third_party/abseil-cpp/absl/types:optional",
   ]
   public_deps = [
diff --git a/rtc_base/httpcommon.cc b/rtc_base/httpcommon.cc
index baf843d..7926f88 100644
--- a/rtc_base/httpcommon.cc
+++ b/rtc_base/httpcommon.cc
@@ -24,6 +24,7 @@
 #include <utility>  // for pair
 #include <vector>
 
+#include "absl/strings/match.h"
 #include "rtc_base/arraysize.h"
 #include "rtc_base/checks.h"
 #include "rtc_base/cryptstring.h"  // for CryptString
@@ -265,7 +266,7 @@
     return HAR_IGNORE;
 
   // BASIC
-  if (_stricmp(auth_method.c_str(), "basic") == 0) {
+  if (absl::EqualsIgnoreCase(auth_method, "basic")) {
     if (context)
       return HAR_CREDENTIALS;  // Bad credentials
     if (username.empty())
@@ -293,7 +294,7 @@
   }
 
   // DIGEST
-  if (_stricmp(auth_method.c_str(), "digest") == 0) {
+  if (absl::EqualsIgnoreCase(auth_method, "digest")) {
     if (context)
       return HAR_CREDENTIALS;  // Bad credentials
     if (username.empty())
@@ -360,8 +361,8 @@
 
 #if defined(WEBRTC_WIN)
 #if 1
-  bool want_negotiate = (_stricmp(auth_method.c_str(), "negotiate") == 0);
-  bool want_ntlm = (_stricmp(auth_method.c_str(), "ntlm") == 0);
+  bool want_negotiate = absl::EqualsIgnoreCase(auth_method, "negotiate");
+  bool want_ntlm = absl::EqualsIgnoreCase(auth_method, "ntlm");
   // SPNEGO & NTLM
   if (want_negotiate || want_ntlm) {
     const size_t MAX_MESSAGE = 12000, MAX_SPN = 256;
diff --git a/rtc_base/stringutils.h b/rtc_base/stringutils.h
index 28fe1bb..2f75c09 100644
--- a/rtc_base/stringutils.h
+++ b/rtc_base/stringutils.h
@@ -43,9 +43,6 @@
 
 #if defined(WEBRTC_POSIX)
 
-inline int _stricmp(const char* s1, const char* s2) {
-  return strcasecmp(s1, s2);
-}
 inline int _strnicmp(const char* s1, const char* s2, size_t n) {
   return strncasecmp(s1, s2, n);
 }