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}
This commit is contained in:
parent
2a25be6b06
commit
260c39871b
@ -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 @@ 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;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user