Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Replace std::to_string with locale-independent alternative #2266

Merged
merged 1 commit into from
Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/gridcoin/quorum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "gridcoin/scraper/scraper_net.h"
#include "gridcoin/superblock.h"
#include "util/reverse_iterator.h"
#include <util/string.h>

#include <openssl/md5.h>
#include <unordered_map>
Expand Down Expand Up @@ -306,7 +307,7 @@ class LegacyConsensus
? arith_uint256("0x00000000000000000000000000000000ed182f81388f317df738fd9994e7020b")
: arith_uint256("0x000000000000000000000000000000004d182f81388f317df738fd9994e7020b");

std::string input = grc_address + "_" + std::to_string(GetDayOfYear(time));
std::string input = grc_address + "_" + ToString(GetDayOfYear(time));
std::vector<unsigned char> address_day_hash(16);

MD5(reinterpret_cast<const unsigned char*>(input.data()),
Expand Down
171 changes: 86 additions & 85 deletions src/gridcoin/scraper/scraper.cpp

Large diffs are not rendered by default.

23 changes: 12 additions & 11 deletions src/gridcoin/voting/builders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "gridcoin/voting/registry.h"
#include "ui_interface.h"
#include "wallet/wallet.h"
#include <util/string.h>

#include <boost/algorithm/string/trim.hpp>

Expand Down Expand Up @@ -661,7 +662,7 @@ class PollClaimBuilder
throw VotingError(strprintf(
_("No address contains %s GRC in %s UTXOs or fewer."),
FormatMoney(POLL_REQUIRED_BALANCE),
std::to_string(PollEligibilityClaim::MAX_OUTPOINTS)));
ToString(PollEligibilityClaim::MAX_OUTPOINTS)));
}

//!
Expand Down Expand Up @@ -951,7 +952,7 @@ PollBuilder PollBuilder::SetDuration(const uint32_t days)
if (days < Poll::MIN_DURATION_DAYS) {
throw VotingError(strprintf(
_("Poll duration must be at least %s days."),
std::to_string(Poll::MIN_DURATION_DAYS)));
ToString(Poll::MIN_DURATION_DAYS)));
}

// The protocol allows poll durations up to 180 days. To limit unhelpful
Expand All @@ -963,7 +964,7 @@ PollBuilder PollBuilder::SetDuration(const uint32_t days)
if (days > max_duration_days) {
throw VotingError(strprintf(
_("Poll duration cannot exceed %s days."),
std::to_string(max_duration_days)));
ToString(max_duration_days)));
}

m_poll->m_duration_days = days;
Expand All @@ -982,7 +983,7 @@ PollBuilder PollBuilder::SetTitle(std::string title)
if (title.size() > Poll::MAX_TITLE_SIZE) {
throw VotingError(strprintf(
_("Poll title cannot exceed %s characters."),
std::to_string(Poll::MAX_TITLE_SIZE)));
ToString(Poll::MAX_TITLE_SIZE)));
}

m_poll->m_title = std::move(title);
Expand All @@ -999,7 +1000,7 @@ PollBuilder PollBuilder::SetUrl(std::string url)
if (url.size() > Poll::MAX_URL_SIZE) {
throw VotingError(strprintf(
_("Poll discussion URL cannot exceed %s characters."),
std::to_string(Poll::MAX_URL_SIZE)));
ToString(Poll::MAX_URL_SIZE)));
}

m_poll->m_url = std::move(url);
Expand All @@ -1012,7 +1013,7 @@ PollBuilder PollBuilder::SetQuestion(std::string question)
if (question.size() > Poll::MAX_QUESTION_SIZE) {
throw VotingError(strprintf(
_("Poll question cannot exceed %s characters."),
std::to_string(Poll::MAX_QUESTION_SIZE)));
ToString(Poll::MAX_QUESTION_SIZE)));
}

m_poll->m_question = std::move(question);
Expand Down Expand Up @@ -1047,14 +1048,14 @@ PollBuilder PollBuilder::AddChoice(std::string label)
if (m_poll->m_choices.size() + 1 > POLL_MAX_CHOICES_SIZE) {
throw VotingError(strprintf(
_("Poll cannot contain more than %s choices."),
std::to_string(POLL_MAX_CHOICES_SIZE)));
ToString(POLL_MAX_CHOICES_SIZE)));
}

if (label.size() > Poll::Choice::MAX_LABEL_SIZE) {
throw VotingError(strprintf(
_("Poll choice \"%s\" exceeds %s characters."),
label,
std::to_string(Poll::Choice::MAX_LABEL_SIZE)));
ToString(Poll::Choice::MAX_LABEL_SIZE)));
}

if (m_poll->m_choices.LabelExists(label)) {
Expand Down Expand Up @@ -1191,13 +1192,13 @@ VoteBuilder VoteBuilder::AddResponse(const uint8_t offset)
if (!m_poll->Choices().OffsetInRange(offset)) {
throw VotingError(strprintf(
_("\"%s\" is not a valid poll choice."),
std::to_string(offset)));
ToString(offset)));
}

if (m_vote->ResponseExists(offset)) {
throw VotingError(strprintf(
_("Duplicate response for poll choice: %s"),
std::to_string(offset)));
ToString(offset)));
}

// This is effectively handled by the previous conditions. We'll leave
Expand All @@ -1206,7 +1207,7 @@ VoteBuilder VoteBuilder::AddResponse(const uint8_t offset)
if (m_vote->m_responses.size() + 1 > m_poll->Choices().size()) {
throw VotingError(strprintf(
_("Exceeded the number of choices in the poll: %s"),
std::to_string(m_poll->Choices().size())));
ToString(m_poll->Choices().size())));
}

m_vote->m_responses.emplace_back(offset);
Expand Down
5 changes: 3 additions & 2 deletions src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// file COPYING or https://opensource.org/licenses/mit-license.php.

#include "blockchain.h"
#include <util/string.h>

#include <univalue.h>

Expand Down Expand Up @@ -1478,7 +1479,7 @@ UniValue lifetime(const UniValue& params, bool fHelp)
{
if (pindex->ResearchSubsidy() > 0 && pindex->GetMiningId() == *cpid) {
results.pushKV(
std::to_string(pindex->nHeight),
ToString(pindex->nHeight),
ValueFromAmount(pindex->ResearchSubsidy()));
}
}
Expand Down Expand Up @@ -2024,7 +2025,7 @@ UniValue versionreport(const UniValue& params, bool fHelp)
"versionreport <lookback:int> <full:bool>\n"
"\n"
"<lookback> --> Number of blocks to tally from the chain head "
"(default: " + std::to_string(BLOCKS_PER_DAY) + ").\n"
"(default: " + ToString(BLOCKS_PER_DAY) + ").\n"
"<full> ------> Classify by commit suffix (default: false).\n"
"\n"
"Display the software versions of nodes that recently staked.\n");
Expand Down
3 changes: 2 additions & 1 deletion src/rpc/dataacq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "gridcoin/superblock.h"
#include "gridcoin/support/block_finder.h"
#include "util.h"
#include <util/string.h>

#include <boost/algorithm/string/case_conv.hpp> // for to_lower()
#include <boost/algorithm/string.hpp>
Expand Down Expand Up @@ -386,7 +387,7 @@ UniValue rpc_exportstats(const UniValue& params, bool fHelp)
unsigned long points = 0;
double samples = 0; /* this is double for easy division */
fsbridge::ofstream Output;
fs::path o_path = GetDataDir() / "reports" / ( "export_" + std::to_string(GetTime()) + ".txt" );
fs::path o_path = GetDataDir() / "reports" / ( "export_" + ToString(GetTime()) + ".txt" );
fs::create_directories(o_path.parent_path());
Output.open (o_path);
Output.imbue(std::locale::classic());
Expand Down
3 changes: 2 additions & 1 deletion src/rpc/rawtransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "server.h"
#include "streams.h"
#include "txdb.h"
#include <util/string.h>
#include "validation.h"
#include "wallet/coincontrol.h"
#include "wallet/wallet.h"
Expand Down Expand Up @@ -503,7 +504,7 @@ UniValue consolidateunspent(const UniValue& params, bool fHelp)
"[UTXO size]: Optional parameter for target consolidation output size.\n"
"\n"
"[maximum number of inputs]: Defaults and clamped to "
<< std::to_string(GetMaxInputsForConsolidationTxn())
<< ToString(GetMaxInputsForConsolidationTxn())
<< " maximum to prevent transaction failures.\n"
"\n"
"[sweep all addresses]: Boolean to indicate whether all addresses should be used for inputs to the\n"
Expand Down
41 changes: 21 additions & 20 deletions src/test/gridcoin/beacon_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "test/data/testnet_beacon.bin.h"
#include "test/data/mainnet_beacon.bin.h"
#include "txdb-leveldb.h"
#include <util/string.h>

#include <boost/test/unit_test.hpp>
#include <vector>
Expand Down Expand Up @@ -313,7 +314,7 @@ class BeaconRegistryTest
<< ", timestamp = " << left.second->m_timestamp
<< ", hash = " << left.second->m_hash.GetHex()
<< ", prev beacon hash = " << left.second->m_prev_beacon_hash.GetHex()
<< ", status = " << std::to_string(left.second->m_status.Raw())
<< ", status = " << ToString(left.second->m_status.Raw())
<< std::endl;

}
Expand Down Expand Up @@ -347,8 +348,8 @@ class BeaconRegistryTest
std::cout << "init_beacon prev beacon hash = " << left_beacon_ptr->m_prev_beacon_hash.GetHex()
<< ", reinit_beacon prev beacon hash = " << right_beacon_iter->second->m_prev_beacon_hash.GetHex() << std::endl;

std::cout << "init_beacon status = " << std::to_string(left_beacon_ptr->m_status.Raw())
<< ", reinit_beacon status = " << std::to_string(right_beacon_iter->second->m_status.Raw()) << std::endl;
std::cout << "init_beacon status = " << ToString(left_beacon_ptr->m_status.Raw())
<< ", reinit_beacon status = " << ToString(right_beacon_iter->second->m_status.Raw()) << std::endl;
}
}

Expand All @@ -375,7 +376,7 @@ class BeaconRegistryTest
<< ", timestamp = " << left.second->m_timestamp
<< ", hash = " << left.second->m_hash.GetHex()
<< ", prev beacon hash = " << left.second->m_prev_beacon_hash.GetHex()
<< ", status = " << std::to_string(left.second->m_status.Raw())
<< ", status = " << ToString(left.second->m_status.Raw())
<< std::endl;

}
Expand Down Expand Up @@ -409,8 +410,8 @@ class BeaconRegistryTest
std::cout << "reinit_beacon prev beacon hash = " << left_beacon_ptr->m_prev_beacon_hash.GetHex()
<< ", init_beacon prev beacon hash = " << right_beacon_iter->second->m_prev_beacon_hash.GetHex() << std::endl;

std::cout << "reinit_beacon status = " << std::to_string(left_beacon_ptr->m_status.Raw())
<< ", init_beacon status = " << std::to_string(right_beacon_iter->second->m_status.Raw()) << std::endl;
std::cout << "reinit_beacon status = " << ToString(left_beacon_ptr->m_status.Raw())
<< ", init_beacon status = " << ToString(right_beacon_iter->second->m_status.Raw()) << std::endl;
}
}

Expand Down Expand Up @@ -439,7 +440,7 @@ class BeaconRegistryTest
<< ", timestamp = " << beacon.m_timestamp
<< ", hash = " << beacon.m_hash.GetHex()
<< ", prev beacon hash = " << beacon.m_prev_beacon_hash.GetHex()
<< ", status = " << std::to_string(beacon.m_status.Raw())
<< ", status = " << ToString(beacon.m_status.Raw())
<< std::endl;
}

Expand All @@ -456,7 +457,7 @@ class BeaconRegistryTest
<< ", timestamp = " << beacon.m_timestamp
<< ", hash = " << beacon.m_hash.GetHex()
<< ", prev beacon hash = " << beacon.m_prev_beacon_hash.GetHex()
<< ", status = " << std::to_string(beacon.m_status.Raw())
<< ", status = " << ToString(beacon.m_status.Raw())
<< std::endl;
}
}
Expand Down Expand Up @@ -485,7 +486,7 @@ class BeaconRegistryTest
<< ", timestamp = " << left.second.m_timestamp
<< ", hash = " << left.second.m_hash.GetHex()
<< ", prev beacon hash = " << left.second.m_prev_beacon_hash.GetHex()
<< ", status = " << std::to_string(left.second.m_status.Raw())
<< ", status = " << ToString(left.second.m_status.Raw())
<< std::endl;
}
else if (left_beacon != right->second)
Expand All @@ -511,8 +512,8 @@ class BeaconRegistryTest
std::cout << "init_beacon prev beacon hash = " << left_beacon.m_prev_beacon_hash.GetHex()
<< ", reinit_beacon prev beacon hash = " << right->second.m_prev_beacon_hash.GetHex() << std::endl;

std::cout << "init_beacon status = " << std::to_string(left_beacon.m_status.Raw())
<< ", reinit_beacon status = " << std::to_string(right->second.m_status.Raw()) << std::endl;
std::cout << "init_beacon status = " << ToString(left_beacon.m_status.Raw())
<< ", reinit_beacon status = " << ToString(right->second.m_status.Raw()) << std::endl;
}
}

Expand All @@ -538,7 +539,7 @@ class BeaconRegistryTest
<< ", timestamp = " << left.second.m_timestamp
<< ", hash = " << left.second.m_hash.GetHex()
<< ", prev beacon hash = " << left.second.m_prev_beacon_hash.GetHex()
<< ", status = " << std::to_string(left.second.m_status.Raw())
<< ", status = " << ToString(left.second.m_status.Raw())
<< std::endl;

}
Expand All @@ -565,8 +566,8 @@ class BeaconRegistryTest
std::cout << "reinit_beacon prev beacon hash = " << left_beacon.m_prev_beacon_hash.GetHex()
<< ", init_beacon prev beacon hash = " << right->second.m_prev_beacon_hash.GetHex() << std::endl;

std::cout << "reinit_beacon status = " << std::to_string(left_beacon.m_status.Raw())
<< ", init_beacon status = " << std::to_string(right->second.m_status.Raw()) << std::endl;
std::cout << "reinit_beacon status = " << ToString(left_beacon.m_status.Raw())
<< ", init_beacon status = " << ToString(right->second.m_status.Raw()) << std::endl;
}
}

Expand Down Expand Up @@ -602,7 +603,7 @@ class BeaconRegistryTest
<< ", timestamp = " << left_beacon.m_timestamp
<< ", hash = " << left_beacon.m_hash.GetHex()
<< ", prev beacon hash = " << left_beacon.m_prev_beacon_hash.GetHex()
<< ", status = " << std::to_string(left_beacon.m_status.Raw())
<< ", status = " << ToString(left_beacon.m_status.Raw())
<< std::endl;
}
else if (left_beacon != right->second)
Expand Down Expand Up @@ -632,8 +633,8 @@ class BeaconRegistryTest
<< ", reinit_pending_beacon prev beacon hash = " << right->second.m_prev_beacon_hash.GetHex()
<< std::endl;

std::cout << ", init_pending_beacon status = " << std::to_string(left_beacon.m_status.Raw())
<< ", reinit_pending_beacon status = " << std::to_string(right->second.m_status.Raw()) << std::endl;
std::cout << ", init_pending_beacon status = " << ToString(left_beacon.m_status.Raw())
<< ", reinit_pending_beacon status = " << ToString(right->second.m_status.Raw()) << std::endl;
}
}

Expand All @@ -657,7 +658,7 @@ class BeaconRegistryTest
<< ", timestamp = " << left.second.m_timestamp
<< ", hash = " << left.second.m_hash.GetHex()
<< ", prev beacon hash = " << left.second.m_prev_beacon_hash.GetHex()
<< ", status = " << std::to_string(left.second.m_status.Raw())
<< ", status = " << ToString(left.second.m_status.Raw())
<< std::endl;
}
else if (left_beacon != right->second)
Expand Down Expand Up @@ -687,8 +688,8 @@ class BeaconRegistryTest
<< ", reinit_pending_beacon prev beacon hash = " << right->second.m_prev_beacon_hash.GetHex()
<< std::endl;

std::cout << ", init_pending_beacon status = " << std::to_string(left_beacon.m_status.Raw())
<< ", reinit_pending_beacon status = " << std::to_string(right->second.m_status.Raw()) << std::endl;
std::cout << ", init_pending_beacon status = " << ToString(left_beacon.m_status.Raw())
<< ", reinit_pending_beacon status = " << ToString(right->second.m_status.Raw()) << std::endl;
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <script.h>
#include "main.h"
#include "util.h"
#include <util/string.h>
#include <random>
#include "gridcoin/staking/kernel.h"
#include "gridcoin/support/block_finder.h"
Expand Down Expand Up @@ -1396,11 +1397,11 @@ void CWallet::AvailableCoinsForStaking(vector<COutput>& vCoins, unsigned int nSp

g_timer.GetElapsedTime(function
+ "transactions = "
+ std::to_string(transactions)
+ ToString(transactions)
+ ", txns_w_avail_outputs = "
+ std::to_string(txns_w_avail_outputs)
+ ToString(txns_w_avail_outputs)
+ ", balance = "
+ std::to_string(balance_out)
+ ToString(balance_out)
, "miner");
}
}
Expand Down