diff options
author | Eliot Horowitz <eliot@10gen.com> | 2013-05-08 10:22:47 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2013-05-09 10:16:55 -0400 |
commit | f41cc12bf4672528f513fb81f1fab4b4b379ae83 (patch) | |
tree | 706cde2ccbcbbda3d895fd4bca46cc019f50607d /src/mongo/db/field_ref.cpp | |
parent | 0078fb7d2bc7cb352df42524399276fa51b7b110 (diff) | |
download | mongo-f41cc12bf4672528f513fb81f1fab4b4b379ae83.tar.gz |
SERVER-6400 FieldRef has a equalsDottedField to compare it to a full string
Diffstat (limited to 'src/mongo/db/field_ref.cpp')
-rw-r--r-- | src/mongo/db/field_ref.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/mongo/db/field_ref.cpp b/src/mongo/db/field_ref.cpp index c3dbc47ed5d..68ab798b320 100644 --- a/src/mongo/db/field_ref.cpp +++ b/src/mongo/db/field_ref.cpp @@ -16,6 +16,7 @@ #include "mongo/db/field_ref.h" +#include "mongo/util/log.h" #include "mongo/util/assert_util.h" namespace mongo { @@ -115,6 +116,34 @@ namespace mongo { return res; } + bool FieldRef::equalsDottedField( const StringData& other ) const { + StringData rest = other; + + + for ( size_t i = 0; i < _size; i++ ) { + + StringData part = getPart( i ); + + if ( !rest.startsWith( part ) ) + return false; + + if ( i == _size - 1 ) + return rest.size() == part.size(); + + // make sure next thing is a dot + if ( rest.size() == part.size() ) + return false; + + if ( rest[part.size()] != '.' ) + return false; + + rest = rest.substr( part.size() + 1 ); + } + + return false; + } + + size_t FieldRef::numReplaced() const { size_t res = 0; for (size_t i = 0; i < _replacements.size(); i++) { |