Index: tools/SkFlags.h |
diff --git a/tools/SkFlags.h b/tools/SkFlags.h |
index 79cc8788a3b26f93393f519ce0014ebbe79dd532..237d11ce2e77a78839d5decc9632a63dea06d1e7 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. |
reed1
2013/03/20 20:09:41
do you mean --help or -help?
scroggo
2013/03/20 21:12:05
In reality, I mean --help or -help or -h or --h. F
|
* |
* Similarly, the line |
* |
@@ -227,8 +232,38 @@ 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. |
+ * Check to see whether string represents a boolean value. |
+ * @param string C style string to parse. |
+ * @param result Pointer to a boolean which will be set to the value in the string, if the |
+ * string represents a boolean. |
+ * @param boolean True if the string represents a boolean, false otherwise. |
+ */ |
+ static bool ParseBoolArg(const char* string, bool* result) { |
reed1
2013/03/20 20:09:41
Is it cleaner to use a small table of strings for
scroggo
2013/03/20 21:12:05
Done.
|
+ SkString parameter(string); |
+ if (parameter.equals("1") || parameter.equals("TRUE") || parameter.equals("true")) { |
+ *result = true; |
+ return true; |
+ } |
+ if (parameter.equals("0") || parameter.equals("FALSE") || parameter.equals("false")) { |
+ *result = false; |
+ return true; |
+ } |
+ SkDebugf("Parameter \"%s\" not supported.\n", string); |
+ return false; |
+ } |
+ |
+ /** |
+ * 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) { |
@@ -251,6 +286,17 @@ public: |
} |
return false; |
} |
+ int equalIndex = SkStrFind(string, "="); |
+ if (equalIndex > 0) { |
+ // The string has an equal sign. Check to see if the string matches. |
+ SkString flag(string, equalIndex); |
+ if (flag.equals(fName) || flag.equals(fShortName)) { |
+ // Check to see if the remainder beyond the equal sign is true or false: |
+ string += equalIndex + 1; |
+ ParseBoolArg(string, fBoolValue); |
+ return true; |
+ } |
+ } |
} |
return fName.equals(string) || fShortName.equals(string); |
} else { |
@@ -294,6 +340,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; } |