mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-08-07 22:33:50 +00:00
Created regexp search for milestone 5.1
This commit is contained in:
parent
2740f8c1f0
commit
8ef520ef37
@ -52,12 +52,25 @@ function parseFilterOperation(operators,filterString,p) {
|
|||||||
operator.operator = "title";
|
operator.operator = "title";
|
||||||
}
|
}
|
||||||
// Get the operand
|
// Get the operand
|
||||||
|
if(!operator.indirect && filterString.charAt(p) === "/") {
|
||||||
|
// regexp
|
||||||
|
var rex = /^\/((?:[^\\\/]*|\\.))*\/([igm]*)\]/g;
|
||||||
|
var rexMatch = rex.exec(filterString.substring(p));
|
||||||
|
if(!rexMatch) {
|
||||||
|
throw "Incomplete regular expression in filter expression";
|
||||||
|
}
|
||||||
|
operator.regexp = new RegExp(rexMatch[1], rexMatch[2]);
|
||||||
|
operator.operand = filterString.substr(p,rex.lastIndex-1);
|
||||||
|
p += rex.lastIndex;
|
||||||
|
}
|
||||||
|
else {
|
||||||
bracketPos = filterString.indexOf(operator.indirect ? "}" : "]",p);
|
bracketPos = filterString.indexOf(operator.indirect ? "}" : "]",p);
|
||||||
if(bracketPos === -1) {
|
if(bracketPos === -1) {
|
||||||
throw "Missing closing bracket in filter expression";
|
throw "Missing closing bracket in filter expression";
|
||||||
}
|
}
|
||||||
operator.operand = filterString.substring(p,bracketPos);
|
operator.operand = filterString.substring(p,bracketPos);
|
||||||
p = bracketPos + 1;
|
p = bracketPos + 1;
|
||||||
|
}
|
||||||
// Push this operator
|
// Push this operator
|
||||||
operators.push(operator);
|
operators.push(operator);
|
||||||
} while(filterString.charAt(p) !== "]");
|
} while(filterString.charAt(p) !== "]");
|
||||||
@ -161,7 +174,8 @@ exports.compileFilter = function(filterString) {
|
|||||||
results = operatorFunction(accumulator,{
|
results = operatorFunction(accumulator,{
|
||||||
operator: operator.operator,
|
operator: operator.operator,
|
||||||
operand: operand,
|
operand: operand,
|
||||||
prefix: operator.prefix
|
prefix: operator.prefix,
|
||||||
|
regexp: operator.regexp
|
||||||
},{
|
},{
|
||||||
wiki: self,
|
wiki: self,
|
||||||
currTiddlerTitle: currTiddlerTitle
|
currTiddlerTitle: currTiddlerTitle
|
||||||
|
@ -21,7 +21,13 @@ exports.field = function(source,operator,options) {
|
|||||||
function checkTiddler(title) {
|
function checkTiddler(title) {
|
||||||
var tiddler = options.wiki.getTiddler(title);
|
var tiddler = options.wiki.getTiddler(title);
|
||||||
if(tiddler) {
|
if(tiddler) {
|
||||||
var match = tiddler.getFieldString(operator.operator) === operator.operand;
|
var match;
|
||||||
|
if(operator.regexp) {
|
||||||
|
match = !! operator.regexp.exec(tiddler.getFieldString(operator.operator));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
match = tiddler.getFieldString(operator.operator) === operator.operand;
|
||||||
|
}
|
||||||
if(operator.prefix === "!") {
|
if(operator.prefix === "!") {
|
||||||
match = !match;
|
match = !match;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user