1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 18:17:20 +00:00

Created regexp search for milestone 5.1

This commit is contained in:
Stephan Hradek 2014-01-10 10:32:49 +01:00
parent 2740f8c1f0
commit 8ef520ef37
2 changed files with 27 additions and 7 deletions

View File

@ -52,12 +52,25 @@ function parseFilterOperation(operators,filterString,p) {
operator.operator = "title";
}
// Get the operand
bracketPos = filterString.indexOf(operator.indirect ? "}" : "]",p);
if(bracketPos === -1) {
throw "Missing closing bracket in filter expression";
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);
if(bracketPos === -1) {
throw "Missing closing bracket in filter expression";
}
operator.operand = filterString.substring(p,bracketPos);
p = bracketPos + 1;
}
operator.operand = filterString.substring(p,bracketPos);
p = bracketPos + 1;
// Push this operator
operators.push(operator);
} while(filterString.charAt(p) !== "]");
@ -161,7 +174,8 @@ exports.compileFilter = function(filterString) {
results = operatorFunction(accumulator,{
operator: operator.operator,
operand: operand,
prefix: operator.prefix
prefix: operator.prefix,
regexp: operator.regexp
},{
wiki: self,
currTiddlerTitle: currTiddlerTitle

View File

@ -21,7 +21,13 @@ exports.field = function(source,operator,options) {
function checkTiddler(title) {
var tiddler = options.wiki.getTiddler(title);
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 === "!") {
match = !match;
}