Chromium Code Reviews| 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)); | |
|
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
| |
| 15 info->fDefaultString.set(defaultValue); | |
| 16 | |
| 17 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
| |
| 18 info->fStrings->reset(); | |
| 19 // If default is "", leave the array empty. | |
| 20 size_t defaultLength = strlen(defaultValue); | |
| 21 if (defaultLength > 0) { | |
| 22 const char* const defaultEnd = defaultValue + defaultLength; | |
| 23 const char* begin = defaultValue; | |
| 24 while (true) { | |
| 25 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
| |
| 26 begin++; | |
| 27 } | |
| 28 if (begin < defaultEnd) { | |
| 29 const char* end = begin + 1; | |
| 30 while (end < defaultEnd && ' ' != *end) { | |
| 31 end++; | |
| 32 } | |
| 33 size_t length = end - begin; | |
| 34 info->fStrings->append(begin, length); | |
| 35 begin = end + 1; | |
| 36 } else { | |
| 37 break; | |
| 38 } | |
| 39 } | |
| 40 } | |
| 41 return true; | |
| 42 } | |
| 43 | |
| 11 static bool string_is_in(const char* target, const char* set[], size_t len) { | 44 static bool string_is_in(const char* target, const char* set[], size_t len) { |
| 12 for (size_t i = 0; i < len; i++) { | 45 for (size_t i = 0; i < len; i++) { |
| 13 if (0 == strcmp(target, set[i])) { | 46 if (0 == strcmp(target, set[i])) { |
| 14 return true; | 47 return true; |
| 15 } | 48 } |
| 16 } | 49 } |
| 17 return false; | 50 return false; |
| 18 } | 51 } |
| 19 | 52 |
| 20 /** | 53 /** |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 255 gHead = NULL; | 288 gHead = NULL; |
| 256 while (flag != NULL) { | 289 while (flag != NULL) { |
| 257 SkFlagInfo* next = flag->next(); | 290 SkFlagInfo* next = flag->next(); |
| 258 SkDELETE(flag); | 291 SkDELETE(flag); |
| 259 flag = next; | 292 flag = next; |
| 260 } | 293 } |
| 261 if (helpPrinted) { | 294 if (helpPrinted) { |
| 262 exit(0); | 295 exit(0); |
| 263 } | 296 } |
| 264 } | 297 } |
| OLD | NEW |