Browse Source

ref #3314: Filled RegexMatchExpression.js

Brennan Chesley 12 years ago
parent
commit
c1a89c4167
1 changed files with 33 additions and 142 deletions
  1. 33 142
      lib/pipeline/matcher/RegexMatchExpression.js

+ 33 - 142
lib/pipeline/matcher/RegexMatchExpression.js

@@ -1,17 +1,18 @@
-"use strict"
+"use strict";
 
+var LeafMatchExpression = require('./LeafMatchExpression');
 
 
 // Autogenerated by cport.py on 2013-09-17 14:37
-var RegexMatchExpression = module.exports = function (){
-
-}, klass = RegexMatchExpression, base =  Object  , proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
+var RegexMatchExpression = module.exports = function RegexMatchExpression(){
+	this._matchType = 'REGEX';
+}, klass = RegexMatchExpression, base =  LeafMatchExpression, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
 
 
 // File: expression_leaf.h lines: 160-160
 //         static const size_t MaxPatternSize = 32764;
 
-proto.MaxPatternSize = undefined;
+klass.MaxPatternSize = 32764;
 
 
 // File: expression_leaf.h lines: 184-184
@@ -31,51 +32,6 @@ proto._re = undefined;
 
 proto._regex = undefined;
 
-
-// File: expression_leaf.h lines: 160-160
-//         static const size_t MaxPatternSize = 32764;
-
-proto.MaxPatternSize = undefined;
-
-
-// File: expression_leaf.h lines: 184-184
-//         std::string _flags;
-
-proto._flags = undefined;
-
-
-// File: expression_leaf.h lines: 185-185
-//         boost::scoped_ptr<pcrecpp::RE> _re;
-
-proto._re = undefined;
-
-
-// File: expression_leaf.h lines: 183-183
-//         std::string _regex;
-
-proto._regex = undefined;
-
-
-
-
-
-/**
- * 
- * This documentation was automatically generated. Please update when you touch this function.
- * @method RegexMatchExpression
- * @param
- *
- */
-proto.RegexMatchExpression = function RegexMatchExpression( /*  REGEX  */ ){
-// File: expression_leaf.h lines: 162-161
-//         RegexMatchExpression() : LeafMatchExpression( REGEX ){}
-
-
-
-
-}
-
-
 /**
  * 
  * This documentation was automatically generated. Please update when you touch this function.
@@ -83,24 +39,10 @@ proto.RegexMatchExpression = function RegexMatchExpression( /*  REGEX  */ ){
  * @param
  *
  */
-proto.debugString = function debugString( /*  StringBuilder& debug, int level  */ ){
-
+proto.debugString = function debugString( level ) { //  StringBuilder& debug, int level
 // File: expression_leaf.cpp lines: 225-234
-//     void RegexMatchExpression::debugString( StringBuilder& debug, int level ) const {
-//         _debugAddSpace( debug, level );
-//         debug << path() << " regex /" << _regex << "/" << _flags;
-// 
-//         MatchExpression::TagData* td = getTag();
-//         if (NULL != td) {
-//             debug << " ";
-//             td->debugString(&debug);
-//         }
-//         debug << "\n";
-//     }
-
-
-
-}
+	return this._debugAddSpace( level ) + this.path() + " regex /" + this._regex + "/" + this._flags + (this.getTags() ? ' ' + this.getTags().debugString : '') + "\n";
+};
 
 
 /**
@@ -110,23 +52,10 @@ proto.debugString = function debugString( /*  StringBuilder& debug, int level  *
  * @param
  *
  */
-proto.equivalent = function equivalent( /*  const MatchExpression* other  */ ){
-
+proto.equivalent = function equivalent( other ) { //  const MatchExpression* other
 // File: expression_leaf.cpp lines: 177-185
-//     bool RegexMatchExpression::equivalent( const MatchExpression* other ) const {
-//         if ( matchType() != other->matchType() )
-//             return false;
-// 
-//         const RegexMatchExpression* realOther = static_cast<const RegexMatchExpression*>( other );
-//         return
-//             path() == realOther->path() &&
-//             _regex == realOther->_regex
-//             && _flags == realOther->_flags;
-//     }
-
-
-
-}
+	return other._matchType == 'REGEX' && this.path() == other.path() && this._regex == other._regex && this._flags == other._flags;
+};
 
 
 /**
@@ -138,12 +67,8 @@ proto.equivalent = function equivalent( /*  const MatchExpression* other  */ ){
  */
 proto.getFlags = function getFlags( /*  */ ){
 // File: expression_leaf.h lines: 180-179
-//         const string& getFlags() const { return _flags; }
-
-
-
-
-}
+	return this._flags;
+};
 
 
 /**
@@ -155,12 +80,8 @@ proto.getFlags = function getFlags( /*  */ ){
  */
 proto.getString = function getString( /*  */ ){
 // File: expression_leaf.h lines: 179-178
-//         const string& getString() const { return _regex; }
-
-
-
-
-}
+	return this._regex;
+};
 
 
 /**
@@ -170,24 +91,17 @@ proto.getString = function getString( /*  */ ){
  * @param
  *
  */
-proto.init = function init( /*  const StringData& path, const StringData& regex, const StringData& options  */ ){
-
+proto.init = function init( path,regex,flags ) { //  const StringData& path, const StringData& regex, const StringData& options
 // File: expression_leaf.cpp lines: 196-205
-//     Status RegexMatchExpression::init( const StringData& path, const StringData& regex, const StringData& options ) {
-//         if ( regex.size() > MaxPatternSize ) {
-//             return Status( ErrorCodes::BadValue, "Regular expression is too long" );
-//         }
-// 
-//         _regex = regex.toString();
-//         _flags = options.toString();
-//         _re.reset( new pcrecpp::RE( _regex.c_str(), flags2options( _flags.c_str() ) ) );
-// 
-//         return initPath( path );
-//     }
-
+	if(regex.length > klass.MaxPatternSize){
+		return {'code':'BAD_VALUE', 'desc':'Regular Expression too long.'};
+	}
 
-
-}
+	this._regex = regex;
+	this._flags = flags;
+	this._re = new RegExp(regex,flags);
+	return this.initPath( path );
+};
 
 
 /**
@@ -197,29 +111,11 @@ proto.init = function init( /*  const StringData& path, const StringData& regex,
  * @param
  *
  */
-proto.matchesSingleElement = function matchesSingleElement( /*  const BSONElement& e  */ ){
-
+proto.matchesSingleElement = function matchesSingleElement( e ) { //  const BSONElement& e
 // File: expression_leaf.cpp lines: 208-222
-//     bool RegexMatchExpression::matchesSingleElement( const BSONElement& e ) const {
-//         //log() << "RegexMatchExpression::matchesSingleElement _regex: " << _regex << " e: " << e << std::endl;
-//         switch (e.type()) {
-//         case String:
-//         case Symbol:
-//             // TODO
-//             //if (rm._prefix.empty())
-//                 return _re->PartialMatch(e.valuestr());
-//                 //else
-//                 //return !strncmp(e.valuestr(), rm._prefix.c_str(), rm._prefix.size());
-//         case RegEx:
-//             return _regex == e.regex() && _flags == e.regexFlags();
-//         default:
-//             return false;
-//         }
-//     }
-
-
-
-}
+	return (e.match) && e.match(this._re);
+	// No support for SYMBOLS currently
+};
 
 
 /**
@@ -231,13 +127,8 @@ proto.matchesSingleElement = function matchesSingleElement( /*  const BSONElemen
  */
 proto.shallowClone = function shallowClone( /*  */ ){
 // File: expression_leaf.h lines: 167-170
-//         virtual LeafMatchExpression* shallowClone() const {
-//             RegexMatchExpression* e = new RegexMatchExpression();
-//             e->init( path(), _regex, _flags );
-//             return e;
-//         }
-
-
-
+	var e = new RegexMatchExpression();
+	e.init( this.path(), this._regex, this._flags );
+	return e;
+};
 
-}