mirror of
https://github.com/flynx/diff.js.git
synced 2025-10-29 19:10:11 +00:00
.filter(..) almost ready, still needs more testing..
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
cb16f000f7
commit
1edeb867fa
57
diff.js
57
diff.js
@ -2139,17 +2139,21 @@ var DiffPrototype = {
|
|||||||
// '**' | [ .. ],
|
// '**' | [ .. ],
|
||||||
// ...
|
// ...
|
||||||
// ]
|
// ]
|
||||||
|
// XXX when OF(..) is ready, replace '**' with OF(ANY, ANY)...
|
||||||
var path = (filter instanceof Array ? filter : [filter])
|
var path = (filter instanceof Array ? filter : [filter])
|
||||||
// '*' -> ANY
|
// '*' -> ANY
|
||||||
.map(function(e){
|
.map(function(e){
|
||||||
return e == '*' ? ANY : e })
|
return e == '*' ? ANY : e })
|
||||||
|
// remove consecutive repeating '**'
|
||||||
|
.filter(function(e, i, lst){
|
||||||
|
return e == '**' && lst[i-1] != '**' || true })
|
||||||
// split to array sections at '**'...
|
// split to array sections at '**'...
|
||||||
// XXX when OF(..) is ready, replace '**' with OF(ANY, ANY)...
|
|
||||||
// XXX need to remove sets of consecutive '**'...
|
|
||||||
.reduce(function(res, e){
|
.reduce(function(res, e){
|
||||||
var n = res.length-1
|
var n = res.length-1
|
||||||
e == '**' ? res.push(2)
|
e == '**' ?
|
||||||
: (res.length == 0 || res[n] == '**') ? res.push([e])
|
res.push('**')
|
||||||
|
: (res.length == 0 || res[n] == '**') ?
|
||||||
|
res.push([e])
|
||||||
: res[n].push(e)
|
: res[n].push(e)
|
||||||
return res
|
return res
|
||||||
}, [])
|
}, [])
|
||||||
@ -2160,27 +2164,30 @@ var DiffPrototype = {
|
|||||||
return l + (e instanceof Array ? e.length : 0) }, 0)
|
return l + (e instanceof Array ? e.length : 0) }, 0)
|
||||||
|
|
||||||
// XXX account for pattern/path end...
|
// XXX account for pattern/path end...
|
||||||
var test = function(p, pattern, path){
|
var test = function(path, pattern){
|
||||||
return p == '**' ?
|
return (
|
||||||
// compare next pattern section and path...
|
// end of path/pattern...
|
||||||
(cmp(pattern[0], path.slice(0, next.length))
|
path.length == 0 && pattern.length == 0 ?
|
||||||
// next pattern/path section
|
true
|
||||||
// XXX need to stop if we run put of path or pattern...
|
|
||||||
&& test(pattern[1],
|
// consumed pattern with path left over -> fail...
|
||||||
pattern.slice(2),
|
: (path.length > 0 && pattern.length == 0)
|
||||||
path.slice(next.length)))
|
|| (path.length == 0 && pattern.length > 1)?
|
||||||
// shift path and test...
|
false
|
||||||
// XXX need to stop if we run put of path...
|
|
||||||
|| (test(p,
|
// '**' -> test, skip elem and repeat...
|
||||||
pattern,
|
: pattern[0] == '**' ?
|
||||||
path.slice(1))
|
(test(path, pattern.slice(1))
|
||||||
// shift to next pattern section...
|
|| test(path.slice(1), pattern))
|
||||||
// XXX need to stop if we run put of pattern...
|
|
||||||
&& test(pattern[1],
|
// compare sections...
|
||||||
pattern.slice(2),
|
: (cmp(
|
||||||
path.slice(pattern[0].length)))
|
path.slice(0, pattern[0].length),
|
||||||
: cmp(pattern[0], path)
|
pattern[0])
|
||||||
}
|
// test next section...
|
||||||
|
&& test(
|
||||||
|
path.slice(pattern[0].length),
|
||||||
|
pattern.slice(1)))) }
|
||||||
|
|
||||||
// XXX Q: should we ignore the last element of the path???
|
// XXX Q: should we ignore the last element of the path???
|
||||||
filter = function(change, i, lst){
|
filter = function(change, i, lst){
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user