Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/common.js

Issue 29517687: Issue 5079, 5516 - Use webpack for browser tests, modules for content scripts (Closed)
Patch Set: Addressed nits Created Aug. 17, 2017, 1:25 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chromium_process.js ('k') | lib/content/elemHideEmulation.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/common.js
diff --git a/lib/common.js b/lib/common.js
index 54118e54d82caa582ce9b16d0d467eef21987388..9bf00db7d5f89e8bfd516a1259055087148e33db 100644
--- a/lib/common.js
+++ b/lib/common.js
@@ -48,5 +48,44 @@ function filterToRegExp(text)
.replace(/(\.\*)$/, "");
}
-if (typeof exports != "undefined")
- exports.filterToRegExp = filterToRegExp;
+exports.filterToRegExp = filterToRegExp;
+
+function splitSelector(selector)
+{
+ if (selector.indexOf(",") == -1)
+ return [selector];
+
+ let selectors = [];
+ let start = 0;
+ let level = 0;
+ let sep = "";
+
+ for (let i = 0; i < selector.length; i++)
+ {
+ let chr = selector[i];
+
+ if (chr == "\\") // ignore escaped characters
+ i++;
+ else if (chr == sep) // don't split within quoted text
+ sep = ""; // e.g. [attr=","]
+ else if (sep == "")
+ {
+ if (chr == '"' || chr == "'")
+ sep = chr;
+ else if (chr == "(") // don't split between parentheses
+ level++; // e.g. :matches(div,span)
+ else if (chr == ")")
+ level = Math.max(0, level - 1);
+ else if (chr == "," && level == 0)
+ {
+ selectors.push(selector.substring(start, i));
+ start = i + 1;
+ }
+ }
+ }
+
+ selectors.push(selector.substring(start));
+ return selectors;
+}
+
+exports.splitSelector = splitSelector;
« no previous file with comments | « chromium_process.js ('k') | lib/content/elemHideEmulation.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld