aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorGravatar sglez@google.com <sglez@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-07-24 17:24:23 +0000
committerGravatar sglez@google.com <sglez@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-07-24 17:24:23 +0000
commit586db93c447b753364d50fadc5426de4fef9a759 (patch)
tree93057a5d7e6428c97e782ce43078a0ddff7892e3 /tools
parentd9763a550517b003a39437221f2ea03c6b32f026 (diff)
refactor duplication (shouldSkip and skip_name) into a utility function
R=caryclark@google.com, reed@google.com Committed: https://code.google.com/p/skia/source/detail?r=10280 Review URL: https://codereview.chromium.org/19807005 git-svn-id: http://skia.googlecode.com/svn/trunk@10317 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tools')
-rw-r--r--tools/flags/SkCommandLineFlags.cpp31
-rw-r--r--tools/flags/SkCommandLineFlags.h11
2 files changed, 41 insertions, 1 deletions
diff --git a/tools/flags/SkCommandLineFlags.cpp b/tools/flags/SkCommandLineFlags.cpp
index ed8db8e705..b088b4e4d3 100644
--- a/tools/flags/SkCommandLineFlags.cpp
+++ b/tools/flags/SkCommandLineFlags.cpp
@@ -303,3 +303,34 @@ void SkCommandLineFlags::Parse(int argc, char** argv) {
exit(0);
}
}
+
+bool SkCommandLineFlags::ShouldSkip(const SkTDArray<const char*>& strings, const char* name) {
+ int count = strings.count();
+ size_t testLen = strlen(name);
+ bool anyExclude = count == 0;
+ for (int i = 0; i < strings.count(); ++i) {
+ const char* matchName = strings[i];
+ size_t matchLen = strlen(matchName);
+ bool matchExclude, matchStart, matchEnd;
+ if ((matchExclude = matchName[0] == '~')) {
+ anyExclude = true;
+ matchName++;
+ matchLen--;
+ }
+ if ((matchStart = matchName[0] == '^')) {
+ matchName++;
+ matchLen--;
+ }
+ if ((matchEnd = matchName[matchLen - 1] == '$')) {
+ matchLen--;
+ }
+ if (matchStart ? (!matchEnd || matchLen == testLen)
+ && strncmp(name, matchName, matchLen) == 0
+ : matchEnd ? matchLen <= testLen
+ && strncmp(name + testLen - matchLen, matchName, matchLen) == 0
+ : strstr(name, matchName) != 0) {
+ return matchExclude;
+ }
+ }
+ return !anyExclude;
+}
diff --git a/tools/flags/SkCommandLineFlags.h b/tools/flags/SkCommandLineFlags.h
index d0e74502d8..51af933467 100644
--- a/tools/flags/SkCommandLineFlags.h
+++ b/tools/flags/SkCommandLineFlags.h
@@ -10,6 +10,7 @@
#include "SkString.h"
#include "SkTArray.h"
+#include "SkTDArray.h"
/**
* Including this file (and compiling SkCommandLineFlags.cpp) provides command line
@@ -90,7 +91,6 @@
* strings) so that a flag can be followed by multiple parameters.
*/
-
class SkFlagInfo;
class SkCommandLineFlags {
@@ -108,6 +108,15 @@ public:
*/
static void Parse(int argc, char** argv);
+ /* Takes a list of the form [~][^]match[$]
+ ~ causes a matching test to always be skipped
+ ^ requires the start of the test to match
+ $ requires the end of the test to match
+ ^ and $ requires an exact match
+ If a test does not match any list entry, it is skipped unless some list entry starts with ~
+ */
+ static bool ShouldSkip(const SkTDArray<const char*>& strings, const char* name);
+
/**
* Custom class for holding the arguments for a string flag.
* Publicly only has accessors so the strings cannot be modified.