diff options
Diffstat (limited to 'src/util/moneystr.cpp')
-rw-r--r-- | src/util/moneystr.cpp | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/src/util/moneystr.cpp b/src/util/moneystr.cpp index 2797f450ca..544cfb58f9 100644 --- a/src/util/moneystr.cpp +++ b/src/util/moneystr.cpp @@ -31,21 +31,19 @@ std::string FormatMoney(const CAmount& n) } -bool ParseMoney(const std::string& str, CAmount& nRet) +bool ParseMoney(const std::string& money_string, CAmount& nRet) { - if (!ValidAsCString(str)) { + if (!ValidAsCString(money_string)) { + return false; + } + const std::string str = TrimString(money_string); + if (str.empty()) { return false; } - return ParseMoney(str.c_str(), nRet); -} -bool ParseMoney(const char* pszIn, CAmount& nRet) -{ std::string strWhole; int64_t nUnits = 0; - const char* p = pszIn; - while (IsSpace(*p)) - p++; + const char* p = str.c_str(); for (; *p; p++) { if (*p == '.') @@ -60,14 +58,14 @@ bool ParseMoney(const char* pszIn, CAmount& nRet) break; } if (IsSpace(*p)) - break; + return false; if (!IsDigit(*p)) return false; strWhole.insert(strWhole.end(), *p); } - for (; *p; p++) - if (!IsSpace(*p)) - return false; + if (*p) { + return false; + } if (strWhole.size() > 10) // guard against 63 bit overflow return false; if (nUnits < 0 || nUnits > COIN) |