0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 01:21:03 +01:00
This commit is contained in:
Dwight 2007-11-04 14:39:27 -05:00
parent 50e3afabbb
commit 78bba21722
3 changed files with 71 additions and 8 deletions

View File

@ -11,7 +11,7 @@
<DebugSettings
Command="$(TargetPath)"
WorkingDirectory=""
CommandArguments=""
CommandArguments="run"
Attach="false"
DebuggerType="3"
Remote="1"
@ -22,7 +22,7 @@
SQLDebugging=""
Environment=""
EnvironmentMerge="true"
DebuggerFlavor=""
DebuggerFlavor="0"
MPIRunCommand=""
MPIRunArguments=""
MPIRunWorkingDirectory=""

View File

@ -36,7 +36,7 @@ int Element::size() {
const char *p = value();
int len1 = strlen(p);
p = p + len1 + 1;
x = 1 + len1 + strlen(p);
x = 1 + len1 + strlen(p) + 2;
}
break;
default:
@ -48,13 +48,38 @@ int Element::size() {
}
JSMatcher::JSMatcher(JSObj &_jsobj) :
jsobj(_jsobj)
jsobj(_jsobj), nRegex(0)
{
JSElemIter i(jsobj);
n = 0;
while( i.more() ) {
Element e = i.next();
if( !e.eoo() ) {
if( e.eoo() )
break;
if( e.type() == RegEx ) {
if( nRegex >= 4 ) {
cout << "ERROR: too many regexes in query" << endl;
}
else {
pcrecpp::RE_Options options;
options.set_utf8(true);
const char *flags = e.regexFlags();
while( flags && *flags ) {
if( *flags == 'i' )
options.set_caseless(true);
else if( *flags == 'm' )
options.set_multiline(true);
else if( *flags == 'x' )
options.set_extended(true);
flags++;
}
regexs[nRegex].re = new pcrecpp::RE(e.regex(), options);
regexs[nRegex].fieldName = e.fieldName();
nRegex++;
}
}
else {
toMatch.push_back(e);
n++;
}
@ -62,7 +87,6 @@ JSMatcher::JSMatcher(JSObj &_jsobj) :
}
//#include <boost/regex.hpp>
#include <pcrecpp.h>
//#include <pcre.h>
struct RXTest {
@ -85,10 +109,26 @@ struct RXTest {
bool JSMatcher::matches(JSObj& jsobj) {
/* assuming there is usually only one thing to match. if more this
could be slow sometimes. */
for( int r = 0; r < nRegex; r++ ) {
RegexMatcher& rm = regexs[r];
JSElemIter k(jsobj);
while( 1 ) {
if( !k.more() )
return false;
Element e = k.next();
if( strcmp(e.fieldName(), rm.fieldName) == 0 ) {
if( e.type() != String )
return false;
if( !rm.re->PartialMatch(e.valuestr()) )
return false;
break;
}
}
}
for( int i = 0; i < n; i++ ) {
Element& m = toMatch[i];
JSElemIter k(jsobj);

View File

@ -81,6 +81,8 @@ public:
bool eoo() { return type() == EOO; }
int size();
const char * fieldName() { return data + 1; }
// raw data be careful:
const char * value() { return (data + fieldNameSize + 1); }
@ -88,10 +90,18 @@ public:
int valuestrsize() {
return *((int *) value());
}
// for strings. also gives you start of the data for an embedded object
const char * valuestr() { return value() + 4; }
void* embeddedObject() { valuestr(); }
const char *regex() { assert(type() == RegEx); return value(); }
const char *regexFlags() {
const char *p = regex();
return p + strlen(p) + 1;
}
bool operator==(Element& r) {
int sz = size();
return sz == r.size() &&
@ -100,7 +110,7 @@ public:
private:
Element(const char *d) : data(d) {
fieldNameSize = eoo() ? 0 : strlen(data+1) + 1;
fieldNameSize = eoo() ? 0 : strlen(fieldName()) + 1;
totalSize = -1;
}
const char *data;
@ -189,6 +199,16 @@ private:
const char *theend;
};
#include <pcrecpp.h>
class RegexMatcher {
public:
const char *fieldName;
pcrecpp::RE *re;
RegexMatcher() { re = 0; }
~RegexMatcher() { delete re; }
};
/* For when a js object is a pattern... */
class JSMatcher {
public:
@ -199,6 +219,9 @@ private:
JSObj& jsobj;
vector<Element> toMatch;
int n;
RegexMatcher regexs[4];
int nRegex;
};
/*- just for testing -- */