diff options
Diffstat (limited to 'src/mongo/db/field_ref.h')
-rw-r--r-- | src/mongo/db/field_ref.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/mongo/db/field_ref.h b/src/mongo/db/field_ref.h index ad354a0f39c..96368b8f547 100644 --- a/src/mongo/db/field_ref.h +++ b/src/mongo/db/field_ref.h @@ -30,6 +30,7 @@ #include <boost/optional.hpp> #include <iosfwd> +#include <set> #include <string> #include <vector> @@ -50,6 +51,12 @@ namespace mongo { */ class FieldRef { public: + /** + * Returns true if the argument is a numeric string which is eligible to act as the key name for + * an element in a BSON array; in other words, the string matches the regex ^(0|[1-9]+[0-9]*)$. + */ + static bool isNumericPathComponent(StringData component); + FieldRef() = default; explicit FieldRef(StringData path); @@ -94,11 +101,33 @@ public: bool isPrefixOf(const FieldRef& other) const; /** + * Returns true if 'this' FieldRef is a prefix of 'other', or if both paths are identical. + */ + bool isPrefixOfOrEqualTo(const FieldRef& other) const; + + /** * Returns the number of field parts in the prefix that 'this' and 'other' share. */ size_t commonPrefixSize(const FieldRef& other) const; /** + * Returns true if the specified path component is a numeric string which is eligible to act as + * the key name for an element in a BSON array; in other words, the fieldname matches the regex + * ^(0|[1-9]+[0-9]*)$. + */ + bool isNumericPathComponent(size_t i) const; + + /** + * Returns true if this FieldRef has any numeric path components. + */ + bool hasNumericPathComponents() const; + + /** + * Returns the positions of all numeric path components, starting from the given position. + */ + std::set<size_t> getNumericPathComponents(size_t startPart = 0) const; + + /** * Returns a StringData of the full dotted field in its current state (i.e., some parts may * have been replaced since the parse() call). */ |