diff --git a/rtc_base/flags.cc b/rtc_base/flags.cc index b4137981e3..a2fb7089b0 100644 --- a/rtc_base/flags.cc +++ b/rtc_base/flags.cc @@ -22,6 +22,23 @@ #include #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 @@ void FlagList::Print(const char* file, bool print_current_value) { 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; }