From 4bccb4792c8649b965fde46bb2c41a825526729f Mon Sep 17 00:00:00 2001 From: Alberto Lerner Date: Wed, 7 Jul 2010 13:55:12 -0400 Subject: [PATCH] SERVER-1270 Improve StringData (on behalf of Andrew Morrow) --- bson/stringdata.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ util/stringutils.h | 15 --------------- 2 files changed, 46 insertions(+), 15 deletions(-) create mode 100644 bson/stringdata.h diff --git a/bson/stringdata.h b/bson/stringdata.h new file mode 100644 index 00000000000..53cd83896bf --- /dev/null +++ b/bson/stringdata.h @@ -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 +#include + +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 + StringData( const char (&val)[N], literal_tag ) + : data(&val[0]), size(N) {} + }; + +} // namespace mongo + +#endif // UTIL_BSON_STRINGDATA_HEADER diff --git a/util/stringutils.h b/util/stringutils.h index 4919413d9ab..fff27128bd8 100644 --- a/util/stringutils.h +++ b/util/stringutils.h @@ -23,21 +23,6 @@ namespace mongo { void splitStringDelim( const string& str , vector* res , char delim ); void joinStringDelim( const vector& 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