Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F13115087
D1489.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Subscribers
None
D1489.diff
View Options
diff --git a/src/utilmoneystr.h b/src/utilmoneystr.h
--- a/src/utilmoneystr.h
+++ b/src/utilmoneystr.h
@@ -14,7 +14,7 @@
#include "amount.h"
-std::string FormatMoney(const Amount &n);
+std::string FormatMoney(const Amount n);
bool ParseMoney(const std::string &str, Amount &nRet);
bool ParseMoney(const char *pszIn, Amount &nRet);
diff --git a/src/utilmoneystr.cpp b/src/utilmoneystr.cpp
--- a/src/utilmoneystr.cpp
+++ b/src/utilmoneystr.cpp
@@ -9,7 +9,7 @@
#include "tinyformat.h"
#include "utilstrencodings.h"
-std::string FormatMoney(const Amount &amt) {
+std::string FormatMoney(const Amount amt) {
// Note: not using straight sprintf here because we do NOT want localized
// number formatting.
int64_t n = amt.GetSatoshis();
@@ -20,11 +20,16 @@
// Right-trim excess zeros before the decimal point:
int nTrim = 0;
- for (int i = str.size() - 1; (str[i] == '0' && isdigit(str[i - 2])); --i)
+ for (int i = str.size() - 1; (str[i] == '0' && isdigit(str[i - 2])); --i) {
++nTrim;
- if (nTrim) str.erase(str.size() - nTrim, nTrim);
+ }
+ if (nTrim) {
+ str.erase(str.size() - nTrim, nTrim);
+ }
- if (n < 0) str.insert((unsigned int)0, 1, '-');
+ if (n < 0) {
+ str.insert((unsigned int)0, 1, '-');
+ }
return str;
}
@@ -36,8 +41,9 @@
std::string strWhole;
int64_t nUnits = 0;
const char *p = pszIn;
- while (isspace(*p))
+ while (isspace(*p)) {
p++;
+ }
for (; *p; p++) {
if (*p == '.') {
p++;
@@ -48,15 +54,26 @@
}
break;
}
- if (isspace(*p)) break;
- if (!isdigit(*p)) return false;
+ if (isspace(*p)) {
+ break;
+ }
+ if (!isdigit(*p)) {
+ return false;
+ }
strWhole.insert(strWhole.end(), *p);
}
- for (; *p; p++)
- if (!isspace(*p)) return false;
+ for (; *p; p++) {
+ if (!isspace(*p)) {
+ return false;
+ }
+ }
// guard against 63 bit overflow
- if (strWhole.size() > 10) return false;
- if (nUnits < 0 || nUnits > COIN.GetSatoshis()) return false;
+ if (strWhole.size() > 10) {
+ return false;
+ }
+ if (nUnits < 0 || nUnits > COIN.GetSatoshis()) {
+ return false;
+ }
int64_t nWhole = atoi64(strWhole);
Amount nValue = nWhole * COIN + Amount(nUnits);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Mar 1, 09:41 (4 h, 35 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5187231
Default Alt Text
D1489.diff (2 KB)
Attached To
D1489: Various nits in utilmoneystr.{h/cpp}
Event Timeline
Log In to Comment