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

Unified Diff: tools/flags/SkCommandLineFlags.cpp

Issue 14366034: Treat default command line argument properly. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 8 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
« tools/flags/SkCommandLineFlags.h ('K') | « tools/flags/SkCommandLineFlags.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/flags/SkCommandLineFlags.cpp
diff --git a/tools/flags/SkCommandLineFlags.cpp b/tools/flags/SkCommandLineFlags.cpp
index d634edb31100dafa02404bd24502b9ee8f5d1cb7..ddedb8e1c75e932ea5236fcfedb767c0c4940f86 100644
--- a/tools/flags/SkCommandLineFlags.cpp
+++ b/tools/flags/SkCommandLineFlags.cpp
@@ -8,6 +8,39 @@
#include "SkCommandLineFlags.h"
#include "SkTDArray.h"
+bool SkFlagInfo::CreateStringFlag(const char* name, const char* shortName,
+ SkCommandLineFlags::StringArray* pStrings,
+ const char* defaultValue, const char* helpString) {
+ SkFlagInfo* info = SkNEW_ARGS(SkFlagInfo, (name, shortName, kString_FlagType, helpString));
epoger 2013/04/23 16:54:13 Is this ever freed? Does it matter?
scroggo 2013/04/24 18:42:36 Yes. It is freed at https://code.google.com/p/skia
+ info->fDefaultString.set(defaultValue);
+
+ info->fStrings = pStrings;
epoger 2013/04/23 16:54:13 Why is it important for the strings to be stored i
scroggo 2013/04/24 18:42:36 Because pStrings is what the client will actually
+ info->fStrings->reset();
+ // If default is "", leave the array empty.
+ size_t defaultLength = strlen(defaultValue);
+ if (defaultLength > 0) {
+ const char* const defaultEnd = defaultValue + defaultLength;
+ const char* begin = defaultValue;
+ while (true) {
+ while (begin < defaultEnd && ' ' == *begin) {
epoger 2013/04/23 16:54:13 I think it would be cleaner to write a helper func
scroggo 2013/04/24 18:42:36 I like that approach too, except that I also like
+ begin++;
+ }
+ if (begin < defaultEnd) {
+ const char* end = begin + 1;
+ while (end < defaultEnd && ' ' != *end) {
+ end++;
+ }
+ size_t length = end - begin;
+ info->fStrings->append(begin, length);
+ begin = end + 1;
+ } else {
+ break;
+ }
+ }
+ }
+ return true;
+}
+
static bool string_is_in(const char* target, const char* set[], size_t len) {
for (size_t i = 0; i < len; i++) {
if (0 == strcmp(target, set[i])) {
« tools/flags/SkCommandLineFlags.h ('K') | « tools/flags/SkCommandLineFlags.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698