From ab4c05be5983ef86b40510112f69a91de1276fbe Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 25 Jun 2008 22:22:52 +0000 Subject: [PATCH] Add REGEXP SQLite UDF SQLite automatically uses this function for the "foo REGEX '/[a-z]+/'" syntax --- chrome/content/zotero/xpcom/db.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/chrome/content/zotero/xpcom/db.js b/chrome/content/zotero/xpcom/db.js index 4e6b86ef8..527e793a6 100644 --- a/chrome/content/zotero/xpcom/db.js +++ b/chrome/content/zotero/xpcom/db.js @@ -957,22 +957,31 @@ Zotero.DBConnection.prototype._getDBConnection = function () { observerService.addObserver(this, "xpcom-shutdown", false); observerService = null; + // User-defined functions + // TODO: move somewhere else? + // Levenshtein distance UDF - // - // Implements mozIStorageFunction - // TODO: move somewhere else var lev = { ZU: new Zotero.Utilities, - onFunctionCall: function (arg) { var a = arg.getUTF8String(0); var b = arg.getUTF8String(1); return this.ZU.levenshtein(a, b); } }; - this._connection.createFunction('levenshtein', 2, lev); + // Regexp UDF + var rx = { + onFunctionCall: function (arg) { + var re = new RegExp(arg.getUTF8String(0)); + var str = arg.getUTF8String(1); + return re.test(str); + } + }; + this._connection.createFunction('regexp', 2, rx); + + return this._connection; }