bc32add9a5c6d6ff0ee7cc92d1b1f02abc358d2e
[platform/framework/web/crosswalk-tizen.git] /
1 "use strict";
2
3 var makeCheck = require('./makeCheck');
4 var isEmpty = require('./is').isEmpty;
5
6
7 // ---
8
9
10 exports.remove = remove;
11 function remove(target) {
12   if (target.next) {
13     target.next.prev = target.prev;
14   } else if (target.root) {
15     target.root.endToken = target.prev;
16   }
17
18   if (target.prev) {
19     target.prev.next = target.next;
20   } else if (target.root) {
21     target.root.startToken = target.next;
22   }
23 }
24
25
26 exports.removeInBetween = removeInBetween;
27 function removeInBetween(startToken, endToken, check) {
28   check = makeCheck(check);
29   var last = endToken && endToken.next;
30   while (startToken && startToken !== last) {
31     if (check(startToken)) {
32       remove(startToken);
33     }
34     startToken = startToken.next;
35   }
36 }
37
38
39 exports.removeAdjacent = removeAdjacent;
40 function removeAdjacent(token, check) {
41   removeAdjacentBefore(token, check);
42   removeAdjacentAfter(token, check);
43 }
44
45
46 exports.removeAdjacentBefore = removeAdjacentBefore;
47 function removeAdjacentBefore(token, check) {
48   check = makeCheck(check);
49   var prev = token.prev;
50   while (prev && check(prev)) {
51     remove(prev);
52     prev = prev.prev;
53   }
54 }
55
56
57 exports.removeAdjacentAfter = removeAdjacentAfter;
58 function removeAdjacentAfter(token, check) {
59   check = makeCheck(check);
60   var next = token.next;
61   while (next && check(next)) {
62     remove(next);
63     next = next.next;
64   }
65 }
66
67
68 exports.removeEmptyAdjacentBefore = removeEmptyAdjacentBefore;
69 function removeEmptyAdjacentBefore(startToken) {
70   removeAdjacentBefore(startToken, isEmpty);
71 }
72
73
74 exports.removeEmptyAdjacentAfter = removeEmptyAdjacentAfter;
75 function removeEmptyAdjacentAfter(startToken) {
76   removeAdjacentAfter(startToken, isEmpty);
77 }
78
79
80 exports.removeEmptyInBetween = removeEmptyInBetween;
81 function removeEmptyInBetween(startToken, endToken) {
82   removeInBetween(startToken, endToken, isEmpty);
83 }
84