0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-30 17:10:48 +01:00

Support \A in regex and better handling of multiline flag SERVER-815

This commit is contained in:
Mathias Stearn 2010-03-29 20:17:10 -04:00
parent e339760675
commit 4d90a98d69

View File

@ -35,11 +35,25 @@ namespace mongo {
if (purePrefix) *purePrefix = false;
bool multilineOK;
if ( regex[0] == '\\' && regex[1] == 'A'){
multilineOK = true;
regex += 2;
} else if (regex[0] == '^') {
multilineOK = false;
regex += 1;
} else {
return r;
}
bool extended = false;
while (*flags){
switch (*(flags++)){
case 'm': // multiline
if (multilineOK)
continue;
else
return r;
case 'x': // extended
extended = true;
break;
@ -48,9 +62,6 @@ namespace mongo {
}
}
if ( *(regex++) != '^' )
return r;
stringstream ss;
while(*regex){
@ -783,19 +794,31 @@ namespace mongo {
}
{
BSONObjBuilder b;
b.appendRegex("r", "^f", "m");
b.appendRegex("r", "\\Af", "");
BSONObj o = b.done();
assert( simpleRegex(o.firstElement()) == "f" );
}
{
BSONObjBuilder b;
b.appendRegex("r", "^f", "mi");
b.appendRegex("r", "^f", "m");
BSONObj o = b.done();
assert( simpleRegex(o.firstElement()) == "" );
}
{
BSONObjBuilder b;
b.appendRegex("r", "^f \t\vo\n\ro \\ \\# #comment", "mx");
b.appendRegex("r", "\\Af", "m");
BSONObj o = b.done();
assert( simpleRegex(o.firstElement()) == "f" );
}
{
BSONObjBuilder b;
b.appendRegex("r", "\\Af", "mi");
BSONObj o = b.done();
assert( simpleRegex(o.firstElement()) == "" );
}
{
BSONObjBuilder b;
b.appendRegex("r", "\\Af \t\vo\n\ro \\ \\# #comment", "mx");
BSONObj o = b.done();
assert( simpleRegex(o.firstElement()) == "foo #" );
}