19 #include "mongo/util/debug_util.h"
23 inline StringData NamespaceString::db()
const {
24 return _dotIndex == std::string::npos ? StringData() : StringData(_ns.c_str(), _dotIndex);
27 inline StringData NamespaceString::coll()
const {
28 return _dotIndex == std::string::npos ? StringData() : StringData(_ns.c_str() + _dotIndex + 1,
29 _ns.size() - 1 - _dotIndex);
33 if (ns.find(
'$') == std::string::npos)
42 inline bool NamespaceString::special(
const StringData& ns) {
43 return !
normal(ns) || ns.substr(ns.find(
'.')).startsWith(
".system.");
47 if (db.size() == 0 || db.size() > 64)
50 for (StringData::const_iterator iter = db.begin(), end = db.end(); iter != end; ++iter) {
77 size_t idx = ns.find(
'.');
78 if (idx == std::string::npos)
91 for (StringData::const_iterator iter = coll.begin(), end = coll.end(); iter != end; ++iter) {
106 _ns = nsIn.toString();
107 _dotIndex = _ns.find(
'.');
111 : _ns(dbName.size() + collectionName.size() + 1,
'\0') {
113 "'.' is an invalid character in a database name",
114 dbName.find(
'.') == std::string::npos);
116 "Collection names cannot start with '.'",
117 collectionName.empty() || collectionName[0] !=
'.');
118 std::string::iterator it = std::copy(dbName.begin(), dbName.end(), _ns.begin());
121 it = std::copy(collectionName.begin(), collectionName.end(), it);
122 _dotIndex = dbName.size();
123 dassert(it == _ns.end());
124 dassert(_ns[_dotIndex] ==
'.');
126 "namespaces cannot have embedded null characters",
127 _ns.find(
'\0') == std::string::npos);
132 for (
size_t i = 0; i < ns.size(); i++) {
135 hash += 11 * (ns[i]);
141 inline bool nsDBEquals(
const std::string& a,
const std::string& b) {
142 for (
size_t i = 0; i < a.size(); i++) {
165 if (b.size() == a.size() || b[a.size()] ==
'.')
173 verify(local.size() && local[0] !=
'.');
174 return db().toString() +
"." + local.toString();
177 inline std::string NamespaceString::getSystemIndexesCollection()
const {
178 return db().toString() +
".system.indexes";
181 inline std::string NamespaceString::getCommandNS()
const {
182 return db().toString() +
".$cmd";
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
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()
Constructs an empty NamespaceString.
Definition: namespace_string-inl.h:104
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 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