Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Unified Diff: tools/SkFlags.h

Issue 12961003: Allow more options for setting boolean flag values in SkFlags. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/SkFlags.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/SkFlags.h
diff --git a/tools/SkFlags.h b/tools/SkFlags.h
index a2d4c97ece0115159dc24d63ec404eb9bcf1860c..c510707f83e50c2bc4adeea987f6cbb6e1fabcc0 100644
--- a/tools/SkFlags.h
+++ b/tools/SkFlags.h
@@ -37,8 +37,13 @@
*
* which will initially be set to false, and can be set to true by using the
* flag "--boolean" on the commandline. "--noboolean" will set FLAGS_boolean
- * to false. (Single dashes are also permitted for this and other flags.) The
- * helpString will be printed if the help flag (-h or -help) is used.
+ * to false. FLAGS_boolean can also be set using "--boolean=true" or
+ * "--boolean true" (where "true" can be replaced by "false", "TRUE", "FALSE",
+ * "1" or "0").
+ *
+ * Single dashes are also permitted for this and other flags.
+ *
+ * The helpString will be printed if the help flag (-h or -help) is used.
*
* Similarly, the line
*
@@ -227,38 +232,19 @@ public:
}
/**
- * Returns true if the string matches this flag. For a bool, also sets the
- * value, since a bool is specified as true or false by --name or --noname.
+ * Returns true if the string matches this flag.
+ * For a boolean flag, also sets the value, since a boolean flag can be set in a number of ways
+ * without looking at the following string:
+ * --name
+ * --noname
+ * --name=true
+ * --name=false
+ * --name=1
+ * --name=0
+ * --name=TRUE
+ * --name=FALSE
*/
- bool match(const char* string) {
- if (SkStrStartsWith(string, '-') && strlen(string) > 1) {
- string++;
- // Allow one or two dashes
- if (SkStrStartsWith(string, '-') && strlen(string) > 1) {
- string++;
- }
- if (kBool_FlagType == fFlagType) {
- // In this case, go ahead and set the value.
- if (fName.equals(string) || fShortName.equals(string)) {
- *fBoolValue = true;
- return true;
- }
- if (SkStrStartsWith(string, "no") && strlen(string) > 2) {
- string += 2;
- if (fName.equals(string) || fShortName.equals(string)) {
- *fBoolValue = false;
- return true;
- }
- return false;
- }
- }
- return fName.equals(string) || fShortName.equals(string);
- } else {
- // Has no dash
- return false;
- }
- return false;
- }
+ bool match(const char* string);
FlagTypes getFlagType() const { return fFlagType; }
@@ -294,6 +280,14 @@ public:
}
}
+ void setBool(bool value) {
+ if (kBool_FlagType == fFlagType) {
+ *fBoolValue = value;
+ } else {
+ SkASSERT(!"Can only call setBool on kBool_FlagType");
+ }
+ }
+
SkFlagInfo* next() { return fNext; }
const SkString& name() const { return fName; }
« no previous file with comments | « no previous file | tools/SkFlags.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698