| 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, | 11 bool SkFlagInfo::CreateStringFlag(const char* name, const char* shortName, |
| 12 SkCommandLineFlags::StringArray* pStrings, | 12 SkCommandLineFlags::StringArray* pStrings, |
| 13 const char* defaultValue, const char* helpStri
ng) { | 13 const char* defaultValue, const char* helpStri
ng) { |
| 14 SkFlagInfo* info = SkNEW_ARGS(SkFlagInfo, (name, shortName, kString_FlagType
, helpString)); | 14 SkFlagInfo* info = SkNEW_ARGS(SkFlagInfo, (name, shortName, kString_FlagType
, helpString)); |
| 15 info->fDefaultString.set(defaultValue); | 15 info->fDefaultString.set(defaultValue); |
| 16 | 16 |
| 17 info->fStrings = pStrings; | 17 info->fStrings = pStrings; |
| 18 SetDefaultStrings(pStrings, defaultValue); | 18 SetDefaultStrings(pStrings, defaultValue); |
| 19 return true; | 19 return true; |
| 20 } | 20 } |
| 21 | 21 |
| 22 void SkFlagInfo::SetDefaultStrings(SkCommandLineFlags::StringArray* pStrings, | 22 void SkFlagInfo::SetDefaultStrings(SkCommandLineFlags::StringArray* pStrings, |
| 23 const char* defaultValue) { | 23 const char* defaultValue) { |
| 24 pStrings->reset(); | 24 pStrings->reset(); |
| 25 if (NULL == defaultValue) { |
| 26 return; |
| 27 } |
| 25 // If default is "", leave the array empty. | 28 // If default is "", leave the array empty. |
| 26 size_t defaultLength = strlen(defaultValue); | 29 size_t defaultLength = strlen(defaultValue); |
| 27 if (defaultLength > 0) { | 30 if (defaultLength > 0) { |
| 28 const char* const defaultEnd = defaultValue + defaultLength; | 31 const char* const defaultEnd = defaultValue + defaultLength; |
| 29 const char* begin = defaultValue; | 32 const char* begin = defaultValue; |
| 30 while (true) { | 33 while (true) { |
| 31 while (begin < defaultEnd && ' ' == *begin) { | 34 while (begin < defaultEnd && ' ' == *begin) { |
| 32 begin++; | 35 begin++; |
| 33 } | 36 } |
| 34 if (begin < defaultEnd) { | 37 if (begin < defaultEnd) { |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 gHead = NULL; | 296 gHead = NULL; |
| 294 while (flag != NULL) { | 297 while (flag != NULL) { |
| 295 SkFlagInfo* next = flag->next(); | 298 SkFlagInfo* next = flag->next(); |
| 296 SkDELETE(flag); | 299 SkDELETE(flag); |
| 297 flag = next; | 300 flag = next; |
| 298 } | 301 } |
| 299 if (helpPrinted) { | 302 if (helpPrinted) { |
| 300 exit(0); | 303 exit(0); |
| 301 } | 304 } |
| 302 } | 305 } |
| OLD | NEW |