summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBilly Donahue <billy.donahue@mongodb.com>2019-04-09 17:29:16 -0400
committerBilly Donahue <billy.donahue@mongodb.com>2019-04-11 17:01:01 -0400
commit96ad39f93f670e9e09a1e430898e3b9a8bd70f54 (patch)
treeb7a7507e3a25ea36683b8629c4b512abbea53c60
parent7dc8b27f5c34821d24a6751e68da4c62b4545495 (diff)
downloadmongo-96ad39f93f670e9e09a1e430898e3b9a8bd70f54.tar.gz
SERVER-40476 merge contents of utils/stringutils into utils/str.
-rw-r--r--src/mongo/SConscript2
-rw-r--r--src/mongo/base/data_type_terminated.cpp11
-rw-r--r--src/mongo/base/data_type_terminated_test.cpp1
-rw-r--r--src/mongo/bson/bsonelement.cpp13
-rw-r--r--src/mongo/bson/bsonobj.cpp3
-rw-r--r--src/mongo/db/auth/action_set.cpp5
-rw-r--r--src/mongo/db/auth/authorization_manager_impl.cpp2
-rw-r--r--src/mongo/db/auth/authz_manager_external_state_s.cpp1
-rw-r--r--src/mongo/db/auth/sasl_commands.cpp1
-rw-r--r--src/mongo/db/auth/user_document_parser.cpp3
-rw-r--r--src/mongo/db/auth/user_management_commands_parser.cpp3
-rw-r--r--src/mongo/db/catalog/rename_collection_test.cpp5
-rw-r--r--src/mongo/db/concurrency/lock_manager.cpp2
-rw-r--r--src/mongo/db/curop.cpp6
-rw-r--r--src/mongo/db/fts/fts_basic_tokenizer.cpp3
-rw-r--r--src/mongo/db/fts/fts_element_iterator.cpp1
-rw-r--r--src/mongo/db/fts/fts_language.cpp1
-rw-r--r--src/mongo/db/fts/fts_query_impl.cpp1
-rw-r--r--src/mongo/db/fts/fts_query_parser.cpp1
-rw-r--r--src/mongo/db/fts/fts_spec.cpp1
-rw-r--r--src/mongo/db/fts/fts_spec_legacy.cpp22
-rw-r--r--src/mongo/db/fts/fts_unicode_tokenizer.cpp1
-rw-r--r--src/mongo/db/fts/tokenizer.cpp1
-rw-r--r--src/mongo/db/kill_sessions_common.h2
-rw-r--r--src/mongo/db/mongod_options.cpp3
-rw-r--r--src/mongo/db/pipeline/document_path_support.cpp4
-rw-r--r--src/mongo/db/pipeline/document_source_match.cpp2
-rw-r--r--src/mongo/db/query/get_executor.cpp2
-rw-r--r--src/mongo/db/query/getmore_request.cpp2
-rw-r--r--src/mongo/db/query/parsed_distinct.cpp4
-rw-r--r--src/mongo/db/repl/repl_set_config.cpp4
-rw-r--r--src/mongo/db/s/balancer/balancer_policy.cpp2
-rw-r--r--src/mongo/db/s/get_database_version_command.cpp2
-rw-r--r--src/mongo/db/s/get_shard_version_command.cpp2
-rw-r--r--src/mongo/db/s/set_shard_version_command.cpp2
-rw-r--r--src/mongo/db/s/unset_sharding_command.cpp2
-rw-r--r--src/mongo/db/update/path_support.cpp5
-rw-r--r--src/mongo/db/update/update_driver.cpp1
-rw-r--r--src/mongo/db/update/update_leaf_node.cpp4
-rw-r--r--src/mongo/db/update/update_object_node.cpp4
-rw-r--r--src/mongo/dbtests/basictests.cpp2
-rw-r--r--src/mongo/dbtests/jsobjtests.cpp12
-rw-r--r--src/mongo/idl/server_parameter_with_storage.h4
-rw-r--r--src/mongo/logger/parse_log_component_settings.cpp1
-rw-r--r--src/mongo/platform/decimal128.cpp12
-rw-r--r--src/mongo/s/catalog/mongo_version_range.cpp11
-rw-r--r--src/mongo/s/mongos_options.cpp5
-rw-r--r--src/mongo/s/server.cpp2
-rw-r--r--src/mongo/scripting/mozjs/wrapconstrainedmethod.h2
-rw-r--r--src/mongo/shell/dbshell.cpp10
-rw-r--r--src/mongo/shell/shell_utils_launcher.cpp4
-rw-r--r--src/mongo/transport/service_executor_adaptive.cpp2
-rw-r--r--src/mongo/util/SConscript4
-rw-r--r--src/mongo/util/net/hostandport.cpp5
-rw-r--r--src/mongo/util/processinfo_solaris.cpp3
-rw-r--r--src/mongo/util/stacktrace_posix.cpp4
-rw-r--r--src/mongo/util/str.cpp (renamed from src/mongo/util/stringutils.cpp)18
-rw-r--r--src/mongo/util/str.h58
-rw-r--r--src/mongo/util/str_test.cpp (renamed from src/mongo/util/stringutils_test.cpp)8
-rw-r--r--src/mongo/util/stringutils.h116
60 files changed, 171 insertions, 249 deletions
diff --git a/src/mongo/SConscript b/src/mongo/SConscript
index dc0dc2b5628..8cf44ff1562 100644
--- a/src/mongo/SConscript
+++ b/src/mongo/SConscript
@@ -130,7 +130,7 @@ env.Library(
'util/stacktrace.cpp',
'util/stacktrace_${TARGET_OS_FAMILY}.cpp',
'util/startup_test.cpp',
- 'util/stringutils.cpp',
+ 'util/str.cpp',
'util/system_clock_source.cpp',
'util/system_tick_source.cpp',
'util/text.cpp',
diff --git a/src/mongo/base/data_type_terminated.cpp b/src/mongo/base/data_type_terminated.cpp
index 5074abbe22f..e3daa5d33dc 100644
--- a/src/mongo/base/data_type_terminated.cpp
+++ b/src/mongo/base/data_type_terminated.cpp
@@ -30,7 +30,6 @@
#include "mongo/base/data_type_terminated.h"
#include "mongo/util/str.h"
-#include "mongo/util/stringutils.h"
namespace mongo {
@@ -38,8 +37,8 @@ Status TerminatedHelper::makeLoadNoTerminalStatus(char c,
size_t length,
std::ptrdiff_t debug_offset) {
str::stream ss;
- ss << "couldn't locate terminal char (" << escape(StringData(&c, 1)) << ") in buffer[" << length
- << "] at offset: " << debug_offset;
+ ss << "couldn't locate terminal char (" << str::escape(StringData(&c, 1)) << ") in buffer["
+ << length << "] at offset: " << debug_offset;
return Status(ErrorCodes::Overflow, ss);
}
@@ -49,15 +48,15 @@ Status TerminatedHelper::makeLoadShortReadStatus(char c,
std::ptrdiff_t debug_offset) {
str::stream ss;
ss << "only read (" << read << ") bytes. (" << length << ") bytes to terminal char ("
- << escape(StringData(&c, 1)) << ") at offset: " << debug_offset;
+ << str::escape(StringData(&c, 1)) << ") at offset: " << debug_offset;
return Status(ErrorCodes::Overflow, ss);
}
Status TerminatedHelper::makeStoreStatus(char c, size_t length, std::ptrdiff_t debug_offset) {
str::stream ss;
- ss << "couldn't write terminal char (" << escape(StringData(&c, 1)) << ") in buffer[" << length
- << "] at offset: " << debug_offset;
+ ss << "couldn't write terminal char (" << str::escape(StringData(&c, 1)) << ") in buffer["
+ << length << "] at offset: " << debug_offset;
return Status(ErrorCodes::Overflow, ss);
}
diff --git a/src/mongo/base/data_type_terminated_test.cpp b/src/mongo/base/data_type_terminated_test.cpp
index 45635760c6e..d516626e3b9 100644
--- a/src/mongo/base/data_type_terminated_test.cpp
+++ b/src/mongo/base/data_type_terminated_test.cpp
@@ -32,7 +32,6 @@
#include "mongo/base/data_range.h"
#include "mongo/base/data_range_cursor.h"
#include "mongo/unittest/unittest.h"
-#include "mongo/util/stringutils.h"
#include <string>
namespace mongo {
diff --git a/src/mongo/bson/bsonelement.cpp b/src/mongo/bson/bsonelement.cpp
index 5bef012b292..605623fb54f 100644
--- a/src/mongo/bson/bsonelement.cpp
+++ b/src/mongo/bson/bsonelement.cpp
@@ -46,7 +46,6 @@
#include "mongo/util/scopeguard.h"
#include "mongo/util/str.h"
#include "mongo/util/string_map.h"
-#include "mongo/util/stringutils.h"
#include "mongo/util/uuid.h"
namespace mongo {
@@ -69,11 +68,11 @@ void BSONElement::jsonStringStream(JsonStringFormat format,
int pretty,
std::stringstream& s) const {
if (includeFieldNames)
- s << '"' << escape(fieldName()) << "\" : ";
+ s << '"' << str::escape(fieldName()) << "\" : ";
switch (type()) {
case mongo::String:
case Symbol:
- s << '"' << escape(string(valuestr(), valuestrsize() - 1)) << '"';
+ s << '"' << str::escape(string(valuestr(), valuestrsize() - 1)) << '"';
break;
case NumberLong:
if (format == TenGen) {
@@ -271,10 +270,10 @@ void BSONElement::jsonStringStream(JsonStringFormat format,
break;
case RegEx:
if (format == Strict) {
- s << "{ \"$regex\" : \"" << escape(regex());
+ s << "{ \"$regex\" : \"" << str::escape(regex());
s << "\", \"$options\" : \"" << regexFlags() << "\" }";
} else {
- s << "/" << escape(regex(), true) << "/";
+ s << "/" << str::escape(regex(), true) << "/";
// FIXME Worry about alpha order?
for (const char* f = regexFlags(); *f; ++f) {
switch (*f) {
@@ -292,14 +291,14 @@ void BSONElement::jsonStringStream(JsonStringFormat format,
case CodeWScope: {
BSONObj scope = codeWScopeObject();
if (!scope.isEmpty()) {
- s << "{ \"$code\" : \"" << escape(_asCode()) << "\" , "
+ s << "{ \"$code\" : \"" << str::escape(_asCode()) << "\" , "
<< "\"$scope\" : " << scope.jsonString() << " }";
break;
}
}
case Code:
- s << "\"" << escape(_asCode()) << "\"";
+ s << "\"" << str::escape(_asCode()) << "\"";
break;
case bsonTimestamp:
diff --git a/src/mongo/bson/bsonobj.cpp b/src/mongo/bson/bsonobj.cpp
index bae36f39544..57bbd59969b 100644
--- a/src/mongo/bson/bsonobj.cpp
+++ b/src/mongo/bson/bsonobj.cpp
@@ -39,7 +39,6 @@
#include "mongo/util/hex.h"
#include "mongo/util/log.h"
#include "mongo/util/str.h"
-#include "mongo/util/stringutils.h"
namespace mongo {
@@ -655,7 +654,7 @@ public:
bool operator()(const char* s1, const char* s2) const;
private:
- LexNumCmp _cmp;
+ str::LexNumCmp _cmp;
};
BSONIteratorSorted::ElementFieldCmp::ElementFieldCmp(bool isArray) : _cmp(!isArray) {}
diff --git a/src/mongo/db/auth/action_set.cpp b/src/mongo/db/auth/action_set.cpp
index 247a5dfac2c..84cefde250b 100644
--- a/src/mongo/db/auth/action_set.cpp
+++ b/src/mongo/db/auth/action_set.cpp
@@ -40,7 +40,6 @@
#include "mongo/bson/util/builder.h"
#include "mongo/util/log.h"
#include "mongo/util/str.h"
-#include "mongo/util/stringutils.h"
namespace mongo {
@@ -96,7 +95,7 @@ bool ActionSet::isSupersetOf(const ActionSet& other) const {
Status ActionSet::parseActionSetFromString(const std::string& actionsString, ActionSet* result) {
std::vector<std::string> actionsList;
- splitStringDelim(actionsString, &actionsList, ',');
+ str::splitStringDelim(actionsString, &actionsList, ',');
std::vector<std::string> unrecognizedActions;
Status status = parseActionSetFromStringVector(actionsList, result, &unrecognizedActions);
invariant(status);
@@ -104,7 +103,7 @@ Status ActionSet::parseActionSetFromString(const std::string& actionsString, Act
return Status::OK();
}
std::string unrecognizedActionsString;
- joinStringDelim(unrecognizedActions, &unrecognizedActionsString, ',');
+ str::joinStringDelim(unrecognizedActions, &unrecognizedActionsString, ',');
return Status(ErrorCodes::FailedToParse,
str::stream() << "Unrecognized action privilege strings: "
<< unrecognizedActionsString);
diff --git a/src/mongo/db/auth/authorization_manager_impl.cpp b/src/mongo/db/auth/authorization_manager_impl.cpp
index 10b4fd6bdc6..d97b1c5d4b9 100644
--- a/src/mongo/db/auth/authorization_manager_impl.cpp
+++ b/src/mongo/db/auth/authorization_manager_impl.cpp
@@ -157,7 +157,7 @@ public:
Status setFromString(const std::string& str) {
std::vector<std::string> strList;
- splitStringDelim(str, &strList, ',');
+ str::splitStringDelim(str, &strList, ',');
std::vector<UserName> out;
for (const auto& nameStr : strList) {
diff --git a/src/mongo/db/auth/authz_manager_external_state_s.cpp b/src/mongo/db/auth/authz_manager_external_state_s.cpp
index fe73ae30754..fdb23453592 100644
--- a/src/mongo/db/auth/authz_manager_external_state_s.cpp
+++ b/src/mongo/db/auth/authz_manager_external_state_s.cpp
@@ -47,7 +47,6 @@
#include "mongo/stdx/memory.h"
#include "mongo/util/net/ssl_types.h"
#include "mongo/util/str.h"
-#include "mongo/util/stringutils.h"
namespace mongo {
diff --git a/src/mongo/db/auth/sasl_commands.cpp b/src/mongo/db/auth/sasl_commands.cpp
index b9886aaa4f0..c733cbb632b 100644
--- a/src/mongo/db/auth/sasl_commands.cpp
+++ b/src/mongo/db/auth/sasl_commands.cpp
@@ -55,7 +55,6 @@
#include "mongo/util/log.h"
#include "mongo/util/sequence_util.h"
#include "mongo/util/str.h"
-#include "mongo/util/stringutils.h"
namespace mongo {
namespace {
diff --git a/src/mongo/db/auth/user_document_parser.cpp b/src/mongo/db/auth/user_document_parser.cpp
index 20387c19892..1c5da7795be 100644
--- a/src/mongo/db/auth/user_document_parser.cpp
+++ b/src/mongo/db/auth/user_document_parser.cpp
@@ -43,7 +43,6 @@
#include "mongo/db/namespace_string.h"
#include "mongo/util/log.h"
#include "mongo/util/str.h"
-#include "mongo/util/stringutils.h"
namespace mongo {
@@ -478,7 +477,7 @@ Status V2UserDocumentParser::initializeUserPrivilegesFromUserDocument(const BSON
}
if (unrecognizedActions.size()) {
std::string unrecognizedActionsString;
- joinStringDelim(unrecognizedActions, &unrecognizedActionsString, ',');
+ str::joinStringDelim(unrecognizedActions, &unrecognizedActionsString, ',');
warning() << "Encountered unrecognized actions \" " << unrecognizedActionsString
<< "\" while parsing user document for " << user->getName();
}
diff --git a/src/mongo/db/auth/user_management_commands_parser.cpp b/src/mongo/db/auth/user_management_commands_parser.cpp
index 8a03d8a4b7d..29f4bc53574 100644
--- a/src/mongo/db/auth/user_management_commands_parser.cpp
+++ b/src/mongo/db/auth/user_management_commands_parser.cpp
@@ -49,7 +49,6 @@
#include "mongo/db/jsobj.h"
#include "mongo/stdx/unordered_set.h"
#include "mongo/util/str.h"
-#include "mongo/util/stringutils.h"
namespace mongo {
namespace auth {
@@ -513,7 +512,7 @@ Status parseAndValidatePrivilegeArray(const BSONArray& privileges,
}
if (unrecognizedActions.size()) {
std::string unrecognizedActionsString;
- joinStringDelim(unrecognizedActions, &unrecognizedActionsString, ',');
+ str::joinStringDelim(unrecognizedActions, &unrecognizedActionsString, ',');
return Status(ErrorCodes::FailedToParse,
str::stream() << "Unrecognized action privilege strings: "
<< unrecognizedActionsString);
diff --git a/src/mongo/db/catalog/rename_collection_test.cpp b/src/mongo/db/catalog/rename_collection_test.cpp
index 3756072fcae..30aca29717f 100644
--- a/src/mongo/db/catalog/rename_collection_test.cpp
+++ b/src/mongo/db/catalog/rename_collection_test.cpp
@@ -61,7 +61,6 @@
#include "mongo/unittest/unittest.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/str.h"
-#include "mongo/util/stringutils.h"
namespace {
@@ -987,9 +986,9 @@ TEST_F(RenameCollectionTest, RenameDifferentDatabaseStayTempTrueSourceNotTempora
void _checkOplogEntries(const std::vector<std::string>& actualOplogEntries,
const std::vector<std::string>& expectedOplogEntries) {
std::string actualOplogEntriesStr;
- joinStringDelim(actualOplogEntries, &actualOplogEntriesStr, ',');
+ str::joinStringDelim(actualOplogEntries, &actualOplogEntriesStr, ',');
std::string expectedOplogEntriesStr;
- joinStringDelim(expectedOplogEntries, &expectedOplogEntriesStr, ',');
+ str::joinStringDelim(expectedOplogEntries, &expectedOplogEntriesStr, ',');
ASSERT_EQUALS(expectedOplogEntries.size(), actualOplogEntries.size())
<< "Incorrect number of oplog entries written to oplog. Actual: " << actualOplogEntriesStr
diff --git a/src/mongo/db/concurrency/lock_manager.cpp b/src/mongo/db/concurrency/lock_manager.cpp
index 237e182d8eb..0b12fa9a575 100644
--- a/src/mongo/db/concurrency/lock_manager.cpp
+++ b/src/mongo/db/concurrency/lock_manager.cpp
@@ -43,7 +43,7 @@
#include "mongo/db/concurrency/locker.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
-#include "mongo/util/stringutils.h"
+#include "mongo/util/str.h"
#include "mongo/util/timer.h"
namespace mongo {
diff --git a/src/mongo/db/curop.cpp b/src/mongo/db/curop.cpp
index 068de93ec44..2111f168edf 100644
--- a/src/mongo/db/curop.cpp
+++ b/src/mongo/db/curop.cpp
@@ -54,7 +54,7 @@
#include "mongo/util/hex.h"
#include "mongo/util/log.h"
#include "mongo/util/net/socket_utils.h"
-#include "mongo/util/stringutils.h"
+#include "mongo/util/str.h"
namespace mongo {
@@ -615,7 +615,7 @@ string OpDebug::report(Client* client,
if (clientMetadata) {
auto appName = clientMetadata.get().getApplicationName();
if (!appName.empty()) {
- s << " appName: \"" << escape(appName) << '\"';
+ s << " appName: \"" << str::escape(appName) << '\"';
}
}
@@ -687,7 +687,7 @@ string OpDebug::report(Client* client,
if (!errInfo.isOK()) {
s << " ok:" << 0;
if (!errInfo.reason().empty()) {
- s << " errMsg:\"" << escape(redact(errInfo.reason())) << "\"";
+ s << " errMsg:\"" << str::escape(redact(errInfo.reason())) << "\"";
}
s << " errName:" << errInfo.code();
s << " errCode:" << static_cast<int>(errInfo.code());
diff --git a/src/mongo/db/fts/fts_basic_tokenizer.cpp b/src/mongo/db/fts/fts_basic_tokenizer.cpp
index 0a46b562955..a7dab749790 100644
--- a/src/mongo/db/fts/fts_basic_tokenizer.cpp
+++ b/src/mongo/db/fts/fts_basic_tokenizer.cpp
@@ -38,7 +38,6 @@
#include "mongo/db/fts/tokenizer.h"
#include "mongo/stdx/memory.h"
#include "mongo/util/str.h"
-#include "mongo/util/stringutils.h"
namespace mongo {
namespace fts {
@@ -69,7 +68,7 @@ bool BasicFTSTokenizer::moveNext() {
continue;
}
- string word = tolowerString(token.data);
+ string word = str::toLower(token.data);
// Stop words are case-sensitive so we need them to be lower cased to check
// against the stop word list
diff --git a/src/mongo/db/fts/fts_element_iterator.cpp b/src/mongo/db/fts/fts_element_iterator.cpp
index 7589904c56e..ebca711dd2b 100644
--- a/src/mongo/db/fts/fts_element_iterator.cpp
+++ b/src/mongo/db/fts/fts_element_iterator.cpp
@@ -31,7 +31,6 @@
#include "mongo/db/fts/fts_spec.h"
#include "mongo/db/fts/fts_util.h"
#include "mongo/util/str.h"
-#include "mongo/util/stringutils.h"
#include <stack>
diff --git a/src/mongo/db/fts/fts_language.cpp b/src/mongo/db/fts/fts_language.cpp
index 518c8a8e9f4..faa54e79333 100644
--- a/src/mongo/db/fts/fts_language.cpp
+++ b/src/mongo/db/fts/fts_language.cpp
@@ -40,7 +40,6 @@
#include "mongo/util/assert_util.h"
#include "mongo/util/str.h"
#include "mongo/util/string_map.h"
-#include "mongo/util/stringutils.h"
namespace mongo {
diff --git a/src/mongo/db/fts/fts_query_impl.cpp b/src/mongo/db/fts/fts_query_impl.cpp
index 4fc03b24746..fffc4362fbb 100644
--- a/src/mongo/db/fts/fts_query_impl.cpp
+++ b/src/mongo/db/fts/fts_query_impl.cpp
@@ -36,7 +36,6 @@
#include "mongo/db/fts/fts_tokenizer.h"
#include "mongo/stdx/memory.h"
#include "mongo/util/str.h"
-#include "mongo/util/stringutils.h"
namespace mongo {
diff --git a/src/mongo/db/fts/fts_query_parser.cpp b/src/mongo/db/fts/fts_query_parser.cpp
index 4d86580374b..a346e03451b 100644
--- a/src/mongo/db/fts/fts_query_parser.cpp
+++ b/src/mongo/db/fts/fts_query_parser.cpp
@@ -31,7 +31,6 @@
#include "mongo/db/fts/fts_query_parser.h"
#include "mongo/util/str.h"
-#include "mongo/util/stringutils.h"
namespace mongo {
diff --git a/src/mongo/db/fts/fts_spec.cpp b/src/mongo/db/fts/fts_spec.cpp
index ec320a562f6..20560ccdad5 100644
--- a/src/mongo/db/fts/fts_spec.cpp
+++ b/src/mongo/db/fts/fts_spec.cpp
@@ -38,7 +38,6 @@
#include "mongo/db/fts/fts_util.h"
#include "mongo/db/matcher/expression_parser.h"
#include "mongo/util/str.h"
-#include "mongo/util/stringutils.h"
namespace mongo {
diff --git a/src/mongo/db/fts/fts_spec_legacy.cpp b/src/mongo/db/fts/fts_spec_legacy.cpp
index b5e61b2f535..53169f5e213 100644
--- a/src/mongo/db/fts/fts_spec_legacy.cpp
+++ b/src/mongo/db/fts/fts_spec_legacy.cpp
@@ -31,7 +31,6 @@
#include "mongo/db/bson/dotted_path_support.h"
#include "mongo/util/str.h"
-#include "mongo/util/stringutils.h"
namespace mongo {
@@ -42,9 +41,6 @@ namespace fts {
// text indexes.
//
-using std::map;
-using std::string;
-
namespace dps = ::mongo::dotted_path_support;
namespace {
@@ -81,7 +77,7 @@ void FTSSpec::_scoreStringV1(const Tools& tools,
if (t.type != Token::TEXT)
continue;
- string term = tolowerString(t.data);
+ std::string term = str::toLower(t.data);
if (tools.stopwords->isStopWord(term))
continue;
term = tools.stemmer->stem(term).toString();
@@ -99,7 +95,7 @@ void FTSSpec::_scoreStringV1(const Tools& tools,
}
for (ScoreHelperMap::const_iterator i = terms.begin(); i != terms.end(); ++i) {
- const string& term = i->first;
+ const std::string& term = i->first;
const ScoreHelperStruct& data = i->second;
// in order to adjust weights as a function of term count as it
@@ -195,7 +191,7 @@ void FTSSpec::_scoreDocumentV1(const BSONObj& obj, TermFrequencyMap* term_freqs)
}
StatusWith<BSONObj> FTSSpec::_fixSpecV1(const BSONObj& spec) {
- map<string, int> m;
+ std::map<std::string, int> m;
BSONObj keyPattern;
{
@@ -240,24 +236,24 @@ StatusWith<BSONObj> FTSSpec::_fixSpecV1(const BSONObj& spec) {
BSONObj weights;
{
BSONObjBuilder b;
- for (map<string, int>::iterator i = m.begin(); i != m.end(); ++i) {
- if (i->second <= 0 || i->second >= MAX_WORD_WEIGHT) {
+ for (const auto& kv : m) {
+ if (kv.second <= 0 || kv.second >= MAX_WORD_WEIGHT) {
return {ErrorCodes::CannotCreateIndex,
str::stream() << "text index weight must be in the exclusive interval (0,"
<< MAX_WORD_WEIGHT
<< ") but found: "
- << i->second};
+ << kv.second};
}
- b.append(i->first, i->second);
+ b.append(kv.first, kv.second);
}
weights = b.obj();
}
- string default_language(spec.getStringField("default_language"));
+ std::string default_language(spec.getStringField("default_language"));
if (default_language.empty())
default_language = "english";
- string language_override(spec.getStringField("language_override"));
+ std::string language_override(spec.getStringField("language_override"));
if (language_override.empty())
language_override = "language";
diff --git a/src/mongo/db/fts/fts_unicode_tokenizer.cpp b/src/mongo/db/fts/fts_unicode_tokenizer.cpp
index f4db4881cb5..ab27d3a5c6a 100644
--- a/src/mongo/db/fts/fts_unicode_tokenizer.cpp
+++ b/src/mongo/db/fts/fts_unicode_tokenizer.cpp
@@ -38,7 +38,6 @@
#include "mongo/db/fts/tokenizer.h"
#include "mongo/stdx/memory.h"
#include "mongo/util/str.h"
-#include "mongo/util/stringutils.h"
namespace mongo {
namespace fts {
diff --git a/src/mongo/db/fts/tokenizer.cpp b/src/mongo/db/fts/tokenizer.cpp
index 2847f7486a8..3de9eb00689 100644
--- a/src/mongo/db/fts/tokenizer.cpp
+++ b/src/mongo/db/fts/tokenizer.cpp
@@ -31,7 +31,6 @@
#include "mongo/db/fts/tokenizer.h"
#include "mongo/util/str.h"
-#include "mongo/util/stringutils.h"
namespace mongo {
diff --git a/src/mongo/db/kill_sessions_common.h b/src/mongo/db/kill_sessions_common.h
index 95361aa5cfe..2200183fe73 100644
--- a/src/mongo/db/kill_sessions_common.h
+++ b/src/mongo/db/kill_sessions_common.h
@@ -38,7 +38,7 @@
#include "mongo/db/operation_context.h"
#include "mongo/db/session_killer.h"
#include "mongo/stdx/unordered_set.h"
-#include "mongo/util/stringutils.h"
+#include "mongo/util/str.h"
namespace mongo {
diff --git a/src/mongo/db/mongod_options.cpp b/src/mongo/db/mongod_options.cpp
index 93debb74db2..62d28f73b50 100644
--- a/src/mongo/db/mongod_options.cpp
+++ b/src/mongo/db/mongod_options.cpp
@@ -55,7 +55,6 @@
#include "mongo/util/net/ssl_options.h"
#include "mongo/util/options_parser/startup_options.h"
#include "mongo/util/str.h"
-#include "mongo/util/stringutils.h"
#include "mongo/util/version.h"
namespace mongo {
@@ -451,7 +450,7 @@ Status storeMongodOptions(const moe::Environment& params) {
for (const std::string& whitelistEntry :
params["security.clusterIpSourceWhitelist"].as<std::vector<std::string>>()) {
std::vector<std::string> intermediates;
- splitStringDelim(whitelistEntry, &intermediates, ',');
+ str::splitStringDelim(whitelistEntry, &intermediates, ',');
std::copy(intermediates.begin(),
intermediates.end(),
std::back_inserter(*mongodGlobalParams.whitelistedClusterNetwork));
diff --git a/src/mongo/db/pipeline/document_path_support.cpp b/src/mongo/db/pipeline/document_path_support.cpp
index cd641cdc07b..d89f122463c 100644
--- a/src/mongo/db/pipeline/document_path_support.cpp
+++ b/src/mongo/db/pipeline/document_path_support.cpp
@@ -38,7 +38,7 @@
#include "mongo/db/pipeline/document.h"
#include "mongo/db/pipeline/field_path.h"
#include "mongo/db/pipeline/value.h"
-#include "mongo/util/stringutils.h"
+#include "mongo/util/str.h"
namespace mongo {
namespace document_path_support {
@@ -81,7 +81,7 @@ void visitAllValuesAtPathHelper(Document doc,
// positional specifications, if applicable. For example, it will consume "0" and "1" from the
// path "a.0.1.b" if the value at "a" is an array with arrays inside it.
while (fieldPathIndex < path.getPathLength() && nextValue.isArray()) {
- if (auto index = parseUnsignedBase10Integer(path.getFieldName(fieldPathIndex))) {
+ if (auto index = str::parseUnsignedBase10Integer(path.getFieldName(fieldPathIndex))) {
nextValue = nextValue[*index];
++fieldPathIndex;
} else {
diff --git a/src/mongo/db/pipeline/document_source_match.cpp b/src/mongo/db/pipeline/document_source_match.cpp
index 0a269db2451..b89c04b3a87 100644
--- a/src/mongo/db/pipeline/document_source_match.cpp
+++ b/src/mongo/db/pipeline/document_source_match.cpp
@@ -42,7 +42,7 @@
#include "mongo/db/pipeline/expression.h"
#include "mongo/db/pipeline/lite_parsed_document_source.h"
#include "mongo/stdx/memory.h"
-#include "mongo/util/stringutils.h"
+#include "mongo/util/str.h"
namespace mongo {
diff --git a/src/mongo/db/query/get_executor.cpp b/src/mongo/db/query/get_executor.cpp
index 03339229f1e..727f6d52449 100644
--- a/src/mongo/db/query/get_executor.cpp
+++ b/src/mongo/db/query/get_executor.cpp
@@ -86,7 +86,7 @@
#include "mongo/scripting/engine.h"
#include "mongo/stdx/memory.h"
#include "mongo/util/log.h"
-#include "mongo/util/stringutils.h"
+#include "mongo/util/str.h"
namespace mongo {
diff --git a/src/mongo/db/query/getmore_request.cpp b/src/mongo/db/query/getmore_request.cpp
index 361dcf398db..e577671f2fd 100644
--- a/src/mongo/db/query/getmore_request.cpp
+++ b/src/mongo/db/query/getmore_request.cpp
@@ -40,7 +40,7 @@
#include "mongo/db/namespace_string.h"
#include "mongo/db/repl/bson_extract_optime.h"
#include "mongo/util/assert_util.h"
-#include "mongo/util/stringutils.h"
+#include "mongo/util/str.h"
namespace mongo {
diff --git a/src/mongo/db/query/parsed_distinct.cpp b/src/mongo/db/query/parsed_distinct.cpp
index b570b160a94..646fc2be778 100644
--- a/src/mongo/db/query/parsed_distinct.cpp
+++ b/src/mongo/db/query/parsed_distinct.cpp
@@ -57,7 +57,7 @@ namespace {
std::string getProjectedDottedField(const std::string& field, bool* isIDOut) {
// Check if field contains an array index.
std::vector<std::string> res;
- mongo::splitStringDelim(field, &res, '.');
+ str::splitStringDelim(field, &res, '.');
// Since we could exit early from the loop,
// we should check _id here and set '*isIDOut' accordingly.
@@ -78,7 +78,7 @@ std::string getProjectedDottedField(const std::string& field, bool* isIDOut) {
// string
// to the end of projectedField.
std::string projectedField;
- mongo::joinStringDelim(prefixStrings, &projectedField, '.');
+ str::joinStringDelim(prefixStrings, &projectedField, '.');
return projectedField;
}
}
diff --git a/src/mongo/db/repl/repl_set_config.cpp b/src/mongo/db/repl/repl_set_config.cpp
index 347e15df311..6b67b047733 100644
--- a/src/mongo/db/repl/repl_set_config.cpp
+++ b/src/mongo/db/repl/repl_set_config.cpp
@@ -39,7 +39,7 @@
#include "mongo/db/mongod_options.h"
#include "mongo/db/server_options.h"
#include "mongo/stdx/functional.h"
-#include "mongo/util/stringutils.h"
+#include "mongo/util/str.h"
namespace mongo {
namespace repl {
@@ -707,7 +707,7 @@ StatusWith<ReplSetTagPattern> ReplSetConfig::findCustomWriteMode(StringData patt
if (iter == _customWriteConcernModes.end()) {
return StatusWith<ReplSetTagPattern>(
ErrorCodes::UnknownReplWriteConcern,
- str::stream() << "No write concern mode named '" << escape(patternName.toString())
+ str::stream() << "No write concern mode named '" << str::escape(patternName.toString())
<< "' found in replica set configuration");
}
return StatusWith<ReplSetTagPattern>(iter->second);
diff --git a/src/mongo/db/s/balancer/balancer_policy.cpp b/src/mongo/db/s/balancer/balancer_policy.cpp
index 32c79756d7c..a12893339d1 100644
--- a/src/mongo/db/s/balancer/balancer_policy.cpp
+++ b/src/mongo/db/s/balancer/balancer_policy.cpp
@@ -36,7 +36,7 @@
#include "mongo/s/catalog/type_shard.h"
#include "mongo/s/catalog/type_tags.h"
#include "mongo/util/log.h"
-#include "mongo/util/stringutils.h"
+#include "mongo/util/str.h"
namespace mongo {
diff --git a/src/mongo/db/s/get_database_version_command.cpp b/src/mongo/db/s/get_database_version_command.cpp
index 16e63db0498..71fc3e4b8ad 100644
--- a/src/mongo/db/s/get_database_version_command.cpp
+++ b/src/mongo/db/s/get_database_version_command.cpp
@@ -39,7 +39,7 @@
#include "mongo/db/commands.h"
#include "mongo/db/s/database_sharding_state.h"
#include "mongo/s/request_types/get_database_version_gen.h"
-#include "mongo/util/stringutils.h"
+#include "mongo/util/str.h"
namespace mongo {
namespace {
diff --git a/src/mongo/db/s/get_shard_version_command.cpp b/src/mongo/db/s/get_shard_version_command.cpp
index bededaabe3b..87ea9653eb1 100644
--- a/src/mongo/db/s/get_shard_version_command.cpp
+++ b/src/mongo/db/s/get_shard_version_command.cpp
@@ -42,7 +42,7 @@
#include "mongo/db/s/sharding_state.h"
#include "mongo/s/grid.h"
#include "mongo/util/log.h"
-#include "mongo/util/stringutils.h"
+#include "mongo/util/str.h"
namespace mongo {
namespace {
diff --git a/src/mongo/db/s/set_shard_version_command.cpp b/src/mongo/db/s/set_shard_version_command.cpp
index 2be706a5428..d77baa5ec17 100644
--- a/src/mongo/db/s/set_shard_version_command.cpp
+++ b/src/mongo/db/s/set_shard_version_command.cpp
@@ -51,7 +51,7 @@
#include "mongo/s/grid.h"
#include "mongo/s/request_types/set_shard_version_request.h"
#include "mongo/util/log.h"
-#include "mongo/util/stringutils.h"
+#include "mongo/util/str.h"
namespace mongo {
namespace {
diff --git a/src/mongo/db/s/unset_sharding_command.cpp b/src/mongo/db/s/unset_sharding_command.cpp
index fa6f102a609..61ceb352b0a 100644
--- a/src/mongo/db/s/unset_sharding_command.cpp
+++ b/src/mongo/db/s/unset_sharding_command.cpp
@@ -39,7 +39,7 @@
#include "mongo/db/operation_context.h"
#include "mongo/db/s/sharded_connection_info.h"
#include "mongo/util/log.h"
-#include "mongo/util/stringutils.h"
+#include "mongo/util/str.h"
namespace mongo {
namespace {
diff --git a/src/mongo/db/update/path_support.cpp b/src/mongo/db/update/path_support.cpp
index 5b470c0dc94..6b9fc80a284 100644
--- a/src/mongo/db/update/path_support.cpp
+++ b/src/mongo/db/update/path_support.cpp
@@ -35,7 +35,6 @@
#include "mongo/bson/mutable/element.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/str.h"
-#include "mongo/util/stringutils.h"
namespace mongo {
namespace pathsupport {
@@ -99,7 +98,7 @@ Status findLongestPrefix(const FieldRef& prefix,
break;
case Array:
- numericPart = parseUnsignedBase10Integer(prefixPart);
+ numericPart = str::parseUnsignedBase10Integer(prefixPart);
if (!numericPart) {
viable = false;
} else {
@@ -172,7 +171,7 @@ StatusWith<mutablebson::Element> createPathAt(const FieldRef& prefix,
size_t i = idxFound;
bool inArray = false;
if (elemFound.getType() == mongo::Array) {
- boost::optional<size_t> newIdx = parseUnsignedBase10Integer(prefix.getPart(idxFound));
+ boost::optional<size_t> newIdx = str::parseUnsignedBase10Integer(prefix.getPart(idxFound));
if (!newIdx) {
return Status(ErrorCodes::PathNotViable,
str::stream() << "Cannot create field '" << prefix.getPart(idxFound)
diff --git a/src/mongo/db/update/update_driver.cpp b/src/mongo/db/update/update_driver.cpp
index d50a3c9f26f..a897f5739cd 100644
--- a/src/mongo/db/update/update_driver.cpp
+++ b/src/mongo/db/update/update_driver.cpp
@@ -46,7 +46,6 @@
#include "mongo/db/update/storage_validation.h"
#include "mongo/util/embedded_builder.h"
#include "mongo/util/str.h"
-#include "mongo/util/stringutils.h"
namespace mongo {
diff --git a/src/mongo/db/update/update_leaf_node.cpp b/src/mongo/db/update/update_leaf_node.cpp
index 2739ec1efd8..5d1f8931b53 100644
--- a/src/mongo/db/update/update_leaf_node.cpp
+++ b/src/mongo/db/update/update_leaf_node.cpp
@@ -31,7 +31,7 @@
#include "mongo/db/update/update_leaf_node.h"
-#include "mongo/util/stringutils.h"
+#include "mongo/util/str.h"
namespace mongo {
@@ -44,7 +44,7 @@ void UpdateLeafNode::checkViability(mutablebson::Element element,
// 'pathTaken' leads to an object, so we know it will be possible to create 'pathToCreate'
// at that path.
} else if (element.getType() == BSONType::Array &&
- parseUnsignedBase10Integer(pathToCreate.getPart(0))) {
+ str::parseUnsignedBase10Integer(pathToCreate.getPart(0))) {
// 'pathTaken' leads to an array, so we know we can add elements at that path so long as the
// next component is a valid array index. We don't check, but we expect that the index will
// be out of bounds. (Otherwise it would be part of 'pathTaken' and we wouldn't need to
diff --git a/src/mongo/db/update/update_object_node.cpp b/src/mongo/db/update/update_object_node.cpp
index e71f273bdff..3ca3a85f797 100644
--- a/src/mongo/db/update/update_object_node.cpp
+++ b/src/mongo/db/update/update_object_node.cpp
@@ -37,7 +37,7 @@
#include "mongo/db/update/update_array_node.h"
#include "mongo/db/update/update_leaf_node.h"
#include "mongo/stdx/memory.h"
-#include "mongo/util/stringutils.h"
+#include "mongo/util/str.h"
namespace mongo {
@@ -89,7 +89,7 @@ mutablebson::Element getChild(mutablebson::Element element, StringData field) {
if (element.getType() == BSONType::Object) {
return element[field];
} else if (element.getType() == BSONType::Array) {
- auto indexFromField = parseUnsignedBase10Integer(field);
+ auto indexFromField = str::parseUnsignedBase10Integer(field);
if (indexFromField) {
return element.findNthChild(*indexFromField);
}
diff --git a/src/mongo/dbtests/basictests.cpp b/src/mongo/dbtests/basictests.cpp
index 6a07c011e69..c6a53840094 100644
--- a/src/mongo/dbtests/basictests.cpp
+++ b/src/mongo/dbtests/basictests.cpp
@@ -35,7 +35,7 @@
#include "mongo/dbtests/dbtests.h"
#include "mongo/util/base64.h"
#include "mongo/util/queue.h"
-#include "mongo/util/stringutils.h"
+#include "mongo/util/str.h"
#include "mongo/util/text.h"
#include "mongo/util/thread_safe_string.h"
#include "mongo/util/timer.h"
diff --git a/src/mongo/dbtests/jsobjtests.cpp b/src/mongo/dbtests/jsobjtests.cpp
index 3ef6d5c2eaf..65b4b142ac1 100644
--- a/src/mongo/dbtests/jsobjtests.cpp
+++ b/src/mongo/dbtests/jsobjtests.cpp
@@ -50,7 +50,7 @@
#include "mongo/util/allocator.h"
#include "mongo/util/embedded_builder.h"
#include "mongo/util/log.h"
-#include "mongo/util/stringutils.h"
+#include "mongo/util/str.h"
#include "mongo/util/timer.h"
namespace mongo {
@@ -126,7 +126,9 @@ BSONObj nested2dotted(const BSONObj& obj) {
return b.obj();
}
-FieldCompareResult compareDottedFieldNames(const string& l, const string& r, const LexNumCmp& cmp) {
+FieldCompareResult compareDottedFieldNames(const string& l,
+ const string& r,
+ const str::LexNumCmp& cmp) {
static int maxLoops = 1024 * 1024;
size_t lstart = 0;
@@ -783,7 +785,7 @@ public:
BSONObj obj = BSON("str" << input);
const string output = obj.firstElement().String();
- ASSERT_EQUALS(escape(output), escape(input)); // for better failure output
+ ASSERT_EQUALS(str::escape(output), str::escape(input)); // for better failure output
ASSERT_EQUALS(output, input);
}
};
@@ -1550,7 +1552,7 @@ public:
class CompareDottedFieldNamesTest {
public:
void t(FieldCompareResult res, const string& l, const string& r) {
- LexNumCmp cmp(true);
+ str::LexNumCmp cmp(true);
ASSERT_EQUALS(res, compareDottedFieldNames(l, r, cmp));
ASSERT_EQUALS(-1 * res, compareDottedFieldNames(r, l, cmp));
}
@@ -1571,7 +1573,7 @@ public:
class CompareDottedArrayFieldNamesTest {
public:
void t(FieldCompareResult res, const string& l, const string& r) {
- LexNumCmp cmp(false); // Specify numeric comparison for array field names.
+ str::LexNumCmp cmp(false); // Specify numeric comparison for array field names.
ASSERT_EQUALS(res, compareDottedFieldNames(l, r, cmp));
ASSERT_EQUALS(-1 * res, compareDottedFieldNames(r, l, cmp));
}
diff --git a/src/mongo/idl/server_parameter_with_storage.h b/src/mongo/idl/server_parameter_with_storage.h
index 81b1517135e..0da90e950f7 100644
--- a/src/mongo/idl/server_parameter_with_storage.h
+++ b/src/mongo/idl/server_parameter_with_storage.h
@@ -45,7 +45,7 @@
#include "mongo/idl/server_parameter.h"
#include "mongo/platform/atomic_proxy.h"
#include "mongo/platform/atomic_word.h"
-#include "mongo/util/stringutils.h"
+#include "mongo/util/str.h"
#include "mongo/util/synchronized_value.h"
namespace mongo {
@@ -81,7 +81,7 @@ template <>
inline StatusWith<std::vector<std::string>> coerceFromString<std::vector<std::string>>(
StringData str) {
std::vector<std::string> v;
- splitStringDelim(str.toString(), &v, ',');
+ str::splitStringDelim(str.toString(), &v, ',');
return v;
}
diff --git a/src/mongo/logger/parse_log_component_settings.cpp b/src/mongo/logger/parse_log_component_settings.cpp
index 5c9f1688f32..7a8ee40f7cc 100644
--- a/src/mongo/logger/parse_log_component_settings.cpp
+++ b/src/mongo/logger/parse_log_component_settings.cpp
@@ -42,7 +42,6 @@
#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
#include "mongo/util/str.h"
-#include "mongo/util/stringutils.h"
namespace mongo {
namespace logger {
diff --git a/src/mongo/platform/decimal128.cpp b/src/mongo/platform/decimal128.cpp
index 69ef39d593d..94581933375 100644
--- a/src/mongo/platform/decimal128.cpp
+++ b/src/mongo/platform/decimal128.cpp
@@ -47,11 +47,21 @@
#undef _WCHAR_T
#include "mongo/base/static_assert.h"
+#include "mongo/base/string_data.h"
#include "mongo/config.h"
#include "mongo/util/assert_util.h"
-#include "mongo/util/stringutils.h"
+#include "mongo/util/str.h"
namespace {
+
+std::string toAsciiLowerCase(mongo::StringData input) {
+ std::string res = input.toString();
+ for (char& c : res) {
+ c = tolower(c);
+ }
+ return res;
+}
+
void validateInputString(mongo::StringData input, std::uint32_t* signalingFlags) {
// Input must be of these forms:
// * Valid decimal (standard or scientific notation):
diff --git a/src/mongo/s/catalog/mongo_version_range.cpp b/src/mongo/s/catalog/mongo_version_range.cpp
index f1aa116ddeb..c92fcb0b749 100644
--- a/src/mongo/s/catalog/mongo_version_range.cpp
+++ b/src/mongo/s/catalog/mongo_version_range.cpp
@@ -31,7 +31,7 @@
#include "mongo/s/catalog/mongo_version_range.h"
-#include "mongo/util/stringutils.h"
+#include "mongo/util/str.h"
namespace mongo {
@@ -92,7 +92,7 @@ bool MongoVersionRange::parseBSONElement(const BSONElement& el, string* errMsg)
return false;
}
- if (versionCmp(minVersion, maxVersion) > 0) {
+ if (str::versionCmp(minVersion, maxVersion) > 0) {
string swap = minVersion;
minVersion = maxVersion;
maxVersion = swap;
@@ -131,7 +131,8 @@ bool MongoVersionRange::isInRange(StringData version) const {
return true;
if (version.find(maxVersion) == 0)
return true;
- if (versionCmp(minVersion, version) <= 0 && versionCmp(maxVersion, version) >= 0) {
+ if (str::versionCmp(minVersion, version) <= 0 &&
+ str::versionCmp(maxVersion, version) >= 0) {
return true;
}
}
@@ -140,8 +141,8 @@ bool MongoVersionRange::isInRange(StringData version) const {
}
bool isInMongoVersionRanges(StringData version, const vector<MongoVersionRange>& ranges) {
- for (vector<MongoVersionRange>::const_iterator it = ranges.begin(); it != ranges.end(); ++it) {
- if (it->isInRange(version))
+ for (const auto& r : ranges) {
+ if (r.isInRange(version))
return true;
}
diff --git a/src/mongo/s/mongos_options.cpp b/src/mongo/s/mongos_options.cpp
index 0cfa74fb7d0..f00243433e8 100644
--- a/src/mongo/s/mongos_options.cpp
+++ b/src/mongo/s/mongos_options.cpp
@@ -49,7 +49,6 @@
#include "mongo/util/options_parser/startup_options.h"
#include "mongo/util/startup_test.h"
#include "mongo/util/str.h"
-#include "mongo/util/stringutils.h"
namespace mongo {
@@ -145,10 +144,10 @@ Status storeMongosOptions(const moe::Environment& params) {
if (!resolvedSomeSeedSever) {
if (!hostbyname(configdbConnectionString.getValue().getSetName().c_str()).empty()) {
warning() << "The replica set name \""
- << escape(configdbConnectionString.getValue().getSetName())
+ << str::escape(configdbConnectionString.getValue().getSetName())
<< "\" resolves as a host name, but none of the servers in the seed list do. "
"Did you reverse the replica set name and the seed list in "
- << escape(configdbConnectionString.getValue().toString()) << "?";
+ << str::escape(configdbConnectionString.getValue().toString()) << "?";
}
}
diff --git a/src/mongo/s/server.cpp b/src/mongo/s/server.cpp
index c75e286f3ea..9a8e6ebe71a 100644
--- a/src/mongo/s/server.cpp
+++ b/src/mongo/s/server.cpp
@@ -110,7 +110,7 @@
#include "mongo/util/quick_exit.h"
#include "mongo/util/signal_handlers.h"
#include "mongo/util/stacktrace.h"
-#include "mongo/util/stringutils.h"
+#include "mongo/util/str.h"
#include "mongo/util/text.h"
#include "mongo/util/version.h"
diff --git a/src/mongo/scripting/mozjs/wrapconstrainedmethod.h b/src/mongo/scripting/mozjs/wrapconstrainedmethod.h
index e95f41dda7c..12a94458896 100644
--- a/src/mongo/scripting/mozjs/wrapconstrainedmethod.h
+++ b/src/mongo/scripting/mozjs/wrapconstrainedmethod.h
@@ -35,7 +35,7 @@
#include "mongo/scripting/mozjs/objectwrapper.h"
#include "mongo/scripting/mozjs/valuewriter.h"
#include "mongo/util/assert_util.h"
-#include "mongo/util/stringutils.h"
+#include "mongo/util/str.h"
namespace mongo {
namespace mozjs {
diff --git a/src/mongo/shell/dbshell.cpp b/src/mongo/shell/dbshell.cpp
index 46cf674fea5..f80ac260ec6 100644
--- a/src/mongo/shell/dbshell.cpp
+++ b/src/mongo/shell/dbshell.cpp
@@ -68,7 +68,7 @@
#include "mongo/util/signal_handlers.h"
#include "mongo/util/stacktrace.h"
#include "mongo/util/startup_test.h"
-#include "mongo/util/stringutils.h"
+#include "mongo/util/str.h"
#include "mongo/util/text.h"
#include "mongo/util/version.h"
@@ -844,7 +844,7 @@ int _main(int argc, char* argv[], char** envp) {
// Parse the output of getURIFromArgs which will determine if --host passed in a URI
MongoURI parsedURI;
parsedURI = uassertStatusOK(MongoURI::parse(getURIFromArgs(
- cmdlineURI, escape(shellGlobalParams.dbhost), escape(shellGlobalParams.port))));
+ cmdlineURI, str::escape(shellGlobalParams.dbhost), str::escape(shellGlobalParams.port))));
// TODO: add in all of the relevant shellGlobalParams to parsedURI
parsedURI.setOptionIfNecessary("compressors"s, shellGlobalParams.networkMessageCompressors);
@@ -855,14 +855,14 @@ int _main(int argc, char* argv[], char** envp) {
if (const auto authMechanisms = parsedURI.getOption("authMechanism")) {
std::stringstream ss;
- ss << "DB.prototype._defaultAuthenticationMechanism = \"" << escape(authMechanisms.get())
- << "\";" << std::endl;
+ ss << "DB.prototype._defaultAuthenticationMechanism = \""
+ << str::escape(authMechanisms.get()) << "\";" << std::endl;
mongo::shell_utils::dbConnect += ss.str();
}
if (const auto gssapiServiveName = parsedURI.getOption("gssapiServiceName")) {
std::stringstream ss;
- ss << "DB.prototype._defaultGssapiServiceName = \"" << escape(gssapiServiveName.get())
+ ss << "DB.prototype._defaultGssapiServiceName = \"" << str::escape(gssapiServiveName.get())
<< "\";" << std::endl;
mongo::shell_utils::dbConnect += ss.str();
}
diff --git a/src/mongo/shell/shell_utils_launcher.cpp b/src/mongo/shell/shell_utils_launcher.cpp
index 3b3d128335e..34aa7c61d7e 100644
--- a/src/mongo/shell/shell_utils_launcher.cpp
+++ b/src/mongo/shell/shell_utils_launcher.cpp
@@ -71,7 +71,7 @@
#include "mongo/util/quick_exit.h"
#include "mongo/util/scopeguard.h"
#include "mongo/util/signal_win32.h"
-#include "mongo/util/stringutils.h"
+#include "mongo/util/str.h"
#include "mongo/util/text.h"
#ifndef _WIN32
@@ -525,7 +525,7 @@ boost::filesystem::path ProgramRunner::findProgram(const string& prog) {
// PATH entries are separated by colons. Per POSIX 2013, there is no way to escape a colon in
// an entry.
- splitStringDelim(path, &pathEntries, ':');
+ str::splitStringDelim(path, &pathEntries, ':');
for (const std::string& pathEntry : pathEntries) {
boost::filesystem::path potentialBinary = boost::filesystem::path(pathEntry) / p;
diff --git a/src/mongo/transport/service_executor_adaptive.cpp b/src/mongo/transport/service_executor_adaptive.cpp
index edc0cdb0c75..9b9d3e9c734 100644
--- a/src/mongo/transport/service_executor_adaptive.cpp
+++ b/src/mongo/transport/service_executor_adaptive.cpp
@@ -44,7 +44,7 @@
#include "mongo/util/log.h"
#include "mongo/util/processinfo.h"
#include "mongo/util/scopeguard.h"
-#include "mongo/util/stringutils.h"
+#include "mongo/util/str.h"
#include <asio.hpp>
diff --git a/src/mongo/util/SConscript b/src/mongo/util/SConscript
index 626a6116c32..18f096b148b 100644
--- a/src/mongo/util/SConscript
+++ b/src/mongo/util/SConscript
@@ -263,9 +263,9 @@ env.CppUnitTest(
)
env.CppUnitTest(
- target="stringutils_test",
+ target="str_test",
source=[
- "stringutils_test.cpp",
+ "str_test.cpp",
],
LIBDEPS=[
"$BUILD_DIR/mongo/base",
diff --git a/src/mongo/util/net/hostandport.cpp b/src/mongo/util/net/hostandport.cpp
index 19786d0f375..5c30ef22aa8 100644
--- a/src/mongo/util/net/hostandport.cpp
+++ b/src/mongo/util/net/hostandport.cpp
@@ -40,7 +40,6 @@
#include "mongo/db/server_options.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/str.h"
-#include "mongo/util/stringutils.h"
namespace mongo {
@@ -175,7 +174,7 @@ Status HostAndPort::initialize(StringData s) {
if (hostPart.empty()) {
return Status(ErrorCodes::FailedToParse,
str::stream() << "Empty host component parsing HostAndPort from \""
- << escape(s.toString())
+ << str::escape(s.toString())
<< "\"");
}
@@ -190,7 +189,7 @@ Status HostAndPort::initialize(StringData s) {
return Status(ErrorCodes::FailedToParse,
str::stream() << "Port number " << port
<< " out of range parsing HostAndPort from \""
- << escape(s.toString())
+ << str::escape(s.toString())
<< "\"");
}
} else {
diff --git a/src/mongo/util/processinfo_solaris.cpp b/src/mongo/util/processinfo_solaris.cpp
index e65357b9ae4..91f73e41dd9 100644
--- a/src/mongo/util/processinfo_solaris.cpp
+++ b/src/mongo/util/processinfo_solaris.cpp
@@ -50,7 +50,6 @@
#include "mongo/util/processinfo.h"
#include "mongo/util/scopeguard.h"
#include "mongo/util/str.h"
-#include "mongo/util/stringutils.h"
namespace mongo {
@@ -169,7 +168,7 @@ void ProcessInfo::SystemInfo::collectSystemInfo() {
if (str::startsWith(osName, "Oracle Solaris")) {
std::vector<std::string> versionComponents;
- splitStringDelim(osVersion, &versionComponents, '.');
+ str::splitStringDelim(osVersion, &versionComponents, '.');
if (versionComponents.size() > 1) {
unsigned majorInt, minorInt;
diff --git a/src/mongo/util/stacktrace_posix.cpp b/src/mongo/util/stacktrace_posix.cpp
index ac3fadeb549..9eaed27e06c 100644
--- a/src/mongo/util/stacktrace_posix.cpp
+++ b/src/mongo/util/stacktrace_posix.cpp
@@ -44,7 +44,7 @@
#include "mongo/db/jsobj.h"
#include "mongo/util/hex.h"
#include "mongo/util/log.h"
-#include "mongo/util/stringutils.h"
+#include "mongo/util/str.h"
#include "mongo/util/version.h"
#if defined(MONGO_CONFIG_HAVE_EXECINFO_BACKTRACE)
@@ -353,7 +353,7 @@ void processLoadSegment(const dl_phdr_info& info, const ElfW(Phdr) & phdr, BSONO
ElfW(Ehdr) eHeader;
memcpy(&eHeader, reinterpret_cast<const char*>(info.dlpi_addr) + phdr.p_vaddr, sizeof(eHeader));
- std::string quotedFileName = "\"" + escape(info.dlpi_name) + "\"";
+ std::string quotedFileName = "\"" + str::escape(info.dlpi_name) + "\"";
if (memcmp(&eHeader.e_ident[0], ELFMAG, SELFMAG)) {
warning() << "Bad ELF magic number in image of " << quotedFileName;
diff --git a/src/mongo/util/stringutils.cpp b/src/mongo/util/str.cpp
index 8cffc75d0e0..7209fd90e2e 100644
--- a/src/mongo/util/stringutils.cpp
+++ b/src/mongo/util/str.cpp
@@ -31,23 +31,19 @@
#include <cctype>
-#include "mongo/util/stringutils.h"
-
#include "mongo/base/parse_number.h"
#include "mongo/util/hex.h"
+#include "mongo/util/str.h"
-namespace mongo {
-
-using std::string;
-using std::vector;
+namespace mongo::str {
-void splitStringDelim(const string& str, vector<string>* res, char delim) {
+void splitStringDelim(const std::string& str, std::vector<std::string>* res, char delim) {
if (str.empty())
return;
size_t beg = 0;
size_t pos = str.find(delim);
- while (pos != string::npos) {
+ while (pos != str.npos) {
res->push_back(str.substr(beg, pos - beg));
beg = ++pos;
pos = str.find(delim, beg);
@@ -55,8 +51,8 @@ void splitStringDelim(const string& str, vector<string>* res, char delim) {
res->push_back(str.substr(beg));
}
-void joinStringDelim(const vector<string>& strs, string* res, char delim) {
- for (vector<string>::const_iterator it = strs.begin(); it != strs.end(); ++it) {
+void joinStringDelim(const std::vector<std::string>& strs, std::string* res, char delim) {
+ for (auto it = strs.begin(); it != strs.end(); ++it) {
if (it != strs.begin())
res->push_back(delim);
res->append(*it);
@@ -240,4 +236,4 @@ boost::optional<size_t> parseUnsignedBase10Integer(StringData fieldName) {
return boost::none;
}
-} // namespace mongo
+} // namespace mongo::str
diff --git a/src/mongo/util/str.h b/src/mongo/util/str.h
index f3950adc244..bddfff282b2 100644
--- a/src/mongo/util/str.h
+++ b/src/mongo/util/str.h
@@ -35,8 +35,12 @@
* TODO: De-inline.
*/
+#include <boost/optional.hpp>
+#include <ctype.h>
+#include <memory>
#include <sstream>
#include <string>
+#include <vector>
#include "mongo/base/string_data.h"
#include "mongo/bson/util/builder.h"
@@ -286,4 +290,58 @@ inline int caseInsensitiveCompare(const char* s1, const char* s2) {
#endif
}
+void splitStringDelim(const std::string& str, std::vector<std::string>* res, char delim);
+
+void joinStringDelim(const std::vector<std::string>& strs, std::string* res, char delim);
+
+inline std::string toLower(StringData input) {
+ std::string::size_type sz = input.size();
+
+ std::unique_ptr<char[]> line(new char[sz + 1]);
+ char* copy = line.get();
+
+ for (std::string::size_type i = 0; i < sz; i++) {
+ char c = input[i];
+ copy[i] = (char)tolower((int)c);
+ }
+ copy[sz] = 0;
+ return copy;
+}
+
+/** Functor for combining lexical and numeric comparisons. */
+class LexNumCmp {
+public:
+ /** @param lexOnly - compare all characters lexically, including digits. */
+ LexNumCmp(bool lexOnly);
+ /**
+ * Non numeric characters are compared lexicographically; numeric substrings
+ * are compared numerically; dots separate ordered comparable subunits.
+ * For convenience, character 255 is greater than anything else.
+ * @param lexOnly - compare all characters lexically, including digits.
+ */
+ static int cmp(StringData s1, StringData s2, bool lexOnly);
+ int cmp(StringData s1, StringData s2) const;
+ bool operator()(StringData s1, StringData s2) const;
+
+private:
+ bool _lexOnly;
+};
+
+// TODO: Sane-ify core std::string functionality
+// For now, this needs to be near the LexNumCmp or else
+int versionCmp(StringData rhs, StringData lhs);
+
+/**
+ * A method to escape whitespace and control characters in strings. For example, the string "\t"
+ * goes to "\\t". If `escape_slash` is true, then "/" goes to "\\/".
+ */
+std::string escape(StringData s, bool escape_slash = false);
+
+/**
+ * Converts 'integer' from a base-10 string to a size_t value or returns boost::none if 'integer'
+ * is not a valid base-10 string. A valid string is not allowed to have anything but decimal
+ * numerals, not even a +/- prefix or leading/trailing whitespace.
+ */
+boost::optional<size_t> parseUnsignedBase10Integer(StringData integer);
+
} // namespace mongo::str
diff --git a/src/mongo/util/stringutils_test.cpp b/src/mongo/util/str_test.cpp
index 675e7cb78f1..68d06b7535c 100644
--- a/src/mongo/util/stringutils_test.cpp
+++ b/src/mongo/util/str_test.cpp
@@ -30,9 +30,9 @@
#include "mongo/unittest/unittest.h"
#include "mongo/util/hex.h"
-#include "mongo/util/stringutils.h"
+#include "mongo/util/str.h"
-namespace mongo {
+namespace mongo::str {
using std::string;
@@ -63,7 +63,7 @@ TEST(StringUtilsTest, Simple1) {
}
void assertCmp(int expected, StringData s1, StringData s2, bool lexOnly = false) {
- mongo::LexNumCmp cmp(lexOnly);
+ LexNumCmp cmp(lexOnly);
ASSERT_EQUALS(expected, cmp.cmp(s1, s2, lexOnly));
ASSERT_EQUALS(expected, cmp.cmp(s1, s2));
ASSERT_EQUALS(expected < 0, cmp(s1, s2));
@@ -270,4 +270,4 @@ TEST(StringUtilsTest, WhitespaceWithinNumberFailsToParse) {
boost::optional<size_t> result = parseUnsignedBase10Integer(" 10");
ASSERT(!result);
}
-} // namespace mongo
+} // namespace mongo::str
diff --git a/src/mongo/util/stringutils.h b/src/mongo/util/stringutils.h
deleted file mode 100644
index dc9110fc112..00000000000
--- a/src/mongo/util/stringutils.h
+++ /dev/null
@@ -1,116 +0,0 @@
-/**
- * Copyright (C) 2018-present MongoDB, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the Server Side Public License, version 1,
- * as published by MongoDB, Inc.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * Server Side Public License for more details.
- *
- * You should have received a copy of the Server Side Public License
- * along with this program. If not, see
- * <http://www.mongodb.com/licensing/server-side-public-license>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the Server Side Public License in all respects for
- * all of the code used other than as permitted herein. If you modify file(s)
- * with this exception, you may extend this exception to your version of the
- * file(s), but you are not obligated to do so. If you do not wish to do so,
- * delete this exception statement from your version. If you delete this
- * exception statement from all source files in the program, then also delete
- * it in the license file.
- */
-
-#pragma once
-
-#include <ctype.h>
-
-#include <boost/optional.hpp>
-#include <memory>
-#include <string>
-#include <vector>
-
-#include "mongo/base/string_data.h"
-
-namespace mongo {
-
-// see also mongo/util/str.h - perhaps move these there?
-// see also text.h
-
-void splitStringDelim(const std::string& str, std::vector<std::string>* res, char delim);
-
-void joinStringDelim(const std::vector<std::string>& strs, std::string* res, char delim);
-
-inline std::string tolowerString(StringData input) {
- std::string::size_type sz = input.size();
-
- std::unique_ptr<char[]> line(new char[sz + 1]);
- char* copy = line.get();
-
- for (std::string::size_type i = 0; i < sz; i++) {
- char c = input[i];
- copy[i] = (char)tolower((int)c);
- }
- copy[sz] = 0;
- return copy;
-}
-
-inline std::string toAsciiLowerCase(StringData input) {
- size_t sz = input.size();
- std::unique_ptr<char[]> line(new char[sz + 1]);
- char* res = line.get();
- for (size_t i = 0; i < sz; i++) {
- char c = input[i];
- if (c >= 'A' && c <= 'Z') {
- res[i] = c + 32;
- } else {
- res[i] = c;
- }
- }
- res[sz] = 0;
- return res;
-}
-
-/** Functor for combining lexical and numeric comparisons. */
-class LexNumCmp {
-public:
- /** @param lexOnly - compare all characters lexically, including digits. */
- LexNumCmp(bool lexOnly);
- /**
- * Non numeric characters are compared lexicographically; numeric substrings
- * are compared numerically; dots separate ordered comparable subunits.
- * For convenience, character 255 is greater than anything else.
- * @param lexOnly - compare all characters lexically, including digits.
- */
- static int cmp(StringData s1, StringData s2, bool lexOnly);
- int cmp(StringData s1, StringData s2) const;
- bool operator()(StringData s1, StringData s2) const;
-
-private:
- bool _lexOnly;
-};
-
-// TODO: Sane-ify core std::string functionality
-// For now, this needs to be near the LexNumCmp or else
-int versionCmp(const StringData rhs, const StringData lhs);
-
-/**
- * A method to escape whitespace and control characters in strings. For example, the string "\t"
- * goes to "\\t". If `escape_slash` is true, then "/" goes to "\\/".
- */
-std::string escape(StringData s, bool escape_slash = false);
-
-/**
- * Converts 'integer' from a base-10 string to a size_t value or returns boost::none if 'integer'
- * is not a valid base-10 string. A valid string is not allowed to have anything but decimal
- * numerals, not even a +/- prefix or leading/trailing whitespace.
- */
-boost::optional<size_t> parseUnsignedBase10Integer(StringData integer);
-
-} // namespace mongo