Add support for hyphens to rtc_base/flags

Make it possible to specify flags both with hyphens (--flag-name)
and underscores (--flag_name).

Bug: None
Change-Id: Ic02cdc2d5b9f7c75d06cdb6287a86ed432fd9daa
Reviewed-on: https://webrtc-review.googlesource.com/49204
Commit-Queue: Edward Lemur <ehmaldonado@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21945}
diff --git a/rtc_base/flags.cc b/rtc_base/flags.cc
index b413798..a2fb708 100644
--- a/rtc_base/flags.cc
+++ b/rtc_base/flags.cc
@@ -22,6 +22,23 @@
 #include <shellapi.h>
 #endif
 
+
+namespace {
+bool FlagEq(const char* arg, const char* flag) {
+  // Compare two flags for equality.
+  // 'arg' is the name of a flag passed via the command line and 'flag' is the
+  // name of a flag defined with the DEFINE_* macros.
+  // We compare the flags for equality, considering hyphens (-) and
+  // underscores (_) to be equivalent, so that --flag-name and --flag_name both
+  // match with --flag_name.
+  while (*arg != '\0' && (*arg == *flag || (*arg == '-' && *flag == '_'))) {
+    ++arg;
+    ++flag;
+  }
+  return *arg == '\0' && *flag == '\0';
+}
+}  // namespace
+
 namespace rtc {
 // -----------------------------------------------------------------------------
 // Implementation of Flag
@@ -131,7 +148,7 @@
 
 Flag* FlagList::Lookup(const char* name) {
   Flag* f = list_;
-  while (f != nullptr && strcmp(name, f->name()) != 0)
+  while (f != nullptr && !FlagEq(name, f->name()))
     f = f->next();
   return f;
 }