Treat default command line argument properly.

In SkCommandLineFlags, if the client sets a default value
of multiple arguments (e.g. "arg0 arg1 ..."), set
the actual defaults to all of those arguments separately
(i.e. an array with [0] == "arg0", [1] == "arg1", ...),
rather than as one string (i.e. [0] == "arg0 arg1 ...").

Remove the hack that worked around this bug.

Also move the increasingly complicated implementation of
SkFlagInfo::CreateStringFlag into the cpp file.

BUG=https://code.google.com/p/skia/issues/detail?id=1237

Review URL: https://codereview.chromium.org/14366034

git-svn-id: http://skia.googlecode.com/svn/trunk@8845 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/tools/flags/SkCommandLineFlags.cpp b/tools/flags/SkCommandLineFlags.cpp
index d634edb..7420d26 100644
--- a/tools/flags/SkCommandLineFlags.cpp
+++ b/tools/flags/SkCommandLineFlags.cpp
@@ -8,6 +8,44 @@
 #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));
+    info->fDefaultString.set(defaultValue);
+
+    info->fStrings = pStrings;
+    SetDefaultStrings(pStrings, defaultValue);
+    return true;
+}
+
+void SkFlagInfo::SetDefaultStrings(SkCommandLineFlags::StringArray* pStrings,
+                                   const char* defaultValue) {
+    pStrings->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) {
+                begin++;
+            }
+            if (begin < defaultEnd) {
+                const char* end = begin + 1;
+                while (end < defaultEnd && ' ' != *end) {
+                    end++;
+                }
+                size_t length = end - begin;
+                pStrings->append(begin, length);
+                begin = end + 1;
+            } else {
+                break;
+            }
+        }
+    }
+}
+
 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])) {