Permalink
Browse files

glob: prefix

  • Loading branch information...
1 parent e10a7e8 commit 7c2adfb9591cbb9e874f8921a50d591bc4a03566 @dvv dvv committed Nov 29, 2010
Showing with 13 additions and 6 deletions.
  1. +6 −0 lib/parser.js
  2. +7 −6 lib/query.js
View
@@ -254,6 +254,12 @@ exports.converters = {
},
RE: function(x){
return new RegExp(decodeURIComponent(x));
+ },
+ glob: function(x){
+ var s = decodeURIComponent(x).replace(/([\\|\||\(|\)|\[|\{|\^|\$|\*|\+|\?|\.|\<|\>])/g, function(x){return '\\'+x;}).replace(/\\\*/g,'.*').replace(/\\\?/g,'.?');
+ if (s.substring(0,2) !== '.*') s = '^'+s; else s = s.substring(2);
+ if (s.substring(s.length-2) !== '.*') s = s+'$'; else s = s.substring(0, s.length-2);
+ return new RegExp(s, 'i');
}
};
View
@@ -28,7 +28,7 @@ parser.Query = function(seed, params){
return q;
};
exports.Query = parser.Query;
-exports.knownOperators = ["and", "or", "eq", "ne", "le", "lt", "gt", "ge", "sort", "in", "select", "contains","values","aggregate","distinct","limit","recurse"];
+exports.knownOperators = ["and", "or", "eq", "ne", "le", "lt", "gt", "ge", "sort", "in", "notin", "select", "exclude", "contains", "notcontains", "values","aggregate","distinct","limit","recurse"];
exports.knownScalarOperators = ["mean", "sum", "min", "max", "count", "first", "one"];
exports.arrayMethods = ["forEach", "reduce", "map", "filter", "indexOf", "some", "every"];
@@ -79,11 +79,12 @@ exports.encodeValue = function(val) {
))) {
var type = typeof val;
if(val instanceof RegExp){
- val = val.toString();
- var i = val.lastIndexOf('/');
- type = val.substring(i).indexOf('i') >= 0 ? "re" : "RE";
- val = encodeString(val.substring(1, i));
- encoded = true;
+ // TODO: control whether to we want simpler glob() style
+ val = val.toString();
+ var i = val.lastIndexOf('/');
+ type = val.substring(i).indexOf('i') >= 0 ? "re" : "RE";
+ val = encodeString(val.substring(1, i));
+ encoded = true;
}
if(type === "object"){
type = "epoch";

0 comments on commit 7c2adfb

Please sign in to comment.