0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

SERVER-1270 Improve StringData (on behalf of Andrew Morrow)

This commit is contained in:
Alberto Lerner 2010-07-07 13:55:12 -04:00
parent 1dcdf8305b
commit 4bccb4792c
2 changed files with 46 additions and 15 deletions

46
bson/stringdata.h Normal file
View File

@ -0,0 +1,46 @@
// stringdata.h
/* Copyright 2010 10gen Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef UTIL_BSON_STRINGDATA_HEADER
#define UTIL_BSON_STRINGDATA_HEADER
#include <string>
#include <cstring>
namespace mongo {
using std::string;
struct StringData {
const char* data;
const unsigned size;
StringData( const char* c )
: data(c), size(strlen(c)) {}
StringData( const string& s )
: data(s.c_str()), size(s.size()) {}
struct literal_tag {};
template<size_t N>
StringData( const char (&val)[N], literal_tag )
: data(&val[0]), size(N) {}
};
} // namespace mongo
#endif // UTIL_BSON_STRINGDATA_HEADER

View File

@ -23,21 +23,6 @@ namespace mongo {
void splitStringDelim( const string& str , vector<string>* res , char delim );
void joinStringDelim( const vector<string>& strs , string* res , char delim );
struct StringData {
const char* data;
unsigned size;
StringData( const char * c ){
data = c;
size = strlen(c);
}
StringData( const string& s ){
data = s.c_str();
size = s.size();
}
};
} // namespace mongo