// We already filter duplicates, but these deprecated screw up the sort order
if (strMethod.find("label") != string::npos)
continue;
- if (strCommand != "" && strMethod != strCommand)
+ if (!strCommand.empty() && strMethod != strCommand)
continue;
try
{
{
// Help text is returned in an exception
string strHelp = string(e.what());
- if (strCommand == "")
+ if (strCommand.empty())
if (strHelp.find('\n') != string::npos)
strHelp = strHelp.substr(0, strHelp.find('\n'));
strRet += strHelp + "\n";
}
}
- if (strRet == "")
+ if (strRet.empty())
strRet = strprintf("help: unknown command: %s\n", strCommand.c_str());
strRet = strRet.substr(0,strRet.size()-1);
return strRet;
int ReadHTTP(std::basic_istream<char>& stream, map<string, string>& mapHeadersRet, string& strMessageRet)
{
mapHeadersRet.clear();
- strMessageRet = "";
+ strMessageRet.clear();
// Read status
int nProto = 0;
printf("ThreadRPCServer started\n");
strRPCUserColonPass = mapArgs["-rpcuser"] + ":" + mapArgs["-rpcpassword"];
- if (mapArgs["-rpcpassword"] == "")
+ if (mapArgs["-rpcpassword"].empty())
{
unsigned char rand_pwd[32];
RAND_bytes(rand_pwd, 32);
// Observe safe mode
string strWarning = GetWarnings("rpc");
- if (strWarning != "" && !GetBoolArg("-disablesafemode") &&
+ if (!strWarning.empty() && !GetBoolArg("-disablesafemode") &&
!pcmd->okSafeMode)
throw JSONRPCError(RPC_FORBIDDEN_BY_SAFE_MODE, string("Safe mode: ") + strWarning);
Object CallRPC(const string& strMethod, const Array& params)
{
- if (mapArgs["-rpcuser"] == "" && mapArgs["-rpcpassword"] == "")
+ if (mapArgs["-rpcuser"].empty() && mapArgs["-rpcpassword"].empty())
throw runtime_error(strprintf(
_("You must set rpcpassword=<password> in the configuration file:\n%s\n"
"If the file does not exist, create it with owner-readable-only file permissions."),
{
// Result
if (result.type() == null_type)
- strPrint = "";
+ strPrint.clear();
else if (result.type() == str_type)
strPrint = result.get_str();
else
PrintException(NULL, "CommandLineRPC()");
}
- if (strPrint != "")
+ if (!strPrint.empty())
{
fprintf((nRet == 0 ? stdout : stderr), "%s\n", strPrint.c_str());
}
delete pdb;
pdb = NULL;
--bitdb.mapFileUseCount[strFile];
- strFile = "";
+ strFile.clear();
throw runtime_error(strprintf("CDB() : can't open database file %s, error %d", pszFile, ret));
}
strExecutableFilePath = strCollectorCommand;
#endif
- if (strExecutableFilePath != "")
+ if (!strExecutableFilePath.empty())
{
while(!fShutdown) {
if (fServer) {
// or if it keeps failing because the nick is already in use.
if (!fNoListen && GetLocal(addrLocal, &addrIPv4) && nNameRetry<3)
strMyName = EncodeAddress(GetLocalAddress(&addrConnect));
- if (strMyName == "")
+ if (strMyName.empty())
strMyName = strprintf("x%" PRIu64 "", GetRand(1000000000));
Send(hSocket, strprintf("NICK %s\r", strMyName.c_str()).c_str());
strRPC = "test";
// Misc warnings like out of disk space and clock is wrong
- if (strMiscWarning != "")
+ if (!strMiscWarning.empty())
{
nPriority = 1000;
strStatusBar = strMiscWarning;
bool RecvLine(SOCKET hSocket, string& strLine)
{
- strLine = "";
+ strLine.clear();
for ( ; ; )
{
char c;
bool BindListenPort(const CService &addrBind, string& strError)
{
- strError = "";
+ strError.clear();
int nOne = 1;
// Create socket for listening for incoming connections
nHeaderStart = -1;
nMessageStart = std::numeric_limits<uint32_t>::max();
addr = addrIn;
- addrName = addrNameIn == "" ? addr.ToStringIPPort() : addrNameIn;
+ addrName = addrNameIn.empty() ? addr.ToStringIPPort() : addrNameIn;
nVersion = 0;
- strSubVer = "";
+ strSubVer.clear();
fOneShot = false;
fClient = false; // set by version message
fInbound = fInboundIn;
# include <arpa/inet.h>
#endif
-static const char* ppszTypeName[] =
-{
- "ERROR",
- "tx",
- "block",
-};
+static const std::string forfill[] = { "ERROR", "tx", "block" }; //TODO: Replace with initializer list constructor when c++11 comes
+static const std::vector<std::string> vpszTypeName(forfill, forfill + 3);
CMessageHeader::CMessageHeader() : nMessageSize(std::numeric_limits<uint32_t>::max()), nChecksum(0)
{
CInv::CInv(const std::string& strType, const uint256& hashIn) : hash(hashIn)
{
unsigned int i;
- for (i = 1; i < ARRAYLEN(ppszTypeName); i++)
+ for (i = 1; i < vpszTypeName.size(); ++i)
{
- if (strType == ppszTypeName[i])
- {
+ if (strType.compare(vpszTypeName[i]) == 0) {
type = i;
break;
}
}
- if (i == ARRAYLEN(ppszTypeName))
+ if (i == vpszTypeName.size())
throw std::out_of_range(strprintf("CInv::CInv(string, uint256) : unknown type '%s'", strType.c_str()));
}
bool CInv::IsKnownType() const
{
- return (type >= 1 && type < (int)ARRAYLEN(ppszTypeName));
+ return (type >= 1 && type < (int)vpszTypeName.size());
}
const char* CInv::GetCommand() const
{
if (!IsKnownType())
throw std::out_of_range(strprintf("CInv::GetCommand() : type=%d unknown type", type));
- return ppszTypeName[type];
+ return vpszTypeName[type].c_str();
}
std::string CInv::ToString() const
throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first.");
string strError = pwalletMain->SendMoney(scriptPubKey, nAmount, wtx);
- if (strError != "")
+ if (!strError.empty())
throw JSONRPCError(RPC_WALLET_ERROR, strError);
return wtx.GetHash().GetHex();
// Send
string strError = pwalletMain->SendMoney(scriptPubKey, nAmount, wtx);
- if (strError != "")
+ if (!strError.empty())
throw JSONRPCError(RPC_WALLET_ERROR, strError);
return wtx.GetHash().GetHex();
bool involvesWatchonly = wtx.IsFromMe(MINE_WATCH_ONLY);
// Generated blocks assigned to account ""
- if ((nGeneratedMature+nGeneratedImmature) != 0 && (fAllAccounts || strAccount == ""))
+ if ((nGeneratedMature+nGeneratedImmature) != 0 && (fAllAccounts || strAccount.empty()))
{
Object entry;
entry.push_back(Pair("account", string("")));
list<pair<CBitcoinAddress, int64_t> > listSent;
GetAmounts(allGeneratedImmature, allGeneratedMature, listReceived, listSent, allFee, strSentAccount, filter);
- if (strAccount == "")
+ if (strAccount.empty())
nGenerated = allGeneratedMature;
if (strAccount == strSentAccount)
{