Skip to content

Commit

Permalink
SERVER-1270 Length uniform in all ctors (thanks Mathias)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberto Lerner committed Jul 7, 2010
1 parent 4bccb47 commit 13a235b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions bson/stringdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ namespace mongo {
using std::string;

struct StringData {
// TODO - Hook this class up in the BSON machinery
// There are two assumptions here that we may want to review then.
// 'data' *always* finishes with a null terminator
// 'size' does *not* account for the null terminator
// These assumptions may make it easier to minimize changes to existing code
const char* data;
const unsigned size;

Expand All @@ -35,10 +40,10 @@ namespace mongo {
StringData( const string& s )
: data(s.c_str()), size(s.size()) {}

struct literal_tag {};
struct LiteralTag {};
template<size_t N>
StringData( const char (&val)[N], literal_tag )
: data(&val[0]), size(N) {}
StringData( const char (&val)[N], LiteralTag )
: data(&val[0]), size(N-1) {}
};

} // namespace mongo
Expand Down

0 comments on commit 13a235b

Please sign in to comment.