diff options
author | Andrew Morrow <acm@mongodb.com> | 2015-01-03 16:21:43 -0500 |
---|---|---|
committer | Andrew Morrow <acm@mongodb.com> | 2015-01-05 18:27:00 -0500 |
commit | 8bff2b205a54d0616e4b3ec04e3c1c3435ff9d11 (patch) | |
tree | a2db00c0ff606eabd0ca0e5419044d8952b627e6 | |
parent | 7c134b66ea15ad39985800a43874413423653809 (diff) | |
download | mongo-8bff2b205a54d0616e4b3ec04e3c1c3435ff9d11.tar.gz |
SERVER-13256 Move string utils from goodies.h to str.h
-rw-r--r-- | src/mongo/db/commands.cpp | 2 | ||||
-rw-r--r-- | src/mongo/scripting/engine.cpp | 2 | ||||
-rw-r--r-- | src/mongo/shell/dbshell.cpp | 4 | ||||
-rw-r--r-- | src/mongo/util/goodies.h | 16 | ||||
-rw-r--r-- | src/mongo/util/mongoutils/str.h | 6 | ||||
-rw-r--r-- | src/mongo/util/version.cpp | 3 |
6 files changed, 12 insertions, 21 deletions
diff --git a/src/mongo/db/commands.cpp b/src/mongo/db/commands.cpp index 57892c764fa..290075e7219 100644 --- a/src/mongo/db/commands.cpp +++ b/src/mongo/db/commands.cpp @@ -160,7 +160,7 @@ namespace mongo { ss << *q++; ss << "\">"; q = p; - if( startsWith(q, "http://www.mongodb.org/display/") ) + if( str::startsWith(q, "http://www.mongodb.org/display/") ) q += 31; while( *q && *q != ' ' && *q != '\n' ) { ss << (*q == '+' ? ' ' : *q); diff --git a/src/mongo/scripting/engine.cpp b/src/mongo/scripting/engine.cpp index a7dffa26e05..b4f432034e8 100644 --- a/src/mongo/scripting/engine.cpp +++ b/src/mongo/scripting/engine.cpp @@ -134,7 +134,7 @@ namespace { for (boost::filesystem::directory_iterator it (p); it != end; it++) { empty = false; boost::filesystem::path sub(*it); - if (!endsWith(sub.string().c_str(), ".js")) + if (!str::endsWith(sub.string().c_str(), ".js")) continue; if (!execFile(sub.string(), printResult, reportError, timeoutMs)) return false; diff --git a/src/mongo/shell/dbshell.cpp b/src/mongo/shell/dbshell.cpp index 3611f83ec43..a1b89e5dfe7 100644 --- a/src/mongo/shell/dbshell.cpp +++ b/src/mongo/shell/dbshell.cpp @@ -416,7 +416,7 @@ string finishCode( string code ) { return ""; char * linePtr = line; - while ( startsWith( linePtr, "... " ) ) + while ( str::startsWith( linePtr, "... " ) ) linePtr += 4; code += linePtr; @@ -831,7 +831,7 @@ int _main( int argc, char* argv[], char **envp ) { continue; } - if ( startsWith( linePtr, "edit " ) ) { + if ( str::startsWith( linePtr, "edit " ) ) { shellHistoryAdd( linePtr ); const char* s = linePtr + 5; // skip "edit " diff --git a/src/mongo/util/goodies.h b/src/mongo/util/goodies.h index 4ad464405fa..f7e0147c256 100644 --- a/src/mongo/util/goodies.h +++ b/src/mongo/util/goodies.h @@ -42,22 +42,6 @@ namespace mongo { - inline bool startsWith(const char *str, const char *prefix) { - size_t l = strlen(prefix); - if ( strlen(str) < l ) return false; - return strncmp(str, prefix, l) == 0; - } - inline bool startsWith(const std::string& s, const std::string& p) { - return startsWith(s.c_str(), p.c_str()); - } - - inline bool endsWith(const char *p, const char *suffix) { - size_t a = strlen(p); - size_t b = strlen(suffix); - if ( b > a ) return false; - return strcmp(p + a - b, suffix) == 0; - } - #if !defined(_WIN32) typedef int HANDLE; #else diff --git a/src/mongo/util/mongoutils/str.h b/src/mongo/util/mongoutils/str.h index 81b58204881..58629249b04 100644 --- a/src/mongo/util/mongoutils/str.h +++ b/src/mongo/util/mongoutils/str.h @@ -91,6 +91,12 @@ namespace mongoutils { size_t len = strlen(s); return len && s[len-1] == p; } + inline bool endsWith(const char *p, const char *suffix) { + size_t a = strlen(p); + size_t b = strlen(suffix); + if ( b > a ) return false; + return strcmp(p + a - b, suffix) == 0; + } inline bool equals( const char * a , const char * b ) { return strcmp( a , b ) == 0; } diff --git a/src/mongo/util/version.cpp b/src/mongo/util/version.cpp index 6b26e05aaea..4fbb230f808 100644 --- a/src/mongo/util/version.cpp +++ b/src/mongo/util/version.cpp @@ -33,6 +33,7 @@ #include "mongo/base/parse_number.h" #include "mongo/db/jsobj.h" +#include "mongo/util/mongoutils/str.h" namespace mongo { @@ -66,7 +67,7 @@ namespace mongo { verify(*c == '\0'); break; } - else if (startsWith(curPart, "rc")){ + else if (str::startsWith(curPart, "rc")){ num = 0; verify( parseNumberFromString( curPart.substr(2), &num ).isOK() ); finalPart = -10 + num; |