summaryrefslogtreecommitdiff
path: root/tools/eslint/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'tools/eslint/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/index.js')
-rw-r--r--tools/eslint/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/index.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/tools/eslint/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/index.js b/tools/eslint/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/index.js
new file mode 100644
index 0000000000..d165ae8174
--- /dev/null
+++ b/tools/eslint/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/index.js
@@ -0,0 +1,38 @@
+module.exports = balanced;
+function balanced(a, b, str) {
+ var bal = 0;
+ var m = {};
+ var ended = false;
+
+ for (var i = 0; i < str.length; i++) {
+ if (a == str.substr(i, a.length)) {
+ if (!('start' in m)) m.start = i;
+ bal++;
+ }
+ else if (b == str.substr(i, b.length) && 'start' in m) {
+ ended = true;
+ bal--;
+ if (!bal) {
+ m.end = i;
+ m.pre = str.substr(0, m.start);
+ m.body = (m.end - m.start > 1)
+ ? str.substring(m.start + a.length, m.end)
+ : '';
+ m.post = str.slice(m.end + b.length);
+ return m;
+ }
+ }
+ }
+
+ // if we opened more than we closed, find the one we closed
+ if (bal && ended) {
+ var start = m.start + a.length;
+ m = balanced(a, b, str.substr(start));
+ if (m) {
+ m.start += start;
+ m.end += start;
+ m.pre = str.slice(0, start) + m.pre;
+ }
+ return m;
+ }
+}