From 1620d7ebdf78eb171fffbd6f66401b475c8791ad Mon Sep 17 00:00:00 2001 From: Dwight Date: Thu, 26 Jun 2008 10:39:32 -0400 Subject: [PATCH] regex matches now supported, partially, when reaching into arrays. --- db/jsobj.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/db/jsobj.cpp b/db/jsobj.cpp index 9c70414634a..6fe927efafd 100644 --- a/db/jsobj.cpp +++ b/db/jsobj.cpp @@ -476,8 +476,21 @@ inline bool _regexMatches(RegexMatcher& rm, Element& e) { return false; return rm.re->PartialMatch(p); } -inline bool regexMatches(RegexMatcher& rm, Element& e) { - return _regexMatches(rm, e); +/* todo: internal dotted notation scans -- not done yet here. */ +inline bool regexMatches(RegexMatcher& rm, Element& e, bool *deep) { + if( e.type() != Array ) + return _regexMatches(rm, e); + + JSElemIter ai(e.embeddedObject()); + while( ai.more() ) { + Element z = ai.next(); + if( _regexMatches(rm, z) ) { + if( deep ) + *deep = true; + return true; + } + } + return false; } /* See if an object matches the query. @@ -495,7 +508,7 @@ bool JSMatcher::matches(JSObj& jsobj, bool *deep) { Element e = jsobj.getFieldDotted(rm.fieldName); if( e.eoo() ) return false; - if( !regexMatches(rm, e) ) + if( !regexMatches(rm, e, deep) ) return false; }