| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkCommandLineFlags.h" | 8 #include "SkCommandLineFlags.h" |
| 9 #include "SkTDArray.h" | 9 #include "SkTDArray.h" |
| 10 | 10 |
| 11 bool SkFlagInfo::CreateStringFlag(const char* name, const char* shortName, |
| 12 SkCommandLineFlags::StringArray* pStrings, |
| 13 const char* defaultValue, const char* helpStri
ng) { |
| 14 SkFlagInfo* info = SkNEW_ARGS(SkFlagInfo, (name, shortName, kString_FlagType
, helpString)); |
| 15 info->fDefaultString.set(defaultValue); |
| 16 |
| 17 info->fStrings = pStrings; |
| 18 SetDefaultStrings(pStrings, defaultValue); |
| 19 return true; |
| 20 } |
| 21 |
| 22 void SkFlagInfo::SetDefaultStrings(SkCommandLineFlags::StringArray* pStrings, |
| 23 const char* defaultValue) { |
| 24 pStrings->reset(); |
| 25 // If default is "", leave the array empty. |
| 26 size_t defaultLength = strlen(defaultValue); |
| 27 if (defaultLength > 0) { |
| 28 const char* const defaultEnd = defaultValue + defaultLength; |
| 29 const char* begin = defaultValue; |
| 30 while (true) { |
| 31 while (begin < defaultEnd && ' ' == *begin) { |
| 32 begin++; |
| 33 } |
| 34 if (begin < defaultEnd) { |
| 35 const char* end = begin + 1; |
| 36 while (end < defaultEnd && ' ' != *end) { |
| 37 end++; |
| 38 } |
| 39 size_t length = end - begin; |
| 40 pStrings->append(begin, length); |
| 41 begin = end + 1; |
| 42 } else { |
| 43 break; |
| 44 } |
| 45 } |
| 46 } |
| 47 } |
| 48 |
| 11 static bool string_is_in(const char* target, const char* set[], size_t len) { | 49 static bool string_is_in(const char* target, const char* set[], size_t len) { |
| 12 for (size_t i = 0; i < len; i++) { | 50 for (size_t i = 0; i < len; i++) { |
| 13 if (0 == strcmp(target, set[i])) { | 51 if (0 == strcmp(target, set[i])) { |
| 14 return true; | 52 return true; |
| 15 } | 53 } |
| 16 } | 54 } |
| 17 return false; | 55 return false; |
| 18 } | 56 } |
| 19 | 57 |
| 20 /** | 58 /** |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 gHead = NULL; | 293 gHead = NULL; |
| 256 while (flag != NULL) { | 294 while (flag != NULL) { |
| 257 SkFlagInfo* next = flag->next(); | 295 SkFlagInfo* next = flag->next(); |
| 258 SkDELETE(flag); | 296 SkDELETE(flag); |
| 259 flag = next; | 297 flag = next; |
| 260 } | 298 } |
| 261 if (helpPrinted) { | 299 if (helpPrinted) { |
| 262 exit(0); | 300 exit(0); |
| 263 } | 301 } |
| 264 } | 302 } |
| OLD | NEW |