23 #include "mongo/base/string_data.h"
24 #include "mongo/util/assert_util.h"
30 const size_t MaxDatabaseNameLen = 128;
67 MaxNsLenWithNUL = 128,
70 MaxNsLen = MaxNsLenWithNUL - 1,
74 MaxNsCollectionLen = MaxNsLen - 7 ,
80 const std::string& ns()
const {
84 operator const std::string&()
const {
87 const std::string& toString()
const {
95 bool isSystem()
const {
98 bool isSystemDotIndexes()
const {
99 return coll() ==
"system.indexes";
101 bool isConfigDB()
const {
102 return db() ==
"config";
104 bool isCommand()
const {
105 return coll() ==
"$cmd";
107 bool isOplog()
const {
110 bool isSpecialCommand()
const {
113 bool isSpecial()
const {
116 bool isNormal()
const {
119 bool isListCollectionsGetMore()
const;
120 bool isListIndexesGetMore()
const;
136 bool operator==(
const std::string& nsIn)
const {
139 bool operator==(
const StringData& nsIn)
const {
143 return nsIn._ns == _ns;
146 bool operator!=(
const std::string& nsIn)
const {
150 return nsIn._ns != _ns;
154 return _ns < rhs._ns;
159 std::string
getSisterNS(
const StringData& local)
const;
162 std::string getSystemIndexesCollection()
const;
165 std::string getCommandNS()
const;
171 static bool normal(
const StringData& ns);
176 static bool oplog(
const StringData& ns);
178 static bool special(
const StringData& ns);
230 inline StringData nsToDatabaseSubstring(
const StringData& ns) {
231 size_t i = ns.find(
'.');
232 if (i == std::string::npos) {
233 massert(10078,
"nsToDatabase: db too long", ns.size() < MaxDatabaseNameLen);
236 massert(10088,
"nsToDatabase: db too long", i < static_cast<size_t>(MaxDatabaseNameLen));
237 return ns.substr(0, i);
241 inline void nsToDatabase(
const StringData& ns,
char* database) {
242 StringData db = nsToDatabaseSubstring(ns);
243 db.copyTo(database,
true);
247 inline std::string nsToDatabase(
const StringData& ns) {
248 return nsToDatabaseSubstring(ns).toString();
252 inline StringData nsToCollectionSubstring(
const StringData& ns) {
253 size_t i = ns.find(
'.');
254 massert(16886,
"nsToCollectionSubstring: no .", i != std::string::npos);
255 return ns.substr(i + 1);
264 size_t i = ns.find(
'.');
265 if (i == std::string::npos)
267 if (i == ns.size() - 1)
278 size_t i = ns.find(
'.');
279 if (i == std::string::npos)
294 int nsDBHash(
const std::string& ns);
296 bool nsDBEquals(
const std::string& a,
const std::string& b);
299 int operator()(
const std::string& ns)
const {
305 bool operator()(
const std::string& a,
const std::string& b)
const {
306 return nsDBEquals(a, b);
312 #include "mongo/db/namespace_string-inl.h"
bool nsIsDbOnly(const StringData &ns)
foo = true foo.
Definition: namespace_string.h:277
static bool validCollectionComponent(const StringData &ns)
Takes a fully qualified namespace (ie dbname.collectionName), and returns true if the collection name...
Definition: namespace_string-inl.h:76
static bool oplog(const StringData &ns)
Definition: namespace_string-inl.h:38
A StringData object wraps a 'const string&' or a 'const char*' without copying its contents...
Definition: string_data.h:43
Utility functions for parsing numbers from strings.
Definition: compare_numbers.h:20
static bool normal(const StringData &ns)
Definition: namespace_string-inl.h:32
bool legalClientSystemNS(const StringData &ns, bool write)
static bool validDBName(const StringData &dbin)
samples: good foo bar foo-bar bad: foo bar foo.bar foo"bar
Definition: namespace_string-inl.h:46
NamespaceString getTargetNSForListIndexesGetMore() const
Given a NamespaceString for which isListIndexesGetMore() returns true, returns the NamespaceString fo...
NamespaceString()
Constructs an empty NamespaceString.
Definition: namespace_string-inl.h:104
Definition: namespace_string.h:42
MaxNsLenValue
Note that these values are derived from the mmap_v1 implementation and that is the only reason they a...
Definition: namespace_string.h:64
static bool validCollectionName(const StringData &coll)
Takes a collection name and returns true if it is a valid collection name.
Definition: namespace_string-inl.h:84
std::string getSisterNS(const StringData &local) const
( foo.bar ).getSisterNS( "blah" ) == foo.blah
Definition: namespace_string-inl.h:172
int nsDBHash(const std::string &ns)
NamespaceDBHash and NamespaceDBEquals allow you to do something like unordered_map and use the full namespace for the string but comparisons are done only on the db piece.
Definition: namespace_string-inl.h:130
bool isValid() const
Definition: namespace_string.h:132
bool startsWith(const StringData &prefix) const
Returns true if 'prefix' is a substring of this instance, anchored at position 0. ...
Definition: string_data-inl.h:109
Definition: namespace_string.h:304
bool nsIsFull(const StringData &ns)
foo = false foo.
Definition: namespace_string.h:263
Definition: namespace_string.h:298