| 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 |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 while (flag != NULL) { | 297 while (flag != NULL) { |
| 298 SkFlagInfo* next = flag->next(); | 298 SkFlagInfo* next = flag->next(); |
| 299 SkDELETE(flag); | 299 SkDELETE(flag); |
| 300 flag = next; | 300 flag = next; |
| 301 } | 301 } |
| 302 if (helpPrinted) { | 302 if (helpPrinted) { |
| 303 exit(0); | 303 exit(0); |
| 304 } | 304 } |
| 305 } | 305 } |
| 306 | 306 |
| 307 bool SkCommandLineFlags::ShouldSkip(const SkTDArray<const char*>& strings, const
char* name) { | 307 namespace { |
| 308 |
| 309 template <typename Strings> |
| 310 bool ShouldSkipImpl(const Strings& strings, const char* name) { |
| 308 int count = strings.count(); | 311 int count = strings.count(); |
| 309 size_t testLen = strlen(name); | 312 size_t testLen = strlen(name); |
| 310 bool anyExclude = count == 0; | 313 bool anyExclude = count == 0; |
| 311 for (int i = 0; i < strings.count(); ++i) { | 314 for (int i = 0; i < strings.count(); ++i) { |
| 312 const char* matchName = strings[i]; | 315 const char* matchName = strings[i]; |
| 313 size_t matchLen = strlen(matchName); | 316 size_t matchLen = strlen(matchName); |
| 314 bool matchExclude, matchStart, matchEnd; | 317 bool matchExclude, matchStart, matchEnd; |
| 315 if ((matchExclude = matchName[0] == '~')) { | 318 if ((matchExclude = matchName[0] == '~')) { |
| 316 anyExclude = true; | 319 anyExclude = true; |
| 317 matchName++; | 320 matchName++; |
| 318 matchLen--; | 321 matchLen--; |
| 319 } | 322 } |
| 320 if ((matchStart = matchName[0] == '^')) { | 323 if ((matchStart = matchName[0] == '^')) { |
| 321 matchName++; | 324 matchName++; |
| 322 matchLen--; | 325 matchLen--; |
| 323 } | 326 } |
| 324 if ((matchEnd = matchName[matchLen - 1] == '$')) { | 327 if ((matchEnd = matchName[matchLen - 1] == '$')) { |
| 325 matchLen--; | 328 matchLen--; |
| 326 } | 329 } |
| 327 if (matchStart ? (!matchEnd || matchLen == testLen) | 330 if (matchStart ? (!matchEnd || matchLen == testLen) |
| 328 && strncmp(name, matchName, matchLen) == 0 | 331 && strncmp(name, matchName, matchLen) == 0 |
| 329 : matchEnd ? matchLen <= testLen | 332 : matchEnd ? matchLen <= testLen |
| 330 && strncmp(name + testLen - matchLen, matchName, matchLen) == 0 | 333 && strncmp(name + testLen - matchLen, matchName, matchLen) == 0 |
| 331 : strstr(name, matchName) != 0) { | 334 : strstr(name, matchName) != 0) { |
| 332 return matchExclude; | 335 return matchExclude; |
| 333 } | 336 } |
| 334 } | 337 } |
| 335 return !anyExclude; | 338 return !anyExclude; |
| 336 } | 339 } |
| 340 |
| 341 } // namespace |
| 342 |
| 343 bool SkCommandLineFlags::ShouldSkip(const SkTDArray<const char*>& strings, const
char* name) { |
| 344 return ShouldSkipImpl(strings, name); |
| 345 } |
| 346 bool SkCommandLineFlags::ShouldSkip(const StringArray& strings, const char* name
) { |
| 347 return ShouldSkipImpl(strings, name); |
| 348 } |
| OLD | NEW |