diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2012-10-02 21:36:39 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2012-10-07 14:38:37 +0200 |
commit | 6032e4f4e7c1892a4e3f0a1a2007e4cd0fe99937 (patch) | |
tree | 45117631344c248ef87b7c92b2a832c2810729a5 /src/util.cpp | |
parent | ee0b64853699c08602fed81cdefc62d7e8dcdce2 (diff) |
get rid of strlcpy.h
Don't use hand-rolled string manipulation routine with a fixed
buffer in the bitcoin core, instead make use of c++ strings and boost.
Diffstat (limited to 'src/util.cpp')
-rw-r--r-- | src/util.cpp | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/src/util.cpp b/src/util.cpp index 296842acc3..ad2b8c6601 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -5,10 +5,11 @@ #include "util.h" #include "sync.h" -#include "strlcpy.h" #include "version.h" #include "ui_interface.h" #include <boost/algorithm/string/join.hpp> +#include <boost/algorithm/string/case_conv.hpp> // for to_lower() +#include <boost/algorithm/string/predicate.hpp> // for startswith() and endswith() // Work around clang compilation problem in Boost 1.46: // /usr/include/boost/program_options/detail/config_file.hpp:163:17: error: call to function 'to_internal' that is neither visible in the template definition nor found by argument-dependent lookup @@ -499,24 +500,24 @@ void ParseParameters(int argc, const char* const argv[]) mapMultiArgs.clear(); for (int i = 1; i < argc; i++) { - char psz[10000]; - strlcpy(psz, argv[i], sizeof(psz)); - char* pszValue = (char*)""; - if (strchr(psz, '=')) + std::string str(argv[i]); + std::string strValue; + size_t is_index = str.find('='); + if (is_index != std::string::npos) { - pszValue = strchr(psz, '='); - *pszValue++ = '\0'; + strValue = str.substr(is_index+1); + str = str.substr(0, is_index); } - #ifdef WIN32 - _strlwr(psz); - if (psz[0] == '/') - psz[0] = '-'; - #endif - if (psz[0] != '-') +#ifdef WIN32 + boost::to_lower(str); + if (boost::algorithm::starts_with(str, "/")) + str = "-" + str.substr(1); +#endif + if (str[0] != '-') break; - mapArgs[psz] = pszValue; - mapMultiArgs[psz].push_back(pszValue); + mapArgs[str] = strValue; + mapMultiArgs[str].push_back(strValue); } // New 0.6 features: |