Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Unified Diff: tools/ToolUtils.cpp

Issue 19807005: refactor duplication (shouldSkip and skip_name) into a utility function (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Forgot to add new files.. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« tools/ToolUtils.h ('K') | « tools/ToolUtils.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/ToolUtils.cpp
diff --git a/tools/ToolUtils.cpp b/tools/ToolUtils.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..45dae438ad36647e9aa073a950dac33700707326
--- /dev/null
+++ b/tools/ToolUtils.cpp
@@ -0,0 +1,32 @@
+#include "ToolUtils.h"
+
+bool 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;
+}
« tools/ToolUtils.h ('K') | « tools/ToolUtils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698