From c0b69e8ef7208a75bb006fbd2d3dc497def118b6 Mon Sep 17 00:00:00 2001 From: Nik Bougalis Date: Sun, 28 Sep 2014 18:38:11 -0700 Subject: [PATCH] Remove the use of beast::String from rippled (RIPD-443) --- src/ripple/app/ledger/Ledger.cpp | 14 ++- src/ripple/app/main/Application.cpp | 9 +- src/ripple/app/main/Main.cpp | 19 ++-- src/ripple/app/misc/ProofOfWorkFactory.cpp | 4 - src/ripple/app/node/SqliteFactory.cpp | 28 +++--- src/ripple/app/node/SqliteFactory.h | 2 +- src/ripple/app/shamap/SHAMap.cpp | 15 +-- src/ripple/basics/LoggedTimings.h | 26 ++--- src/ripple/common/tests/MultiSocket.test.cpp | 22 +++-- src/ripple/core/Config.h | 11 +-- src/ripple/core/ConfigSections.h | 6 +- src/ripple/core/impl/Config.cpp | 22 ++--- src/ripple/data/crypto/RFC1751.cpp | 2 +- src/ripple/data/crypto/RFC1751.h | 2 +- src/ripple/data/protocol/STAmount.test.cpp | 35 +++---- src/ripple/net/impl/RPCDoor.cpp | 6 +- src/ripple/nodestore/Database.h | 2 +- src/ripple/nodestore/Factory.h | 2 +- .../nodestore/backend/HyperDBFactory.cpp | 2 +- .../nodestore/backend/LevelDBFactory.cpp | 2 +- .../nodestore/backend/MemoryFactory.cpp | 2 +- src/ripple/nodestore/backend/NullFactory.cpp | 3 +- .../nodestore/backend/RocksDBFactory.cpp | 2 +- src/ripple/nodestore/impl/DatabaseImp.h | 3 +- src/ripple/nodestore/impl/Manager.cpp | 8 +- src/ripple/nodestore/tests/BackendTests.cpp | 4 +- src/ripple/nodestore/tests/DatabaseTests.cpp | 15 +-- src/ripple/nodestore/tests/TimingTests.cpp | 18 +--- src/ripple/resource/impl/Tests.cpp | 2 +- src/ripple/testoverlay/api/Results.h | 13 +-- src/ripple/testoverlay/api/SimplePayload.h | 27 ++---- src/ripple/testoverlay/impl/TestOverlay.cpp | 12 +-- src/ripple/validators/Manager.h | 4 +- src/ripple/validators/Source.h | 9 +- src/ripple/validators/impl/Logic.h | 4 +- src/ripple/validators/impl/Manager.cpp | 20 +--- src/ripple/validators/impl/SourceFile.cpp | 8 +- src/ripple/validators/impl/SourceStrings.cpp | 24 ++--- src/ripple/validators/impl/SourceStrings.h | 2 +- src/ripple/validators/impl/SourceURL.cpp | 8 +- src/ripple/validators/impl/StoreSqdb.cpp | 97 ++++++++++++++++--- src/ripple/validators/impl/StoreSqdb.h | 6 ++ src/ripple/validators/impl/Tests.cpp | 27 +++--- src/ripple/validators/impl/Utilities.cpp | 69 ------------- src/ripple/validators/impl/Utilities.h | 9 -- 45 files changed, 285 insertions(+), 342 deletions(-) diff --git a/src/ripple/app/ledger/Ledger.cpp b/src/ripple/app/ledger/Ledger.cpp index 1be830bab..66091876e 100644 --- a/src/ripple/app/ledger/Ledger.cpp +++ b/src/ripple/app/ledger/Ledger.cpp @@ -243,18 +243,16 @@ Ledger::~Ledger () { if (mTransactionMap) { - logTimedDestroy ( - mTransactionMap, - "mTransactionMap with " - + std::to_string(mTransactionMap->size ()) + " items"); + logTimedDestroy (mTransactionMap, + "mTransactionMap with " + + std::to_string(mTransactionMap->size ()) + " items"); } if (mAccountStateMap) { - logTimedDestroy ( - mAccountStateMap, - "mAccountStateMap with " - + std::to_string (mAccountStateMap->size ()) + " items"); + logTimedDestroy (mAccountStateMap, + "mAccountStateMap with " + + std::to_string (mAccountStateMap->size ()) + " items"); } } diff --git a/src/ripple/app/main/Application.cpp b/src/ripple/app/main/Application.cpp index 12787fe4a..5879fabc6 100644 --- a/src/ripple/app/main/Application.cpp +++ b/src/ripple/app/main/Application.cpp @@ -209,14 +209,16 @@ public: //-------------------------------------------------------------------------- - static std::vector > make_Factories () + static + std::vector > + make_Factories (int hashnode_cache_size) { std::vector > list; // VFALCO NOTE SqliteFactory is here because it has // dependencies like SqliteDatabase and DatabaseCon // - list.emplace_back (make_SqliteFactory ()); + list.emplace_back (make_SqliteFactory (hashnode_cache_size)); return list; } @@ -241,7 +243,8 @@ public: , m_journal (m_logs.journal("Application")) , m_nodeStoreManager (NodeStore::make_Manager ( - std::move (make_Factories ()))) + std::move (make_Factories ( + getConfig ().getSize(siHashNodeDBCache) * 1024)))) , m_tempNodeCache ("NodeCache", 16384, 90, get_seconds_clock (), m_logs.journal("TaggedCache")) diff --git a/src/ripple/app/main/Main.cpp b/src/ripple/app/main/Main.cpp index 5311ce2b7..326117eab 100644 --- a/src/ripple/app/main/Main.cpp +++ b/src/ripple/app/main/Main.cpp @@ -167,13 +167,14 @@ int run (int argc, char** argv) int iResult = 0; po::variables_map vm; - beast::String importDescription; + std::string importText; { - importDescription << - "Import an existing node database (specified in the " << - "[" << ConfigSection::importNodeDatabase () << "] configuration file section) " - "into the current node database (specified in the " << - "[" << ConfigSection::nodeDatabase () << "] configuration file section). "; + importText += "Import an existing node database (specified in the ["; + importText += ConfigSection::importNodeDatabase (); + importText += "] configuration file section) into the current "; + importText += "node database (specified in the ["; + importText += ConfigSection::nodeDatabase (); + importText += "] configuration file section)."; } // VFALCO TODO Replace boost program options with something from Beast. @@ -201,7 +202,7 @@ int run (int argc, char** argv) ("start", "Start from a fresh Ledger.") ("net", "Get the initial ledger from the network.") ("fg", "Run in the foreground.") - ("import", importDescription.toStdString ().c_str ()) + ("import", importText.c_str ()) ("version", "Display the build version.") ; @@ -240,8 +241,8 @@ int run (int argc, char** argv) if (vm.count ("version")) { - beast::String const& s (BuildInfo::getVersionString ()); - std::cout << "rippled version " << s.toStdString() << std::endl; + std::cout << "rippled version " << + BuildInfo::getVersionString () << std::endl; return 0; } diff --git a/src/ripple/app/misc/ProofOfWorkFactory.cpp b/src/ripple/app/misc/ProofOfWorkFactory.cpp index 12c67437f..0c39bdb55 100644 --- a/src/ripple/app/misc/ProofOfWorkFactory.cpp +++ b/src/ripple/app/misc/ProofOfWorkFactory.cpp @@ -371,10 +371,6 @@ public: ProofOfWorkFactoryImp gen; ProofOfWork pow = gen.getProof (); - beast::String s; - - s << "solve difficulty " << beast::String (pow.getDifficulty ()); - uint256 solution = pow.solve (16777216); expect (! solution.isZero (), "Should be solved"); diff --git a/src/ripple/app/node/SqliteFactory.cpp b/src/ripple/app/node/SqliteFactory.cpp index bd97c91fb..41f580104 100644 --- a/src/ripple/app/node/SqliteFactory.cpp +++ b/src/ripple/app/node/SqliteFactory.cpp @@ -51,16 +51,13 @@ static int s_nodeStoreDBCount = RIPPLE_ARRAYSIZE (s_nodeStoreDBInit); class SqliteBackend : public NodeStore::Backend { public: - explicit SqliteBackend (std::string const& path) + explicit SqliteBackend (std::string const& path, int hashnode_cache_size) : m_name (path) , m_db (new DatabaseCon(path, s_nodeStoreDBInit, s_nodeStoreDBCount)) { - beast::String s; - - // VFALCO TODO Remove this dependency on theConfig - // - s << "PRAGMA cache_size=-" << beast::String (getConfig ().getSize(siHashNodeDBCache) * 1024); - m_db->getDB()->executeSQL (s.toStdString ().c_str ()); + std::string s ("PRAGMA cache_size=-"); + s += std::to_string (hashnode_cache_size); + m_db->getDB()->executeSQL (s); } ~SqliteBackend() @@ -227,8 +224,16 @@ private: class SqliteFactory : public NodeStore::Factory { + int hashnode_cache_size_; + public: - beast::String getName () const + SqliteFactory (int hashnode_cache_size) + : hashnode_cache_size_ (hashnode_cache_size) + { + } + + std::string + getName () const { return "Sqlite"; } @@ -237,15 +242,16 @@ public: size_t, NodeStore::Parameters const& keyValues, NodeStore::Scheduler&, beast::Journal) { - return std::make_unique (keyValues ["path"].toStdString ()); + return std::make_unique ( + keyValues ["path"].toStdString (), hashnode_cache_size_); } }; //------------------------------------------------------------------------------ -std::unique_ptr make_SqliteFactory () +std::unique_ptr make_SqliteFactory (int hashnode_cache_size) { - return std::make_unique (); + return std::make_unique (hashnode_cache_size); } } diff --git a/src/ripple/app/node/SqliteFactory.h b/src/ripple/app/node/SqliteFactory.h index 7ff70820a..52d10a5a2 100644 --- a/src/ripple/app/node/SqliteFactory.h +++ b/src/ripple/app/node/SqliteFactory.h @@ -27,7 +27,7 @@ namespace ripple { /** Factory to produce SQLite backends for the NodeStore. @see Database */ -std::unique_ptr make_SqliteFactory (); +std::unique_ptr make_SqliteFactory (int hashnode_cache_size); } diff --git a/src/ripple/app/shamap/SHAMap.cpp b/src/ripple/app/shamap/SHAMap.cpp index 4b6d971ed..d6e5c7f11 100644 --- a/src/ripple/app/shamap/SHAMap.cpp +++ b/src/ripple/app/shamap/SHAMap.cpp @@ -83,22 +83,17 @@ SHAMap::~SHAMap () { mState = smsInvalid; - logTimedDestroy (mTNByID, - beast::String ("mTNByID with ") + - beast::String::fromNumber (mTNByID.size ()) + " items"); + logTimedDestroy (mTNByID, "mTNByID with " + + std::to_string (mTNByID.size ()) + " items"); if (mDirtyNodes) { - logTimedDestroy (mDirtyNodes, - beast::String ("mDirtyNodes with ") + - beast::String::fromNumber (mDirtyNodes->size ()) + " items"); + logTimedDestroy (mDirtyNodes, "mDirtyNodes with " + + std::to_string (mDirtyNodes->size ()) + " items"); } if (root) - { - logTimedDestroy (root, - beast::String ("root node")); - } + logTimedDestroy (root, "root node"); } void SHAMapNodeID::setMHash () const diff --git a/src/ripple/basics/LoggedTimings.h b/src/ripple/basics/LoggedTimings.h index cbb601bf7..e9032d557 100644 --- a/src/ripple/basics/LoggedTimings.h +++ b/src/ripple/basics/LoggedTimings.h @@ -99,15 +99,17 @@ double timedDestroy (Object& object) */ template void logTimedDestroy ( - Object& object, beast::String objectDescription, double thresholdSeconds = 1) + Object& object, + std::string const& objectDescription, + double thresholdSeconds = 1) { double const seconds = timedDestroy (object); if (seconds > thresholdSeconds) { deprecatedLogs().journal("LoggedTimings").warning << - objectDescription << " took "<< - beast::String (detail::cleanElapsed (seconds)) << + objectDescription << " took " << + detail::cleanElapsed (seconds) << " seconds to destroy"; } } @@ -116,11 +118,13 @@ void logTimedDestroy ( /** Log a timed function call if the time exceeds a threshold. */ template -void logTimedCall (beast::Journal::Stream stream, - beast::String description, - char const* fileName, - int lineNumber, - Function f, double thresholdSeconds = 1) +void logTimedCall ( + beast::Journal::Stream stream, + std::string const& description, + char const* fileName, + int lineNumber, + Function f, + double thresholdSeconds = 1) { double const seconds = beast::measureFunctionCallTime (f); @@ -128,9 +132,9 @@ void logTimedCall (beast::Journal::Stream stream, { stream << description << " took "<< - beast::String (detail::cleanElapsed (seconds)) << - " seconds to execute at " << - beast::Debug::getSourceLocation (fileName, lineNumber); + detail::cleanElapsed (seconds) << + " seconds to execute at " << + beast::Debug::getSourceLocation (fileName, lineNumber); } } diff --git a/src/ripple/common/tests/MultiSocket.test.cpp b/src/ripple/common/tests/MultiSocket.test.cpp index 4dc1d6ebe..4e4429154 100644 --- a/src/ripple/common/tests/MultiSocket.test.cpp +++ b/src/ripple/common/tests/MultiSocket.test.cpp @@ -40,28 +40,30 @@ public: { } - static beast::String getArgName (arg_type arg) + static std::string getArgName (arg_type arg) { - beast::String s; + std::string s; if (arg & MultiSocket::Flag::client_role) - s << "client,"; + s += "client,"; if (arg & MultiSocket::Flag::server_role) - s << "server,"; + s += "server,"; if (arg & MultiSocket::Flag::ssl) - s << "ssl,"; + s += "ssl,"; if (arg & MultiSocket::Flag::ssl_required) - s << "ssl_required,"; + s += "ssl_required,"; if (arg & MultiSocket::Flag::proxy) - s << "proxy,"; + s += "proxy,"; - if (s != beast::String::empty) + if (!s.empty ()) { - s = "(" + s.substring (0, s.length () - 1) + ")"; + s = std::string ("(") + + s.substr (0, s.length () - 1) + + std::string (")"); } return s; @@ -88,7 +90,7 @@ public: return holder.context->get (); } - beast::String name () const + std::string name () const { return getArgName (m_flags); } diff --git a/src/ripple/core/Config.h b/src/ripple/core/Config.h index 0d8436908..984c30e84 100644 --- a/src/ripple/core/Config.h +++ b/src/ripple/core/Config.h @@ -60,8 +60,7 @@ getIniFileSection (IniFileSections& secSource, std::string const& strSection); */ // DEPRECATED beast::StringPairArray -parseKeyValueSection (IniFileSections& secSource, - beast::String const& strSection); +parseKeyValueSection (IniFileSections& secSource, std::string const& strSection); //------------------------------------------------------------------------------ @@ -246,13 +245,9 @@ public: /** Convert the RPC/port combination to a readable string. */ - beast::String const getRpcAddress () + std::string const getRpcAddress () { - beast::String s; - - s << m_rpcIP.c_str () << ":" << m_rpcPort; - - return s; + return m_rpcIP + ":" + std::to_string (m_rpcPort); } /** Determine the level of administrative permission to grant. diff --git a/src/ripple/core/ConfigSections.h b/src/ripple/core/ConfigSections.h index 2d5c11d5b..e452e9b6e 100644 --- a/src/ripple/core/ConfigSections.h +++ b/src/ripple/core/ConfigSections.h @@ -30,9 +30,9 @@ namespace ripple { // struct ConfigSection { - static beast::String nodeDatabase () { return "node_db"; } - static beast::String tempNodeDatabase () { return "temp_db"; } - static beast::String importNodeDatabase () { return "import_db"; } + static std::string nodeDatabase () { return "node_db"; } + static std::string tempNodeDatabase () { return "temp_db"; } + static std::string importNodeDatabase () { return "import_db"; } }; // VFALCO TODO Rename and replace these macros with variables. diff --git a/src/ripple/core/impl/Config.cpp b/src/ripple/core/impl/Config.cpp index cfe3a1fe8..71a9a957f 100644 --- a/src/ripple/core/impl/Config.cpp +++ b/src/ripple/core/impl/Config.cpp @@ -145,34 +145,28 @@ bool getSingleSection (IniFileSections& secSource, } beast::StringPairArray -parseKeyValueSection (IniFileSections& secSource, - beast::String const& strSection) +parseKeyValueSection (IniFileSections& secSource, std::string const& strSection) { beast::StringPairArray result; - // yuck. - std::string const stdStrSection (strSection.toStdString ()); - typedef IniFileSections::mapped_type Entries; - Entries* const entries = getIniFileSection (secSource, stdStrSection); + Entries* const entries = getIniFileSection (secSource, strSection); if (entries != nullptr) { for (Entries::const_iterator iter = entries->begin (); iter != entries->end (); ++iter) { - beast::String const line (iter->c_str ()); + std::string const line (iter->c_str ()); - int const equalPos = line.indexOfChar ('='); + int const equalPos = line.find ('='); - if (equalPos != -1) + if (equalPos != std::string::npos) { - beast::String const key = line.substring (0, equalPos); - beast::String const value = line.substring (equalPos + 1, - line.length ()); - - result.set (key, value); + result.set ( + line.substr (0, equalPos), + line.substr (equalPos + 1)); } } } diff --git a/src/ripple/data/crypto/RFC1751.cpp b/src/ripple/data/crypto/RFC1751.cpp index b60118b0d..0b69c4061 100644 --- a/src/ripple/data/crypto/RFC1751.cpp +++ b/src/ripple/data/crypto/RFC1751.cpp @@ -473,7 +473,7 @@ void RFC1751::getEnglishFromKey (std::string& strHuman, std::string const& strKe strHuman = strFirst + " " + strSecond; } -beast::String RFC1751::getWordFromBlob (void const* data, size_t bytes) +std::string RFC1751::getWordFromBlob (void const* data, size_t bytes) { std::uint32_t hash; diff --git a/src/ripple/data/crypto/RFC1751.h b/src/ripple/data/crypto/RFC1751.h index 6054ee5e0..57969613d 100644 --- a/src/ripple/data/crypto/RFC1751.h +++ b/src/ripple/data/crypto/RFC1751.h @@ -36,7 +36,7 @@ public: it to turn the pubkey_node into an easily remembered and identified 4 character string. */ - static beast::String getWordFromBlob (void const* data, size_t bytes); + static std::string getWordFromBlob (void const* data, size_t bytes); private: static unsigned long extract (char const* s, int start, int length); diff --git a/src/ripple/data/protocol/STAmount.test.cpp b/src/ripple/data/protocol/STAmount.test.cpp index 7e93a8516..5c46e16ce 100644 --- a/src/ripple/data/protocol/STAmount.test.cpp +++ b/src/ripple/data/protocol/STAmount.test.cpp @@ -118,10 +118,10 @@ public: bool const result = amount.setValue (value); - expect (result == success, std::string ("parse ") + value); + expect (result == success, "parse " + value); if (success) - expect (amount.getText () == value, std::string ("format ") + value); + expect (amount.getText () == value, "format " + value); } void testSetValue () @@ -449,29 +449,17 @@ public: //-------------------------------------------------------------------------- - template - bool - expect (Cond cond, beast::String const& s) - { - return suite::expect (cond, s.toStdString()); - } - - template - bool - expect (Cond cond) - { - return suite::expect (cond); - } - void testUnderflow () { testcase ("underflow"); STAmount bigNative (STAmount::cMaxNative / 2); STAmount bigValue (noIssue(), - (STAmount::cMinValue + STAmount::cMaxValue) / 2, STAmount::cMaxOffset - 1); + (STAmount::cMinValue + STAmount::cMaxValue) / 2, + STAmount::cMaxOffset - 1); STAmount smallValue (noIssue(), - (STAmount::cMinValue + STAmount::cMaxValue) / 2, STAmount::cMinOffset + 1); + (STAmount::cMinValue + STAmount::cMaxValue) / 2, + STAmount::cMinOffset + 1); STAmount zeroSt (noIssue(), 0); STAmount smallXsmall = multiply (smallValue, smallValue, noIssue()); @@ -480,7 +468,7 @@ public: STAmount bigDsmall = divide (smallValue, bigValue, noIssue()); - expect (bigDsmall == zero, beast::String ("small/big != 0: ") + bigDsmall.getText ()); + expect (bigDsmall == zero, "small/big != 0: " + bigDsmall.getText ()); #if 0 // TODO(tom): this test makes no sense - we should have no way to have @@ -488,15 +476,18 @@ public: bigDsmall = divide (smallValue, bigNative, noCurrency(), xrpAccount ()); #endif - expect (bigDsmall == zero, beast::String ("small/bigNative != 0: ") + bigDsmall.getText ()); + expect (bigDsmall == zero, + "small/bigNative != 0: " + bigDsmall.getText ()); bigDsmall = divide (smallValue, bigValue, xrpIssue ()); - expect (bigDsmall == zero, beast::String ("(small/big)->N != 0: ") + bigDsmall.getText ()); + expect (bigDsmall == zero, + "(small/big)->N != 0: " + bigDsmall.getText ()); bigDsmall = divide (smallValue, bigNative, xrpIssue ()); - expect (bigDsmall == zero, beast::String ("(small/bigNative)->N != 0: ") + bigDsmall.getText ()); + expect (bigDsmall == zero, + "(small/bigNative)->N != 0: " + bigDsmall.getText ()); // very bad offer std::uint64_t r = getRate (smallValue, bigValue); diff --git a/src/ripple/net/impl/RPCDoor.cpp b/src/ripple/net/impl/RPCDoor.cpp index 7128db4a4..e6179bdca 100644 --- a/src/ripple/net/impl/RPCDoor.cpp +++ b/src/ripple/net/impl/RPCDoor.cpp @@ -37,7 +37,9 @@ public: getConfig ().RPC_SSL_CERT, getConfig ().RPC_SSL_CHAIN)) { - WriteLog (lsINFO, RPCDoor) << "RPC port: " << getConfig ().getRpcAddress().toRawUTF8() << " allow remote: " << getConfig ().RPC_ALLOW_REMOTE; + WriteLog (lsINFO, RPCDoor) << + "RPC port: " << getConfig ().getRpcAddress() << + " allow remote: " << getConfig ().RPC_ALLOW_REMOTE; startListening (); } @@ -47,7 +49,7 @@ public: ~RPCDoorImp () { WriteLog (lsINFO, RPCDoor) << - "RPC port: " << getConfig ().getRpcAddress().toRawUTF8() << + "RPC port: " << getConfig ().getRpcAddress() << " allow remote: " << getConfig ().RPC_ALLOW_REMOTE; } diff --git a/src/ripple/nodestore/Database.h b/src/ripple/nodestore/Database.h index 7c31a69bc..2b67dd31c 100644 --- a/src/ripple/nodestore/Database.h +++ b/src/ripple/nodestore/Database.h @@ -51,7 +51,7 @@ public: This is used for diagnostics and may not reflect the actual path or paths used by the underlying backend. */ - virtual beast::String getName () const = 0; + virtual std::string getName () const = 0; /** Fetch an object. If the object is known to be not in the database, isn't found in the diff --git a/src/ripple/nodestore/Factory.h b/src/ripple/nodestore/Factory.h index fcfcbfe83..6343e5433 100644 --- a/src/ripple/nodestore/Factory.h +++ b/src/ripple/nodestore/Factory.h @@ -32,7 +32,7 @@ public: virtual ~Factory () = 0; /** Retrieve the name of this factory. */ - virtual beast::String getName () const = 0; + virtual std::string getName () const = 0; /** Create an instance of this factory's backend. @param keyBytes The fixed number of bytes per key. diff --git a/src/ripple/nodestore/backend/HyperDBFactory.cpp b/src/ripple/nodestore/backend/HyperDBFactory.cpp index dbbd56230..7613f4df7 100644 --- a/src/ripple/nodestore/backend/HyperDBFactory.cpp +++ b/src/ripple/nodestore/backend/HyperDBFactory.cpp @@ -233,7 +233,7 @@ public: class HyperDBFactory : public NodeStore::Factory { public: - beast::String + std::string getName () const { return "HyperLevelDB"; diff --git a/src/ripple/nodestore/backend/LevelDBFactory.cpp b/src/ripple/nodestore/backend/LevelDBFactory.cpp index b1139eeb6..b74b34147 100644 --- a/src/ripple/nodestore/backend/LevelDBFactory.cpp +++ b/src/ripple/nodestore/backend/LevelDBFactory.cpp @@ -254,7 +254,7 @@ public: { } - beast::String + std::string getName () const { return "LevelDB"; diff --git a/src/ripple/nodestore/backend/MemoryFactory.cpp b/src/ripple/nodestore/backend/MemoryFactory.cpp index 022b9ed46..b4504e4a4 100644 --- a/src/ripple/nodestore/backend/MemoryFactory.cpp +++ b/src/ripple/nodestore/backend/MemoryFactory.cpp @@ -105,7 +105,7 @@ public: class MemoryFactory : public Factory { public: - beast::String + std::string getName () const { return "Memory"; diff --git a/src/ripple/nodestore/backend/NullFactory.cpp b/src/ripple/nodestore/backend/NullFactory.cpp index aaeb2b50d..fbd10e729 100644 --- a/src/ripple/nodestore/backend/NullFactory.cpp +++ b/src/ripple/nodestore/backend/NullFactory.cpp @@ -72,7 +72,8 @@ private: class NullFactory : public Factory { public: - beast::String getName () const + std::string + getName () const { return "none"; } diff --git a/src/ripple/nodestore/backend/RocksDBFactory.cpp b/src/ripple/nodestore/backend/RocksDBFactory.cpp index 07f40d0b7..85c249d34 100644 --- a/src/ripple/nodestore/backend/RocksDBFactory.cpp +++ b/src/ripple/nodestore/backend/RocksDBFactory.cpp @@ -356,7 +356,7 @@ public: { } - beast::String + std::string getName () const { return "RocksDB"; diff --git a/src/ripple/nodestore/impl/DatabaseImp.h b/src/ripple/nodestore/impl/DatabaseImp.h index 6deb17bb3..6dc2c6114 100644 --- a/src/ripple/nodestore/impl/DatabaseImp.h +++ b/src/ripple/nodestore/impl/DatabaseImp.h @@ -92,7 +92,8 @@ public: e.join(); } - beast::String getName () const + std::string + getName () const { return m_backend->getName (); } diff --git a/src/ripple/nodestore/impl/Manager.cpp b/src/ripple/nodestore/impl/Manager.cpp index 435e3baf3..af5c598c1 100644 --- a/src/ripple/nodestore/impl/Manager.cpp +++ b/src/ripple/nodestore/impl/Manager.cpp @@ -19,6 +19,8 @@ #include +#include + namespace ripple { namespace NodeStore { @@ -67,10 +69,14 @@ public: Factory* find (std::string const& name) const { + beast::ci_equal_to casecmp; + for (List::const_iterator iter (m_list.begin ()); iter != m_list.end (); ++iter) - if ((*iter)->getName().compareIgnoreCase (name) == 0) + { + if (casecmp ((*iter)->getName(), name)) return iter->get(); + } return nullptr; } diff --git a/src/ripple/nodestore/tests/BackendTests.cpp b/src/ripple/nodestore/tests/BackendTests.cpp index 8b77d628d..8121ccaa1 100644 --- a/src/ripple/nodestore/tests/BackendTests.cpp +++ b/src/ripple/nodestore/tests/BackendTests.cpp @@ -27,14 +27,14 @@ namespace NodeStore { class Backend_test : public TestBase { public: - void testBackend (beast::String type, std::int64_t const seedValue, + void testBackend (std::string const& type, std::int64_t const seedValue, int numObjectsToTest = 2000) { std::unique_ptr manager (make_Manager ()); DummyScheduler scheduler; - testcase ((beast::String ("Backend type=") + type).toStdString()); + testcase ("Backend type=" + type); beast::StringPairArray params; beast::File const path (beast::File::createTempFile ("node_db")); diff --git a/src/ripple/nodestore/tests/DatabaseTests.cpp b/src/ripple/nodestore/tests/DatabaseTests.cpp index 2d69db3c0..24785933b 100644 --- a/src/ripple/nodestore/tests/DatabaseTests.cpp +++ b/src/ripple/nodestore/tests/DatabaseTests.cpp @@ -23,7 +23,8 @@ namespace NodeStore { class NodeStoreDatabase_test : public TestBase { public: - void testImport (beast::String destBackendType, beast::String srcBackendType, std::int64_t seedValue) + void testImport (std::string const& destBackendType, + std::string const& srcBackendType, std::int64_t seedValue) { std::unique_ptr manager (make_Manager ()); @@ -63,7 +64,8 @@ public: std::unique_ptr dest (manager->make_Database ( "test", scheduler, j, 2, destParams)); - testcase ((beast::String ("import into '") + destBackendType + "' from '" + srcBackendType + "'").toStdString()); + testcase ("import into '" + destBackendType + + "' from '" + srcBackendType + "'"); // Do the import dest->import (*src); @@ -80,7 +82,7 @@ public: //-------------------------------------------------------------------------- - void testNodeStore (beast::String type, + void testNodeStore (std::string const& type, bool const useEphemeralDatabase, bool const testPersistence, std::int64_t const seedValue, @@ -90,12 +92,11 @@ public: DummyScheduler scheduler; - beast::String s; - s << beast::String ("NodeStore backend '") + type + "'"; + std::string s = "NodeStore backend '" + type + "'"; if (useEphemeralDatabase) - s << " (with ephemeral database)"; + s += " (with ephemeral database)"; - testcase (s.toStdString()); + testcase (s); beast::File const node_db (beast::File::createTempFile ("node_db")); beast::StringPairArray nodeParams; diff --git a/src/ripple/nodestore/tests/TimingTests.cpp b/src/ripple/nodestore/tests/TimingTests.cpp index dd4eccc19..ce49a39d6 100644 --- a/src/ripple/nodestore/tests/TimingTests.cpp +++ b/src/ripple/nodestore/tests/TimingTests.cpp @@ -53,15 +53,13 @@ public: //-------------------------------------------------------------------------- - void testBackend (beast::String type, std::int64_t const seedValue) + void testBackend (std::string const& type, std::int64_t const seedValue) { std::unique_ptr manager (make_Manager ()); DummyScheduler scheduler; - beast::String s; - s << "Testing backend '" << type << "' performance"; - testcase (s.toStdString()); + testcase ("Testing backend '" + type + "' performance"); beast::StringPairArray params; beast::File const path (beast::File::createTempFile ("node_db")); @@ -85,25 +83,19 @@ public: // Individual write batch test t.start (); storeBatch (*backend, batch1); - s = ""; - s << " Single write: " << beast::String (t.getElapsed (), 2) << " seconds"; - log << s.toStdString(); + log << " Single write: " << std::to_string (t.getElapsed ()) << " seconds"; // Bulk write batch test t.start (); backend->storeBatch (batch2); - s = ""; - s << " Batch write: " << beast::String (t.getElapsed (), 2) << " seconds"; - log << s.toStdString(); + log << " Batch write: " << std::to_string (t.getElapsed ()) << " seconds"; // Read test Batch copy; t.start (); fetchCopyOfBatch (*backend, ©, batch1); fetchCopyOfBatch (*backend, ©, batch2); - s = ""; - s << " Batch read: " << beast::String (t.getElapsed (), 2) << " seconds"; - log << s.toStdString(); + log << " Batch read: " << std::to_string (t.getElapsed ()) << " seconds"; } //-------------------------------------------------------------------------- diff --git a/src/ripple/resource/impl/Tests.cpp b/src/ripple/resource/impl/Tests.cpp index 22d9e5976..878db6916 100644 --- a/src/ripple/resource/impl/Tests.cpp +++ b/src/ripple/resource/impl/Tests.cpp @@ -173,7 +173,7 @@ public: createGossip (g[i]); for (int i = 0; i < 5; ++i) - logic.importConsumers (beast::String::fromNumber (i).toStdString(), g[i]); + logic.importConsumers (std::to_string (i), g[i]); pass(); } diff --git a/src/ripple/testoverlay/api/Results.h b/src/ripple/testoverlay/api/Results.h index a77a5a1cc..3a2bc0341 100644 --- a/src/ripple/testoverlay/api/Results.h +++ b/src/ripple/testoverlay/api/Results.h @@ -51,15 +51,12 @@ struct Results return *this; } - beast::String toString () const + std::string to_string () const { - using beast::String; - String s; - s = "steps(" + String::fromNumber (steps) + ")" - + ", sent(" + String::fromNumber (sent) + ")" - + ", received(" + String::fromNumber (received) + ")" - + ", dropped(" + String::fromNumber (dropped) + ")"; - return s; + return "steps=" + std::to_string (steps) + + ", sent=" + std::to_string (sent) + + ", received=" + std::to_string (received) + + ", dropped=" + std::to_string (dropped); } Results& operator+= (Results const& other) diff --git a/src/ripple/testoverlay/api/SimplePayload.h b/src/ripple/testoverlay/api/SimplePayload.h index 8081b6cd8..27b41bd19 100644 --- a/src/ripple/testoverlay/api/SimplePayload.h +++ b/src/ripple/testoverlay/api/SimplePayload.h @@ -27,32 +27,17 @@ namespace TestOverlay class SimplePayload { public: - SimplePayload () - { - } + SimplePayload () = default; + SimplePayload (SimplePayload const& other) = default; + SimplePayload& operator= (SimplePayload const& other) = default; - SimplePayload (int what, beast::String data = beast::String::empty, int hops = 0) + SimplePayload (int what, std::string const& data = "", int hops = 0) : m_hops (hops) , m_what (what) , m_data (data) { } - SimplePayload (SimplePayload const& other) - : m_hops (other.m_hops) - , m_what (other.m_what) - , m_data (other.m_data) - { - } - - SimplePayload& operator= (SimplePayload const& other) - { - m_hops = other.m_hops; - m_what = other.m_what; - m_data = other.m_data; - return *this; - } - SimplePayload withHop () const { return SimplePayload (m_what, m_data, m_hops + 1); @@ -68,7 +53,7 @@ public: return m_what; } - beast::String data () const + std::string data () const { return m_data; } @@ -76,7 +61,7 @@ public: private: int m_hops; int m_what; - beast::String m_data; + std::string m_data; }; } diff --git a/src/ripple/testoverlay/impl/TestOverlay.cpp b/src/ripple/testoverlay/impl/TestOverlay.cpp index 6318a0d76..ba93ae66d 100644 --- a/src/ripple/testoverlay/impl/TestOverlay.cpp +++ b/src/ripple/testoverlay/impl/TestOverlay.cpp @@ -118,20 +118,14 @@ public: Results result; for (int i = 0; result.received < 249 && i < 100; ++i) { - using beast::String; - String s = - String ("step #") + String::fromNumber ( - network.steps()) + " "; + auto s = "step #" + std::to_string (network.steps()) + " "; result += network.step (); - s << result.toString (); - log << s.toStdString(); + log << s << result.to_string (); } int const seen (network.state().seen()); - beast::String s = "Seen = " + beast::String::fromNumber (seen); - log << - s.toStdString(); + log << "Seen = " << std::to_string (seen); pass (); } diff --git a/src/ripple/validators/Manager.h b/src/ripple/validators/Manager.h index 16e7004fa..67904d51e 100644 --- a/src/ripple/validators/Manager.h +++ b/src/ripple/validators/Manager.h @@ -68,10 +68,8 @@ public: Can be called from any thread. */ /** @{ */ - virtual void addStrings (beast::String name, + virtual void addStrings (std::string const& name, std::vector const& strings) = 0; - virtual void addStrings (beast::String name, - beast::StringArray const& stringArray) = 0; virtual void addFile (beast::File const& file) = 0; virtual void addStaticSource (Validators::Source* source) = 0; /** @} */ diff --git a/src/ripple/validators/Source.h b/src/ripple/validators/Source.h index 1692fae94..cee124c38 100644 --- a/src/ripple/validators/Source.h +++ b/src/ripple/validators/Source.h @@ -39,7 +39,7 @@ public: RipplePublicKey publicKey; /** Optional human readable comment describing the validator. */ - beast::String label; + std::string label; }; /** Destroy the Source. @@ -55,10 +55,10 @@ public: /** An identifier that uniquely describes the source. This is used for identification in the database. */ - virtual beast::String uniqueID () const = 0; + virtual std::string uniqueID () const = 0; /** A string that is used to recreate the source from the database entry. */ - virtual beast::String createParam () = 0; + virtual std::string createParam () = 0; /** Cancel any pending fetch. The default implementation does nothing. @@ -74,8 +74,7 @@ public: Results (); bool success; - // VFALCO TODO Replace with std::string - beast::String message; + std::string message; // VFALCO TODO Replace with chrono beast::Time expirationTime; std::vector list; diff --git a/src/ripple/validators/impl/Logic.h b/src/ripple/validators/impl/Logic.h index a7b92f208..7c8cde0a3 100644 --- a/src/ripple/validators/impl/Logic.h +++ b/src/ripple/validators/impl/Logic.h @@ -216,7 +216,7 @@ public: // Returns `true` if a Source with the same unique ID already exists // - bool findSourceByID (beast::String id) + bool findSourceByID (std::string id) { for (SourceTable::const_iterator iter (m_sources.begin()); iter != m_sources.end(); ++iter) @@ -364,7 +364,7 @@ public: m_journal.debug << "Rebuilt chosen list with " << - beast::String::fromNumber (m_chosenList->size()) << " entries"; + std::to_string (m_chosenList->size()) << " entries"; } /** Mark the Chosen List for a rebuild. */ diff --git a/src/ripple/validators/impl/Manager.cpp b/src/ripple/validators/impl/Manager.cpp index bbd42f21b..aa9f4841a 100644 --- a/src/ripple/validators/impl/Manager.cpp +++ b/src/ripple/validators/impl/Manager.cpp @@ -198,25 +198,15 @@ public: // //-------------------------------------------------------------------------- - void addStrings (beast::String name, std::vector const& strings) + void addStrings (std::string const& name, std::vector const& strings) { - beast::StringArray stringArray; - stringArray.ensureStorageAllocated (strings.size()); - for (std::size_t i = 0; i < strings.size(); ++i) - stringArray.add (strings [i]); - addStrings (name, stringArray); - } - - void addStrings (beast::String name, beast::StringArray const& stringArray) - { - if (stringArray.size() > 0) - { - addStaticSource (SourceStrings::New (name, stringArray)); - } - else + if (strings.empty ()) { m_journal.debug << "Static source '" << name << "' is empty."; + return; } + + addStaticSource (SourceStrings::New (name, strings)); } void addFile (beast::File const& file) diff --git a/src/ripple/validators/impl/SourceFile.cpp b/src/ripple/validators/impl/SourceFile.cpp index 07253573a..aa8d60af1 100644 --- a/src/ripple/validators/impl/SourceFile.cpp +++ b/src/ripple/validators/impl/SourceFile.cpp @@ -45,14 +45,14 @@ public: return ss.str(); } - beast::String uniqueID () const + std::string uniqueID () const { - return "File," + m_file.getFullPathName (); + return "File," + m_file.getFullPathName ().toStdString(); } - beast::String createParam () + std::string createParam () { - return m_file.getFullPathName (); + return m_file.getFullPathName ().toStdString(); } void fetch (Results& results, beast::Journal journal) diff --git a/src/ripple/validators/impl/SourceStrings.cpp b/src/ripple/validators/impl/SourceStrings.cpp index 84e49a502..c3dde0a7b 100644 --- a/src/ripple/validators/impl/SourceStrings.cpp +++ b/src/ripple/validators/impl/SourceStrings.cpp @@ -25,8 +25,7 @@ class SourceStringsImp , public beast::LeakChecked { public: - SourceStringsImp ( - beast::String name, beast::StringArray const& strings) + SourceStringsImp (std::string const& name, std::vector const& strings) : m_name (name) , m_strings (strings) { @@ -38,18 +37,18 @@ public: std::string to_string () const { - return m_name.toStdString(); + return m_name; } - beast::String uniqueID () const + std::string uniqueID () const { // VFALCO TODO This can't be right...? - return beast::String::empty; + return std::string{}; } - beast::String createParam () + std::string createParam () { - return beast::String::empty; + return std::string{}; } void fetch (Results& results, beast::Journal journal) @@ -57,10 +56,7 @@ public: results.list.reserve (m_strings.size ()); for (int i = 0; i < m_strings.size (); ++i) - { - std::string const s (m_strings [i].toStdString ()); - Utilities::parseResultLine (results, s); - } + Utilities::parseResultLine (results, m_strings [i]); results.success = results.list.size () > 0; results.expirationTime = beast::Time::getCurrentTime () + @@ -68,14 +64,14 @@ public: } private: - beast::String m_name; - beast::StringArray m_strings; + std::string m_name; + std::vector m_strings; }; //------------------------------------------------------------------------------ SourceStrings* SourceStrings::New ( - beast::String name, beast::StringArray const& strings) + std::string const& name, std::vector const& strings) { return new SourceStringsImp (name, strings); } diff --git a/src/ripple/validators/impl/SourceStrings.h b/src/ripple/validators/impl/SourceStrings.h index dbdeca57d..66058c397 100644 --- a/src/ripple/validators/impl/SourceStrings.h +++ b/src/ripple/validators/impl/SourceStrings.h @@ -30,7 +30,7 @@ class SourceStrings : public Source { public: static SourceStrings* New ( - beast::String name, beast::StringArray const& strings); + std::string const& name, std::vector const& strings); }; } diff --git a/src/ripple/validators/impl/SourceURL.cpp b/src/ripple/validators/impl/SourceURL.cpp index 407dd9170..4a0d62dda 100644 --- a/src/ripple/validators/impl/SourceURL.cpp +++ b/src/ripple/validators/impl/SourceURL.cpp @@ -46,14 +46,14 @@ public: return ss.str(); } - beast::String uniqueID () const + std::string uniqueID () const { - return "URL," + m_url.toString(); + return "URL," + m_url.to_string(); } - beast::String createParam () + std::string createParam () { - return m_url.toString(); + return m_url.to_string(); } void cancel () diff --git a/src/ripple/validators/impl/StoreSqdb.cpp b/src/ripple/validators/impl/StoreSqdb.cpp index 2f453f6d2..e15cee537 100644 --- a/src/ripple/validators/impl/StoreSqdb.cpp +++ b/src/ripple/validators/impl/StoreSqdb.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +#include + namespace ripple { namespace Validators { @@ -65,10 +67,10 @@ void StoreSqdb::insert (SourceDesc& desc) { beast::Error error; - beast::String const sourceID (desc.source->uniqueID().toStdString()); - beast::String const createParam (desc.source->createParam().toStdString()); - beast::String const lastFetchTime (Utilities::timeToString (desc.lastFetchTime)); - beast::String const expirationTime (Utilities::timeToString (desc.expirationTime)); + auto const sourceID (desc.source->uniqueID()); + auto const createParam (desc.source->createParam()); + auto const lastFetchTime (timeToString (desc.lastFetchTime)); + auto const expirationTime (timeToString (desc.expirationTime)); beast::sqdb::statement st = (m_session.prepare << "INSERT INTO Validators_Source ( " @@ -101,14 +103,80 @@ void StoreSqdb::insert (SourceDesc& desc) } //-------------------------------------------------------------------------- +std::string StoreSqdb::itos (int i, std::size_t width) +{ + auto s = std::to_string (i); + if (s.length () < width) + s = std::string (width - s.length(), '0').append (s); + + return s; +} + +beast::Time StoreSqdb::stringToTime (std::string const& s) +{ + static boost::regex const date_pattern ( + "^" // the beginning of the string + "(19[789][0-9]|[2-9][0-9][0-9][0-9])-" // 1970-9999 followed by - + "(0[0-9]|1[01])-" // 0-11 followed by - + "(0[1-9]|[12][0-9]|3[01]) " // 1-31 followed by space + "([01][0-9]|2[0-3]):" // 0-23 followed by : + "([0-5][0-9]):" // 0-59 followed by : + "([0-5][0-9])" // 0-59 + "$", + boost::regex_constants::optimize); + + boost::smatch match; + + if (boost::regex_match (s, match, date_pattern)) + { + int const year = beast::lexicalCast (std::string (match[1]), -1); + int const mon = beast::lexicalCast (std::string (match[2]), -1); + int const day = beast::lexicalCast (std::string (match[3]), -1); + int const hour = beast::lexicalCast (std::string (match[4]), -1); + int const min = beast::lexicalCast (std::string (match[5]), -1); + int const sec = beast::lexicalCast (std::string (match[6]), -1); + + if (year != -1 && + mon != -1 && + day != -1 && + hour != -1 && + min != -1 && + sec != -1) + { + // local time + return beast::Time (year, mon, day, hour, min, sec, 0, true); + } + } + + return beast::Time (0); +} + +std::string StoreSqdb::timeToString (beast::Time const& t) +{ + std::string ret; + + if (t.isNotNull ()) + { + ret = itos (t.getYear(), 4) + "-" + + itos (t.getMonth(), 2) + "-" + + itos (t.getDayOfMonth (), 2) + " " + + itos (t.getHours () , 2) + ":" + + itos (t.getMinutes (), 2) + ":" + + itos (t.getSeconds(), 2); + } + + return ret; +} + +//-------------------------------------------------------------------------- void StoreSqdb::update (SourceDesc& desc, bool updateFetchResults) { beast::Error error; - beast::String const sourceID (desc.source->uniqueID()); - beast::String const lastFetchTime (Utilities::timeToString (desc.lastFetchTime)); - beast::String const expirationTime (Utilities::timeToString (desc.expirationTime)); + std::string const sourceID (desc.source->uniqueID()); + std::string const lastFetchTime (timeToString (desc.lastFetchTime)); + std::string const expirationTime (timeToString (desc.expirationTime)); beast::sqdb::transaction tr (m_session); @@ -136,7 +204,7 @@ void StoreSqdb::update (SourceDesc& desc, bool updateFetchResults) if (! error) { std::string publicKeyString; - beast::String label; + std::string label; beast::sqdb::statement st = (m_session.prepare << "INSERT INTO Validators_SourceItem ( " @@ -197,9 +265,10 @@ bool StoreSqdb::select (SourceDesc& desc) beast::Error error; - beast::String const sourceID (desc.source->uniqueID()); - beast::String lastFetchTime; - beast::String expirationTime; + std::string const sourceID (desc.source->uniqueID()); + std::string lastFetchTime; + std::string expirationTime; + beast::sqdb::statement st = (m_session.prepare << "SELECT " " lastFetchTime, " @@ -217,8 +286,8 @@ bool StoreSqdb::select (SourceDesc& desc) "Found record for " << *desc.source; found = true; - desc.lastFetchTime = Utilities::stringToTime (lastFetchTime); - desc.expirationTime = Utilities::stringToTime (expirationTime); + desc.lastFetchTime = stringToTime (lastFetchTime); + desc.expirationTime = stringToTime (expirationTime); } else if (! error) { @@ -243,7 +312,7 @@ void StoreSqdb::selectList (SourceDesc& desc) { beast::Error error; - beast::String const sourceID (desc.source->uniqueID()); + std::string const sourceID (desc.source->uniqueID()); // Get the count std::size_t count; diff --git a/src/ripple/validators/impl/StoreSqdb.h b/src/ripple/validators/impl/StoreSqdb.h index 03321af85..62f769044 100644 --- a/src/ripple/validators/impl/StoreSqdb.h +++ b/src/ripple/validators/impl/StoreSqdb.h @@ -62,6 +62,12 @@ private: beast::Journal m_journal; beast::sqdb::session m_session; + + + // DEPRECATED + static std::string itos (int i, std::size_t fieldSize = 0); + static std::string timeToString (beast::Time const& t); + static beast::Time stringToTime (std::string const& s); }; } diff --git a/src/ripple/validators/impl/Tests.cpp b/src/ripple/validators/impl/Tests.cpp index 94ec6bd0b..675d3f5c1 100644 --- a/src/ripple/validators/impl/Tests.cpp +++ b/src/ripple/validators/impl/Tests.cpp @@ -35,7 +35,7 @@ public: struct TestSource : Source { - TestSource (beast::String const& name, std::uint32_t start, std::uint32_t end) + TestSource (std::string const& name, std::uint32_t start, std::uint32_t end) : m_name (name) , m_start (start) , m_end (end) @@ -44,38 +44,37 @@ public: std::string to_string () const { - return uniqueID().toStdString(); + return uniqueID(); } - beast::String uniqueID () const + std::string uniqueID () const { - using beast::String; - return String ("Test,") + m_name + "," + - String::fromNumber (m_start) + "," + - String::fromNumber (m_end); + return "Test," + m_name + "," + + std::to_string (m_start) + "," + + std::to_string (m_end); } - beast::String createParam () + std::string createParam () { - return beast::String::empty; + return std::string{}; } void fetch (Results& results, beast::Journal) { results.success = true; - results.message = beast::String::empty; + results.message = std::string{}; results.list.reserve (numberOfTestValidators); for (std::uint32_t i = m_start ; i < m_end; ++i) { - Item item;; + Item item; item.publicKey = RipplePublicKey::createFromInteger (i); - item.label = beast::String::fromNumber (i); + item.label = std::to_string (i); results.list.push_back (item); } } - beast::String m_name; + std::string m_name; std::size_t m_start; std::size_t m_end; }; @@ -113,7 +112,7 @@ public: beast::Random r; for (int i = 1; i <= numberofTestSources; ++i) { - beast::String const name (beast::String::fromNumber (i)); + std::string const name (std::to_string (i)); std::uint32_t const start = r.nextInt (numberOfTestValidators); std::uint32_t const end = start + r.nextInt (numberOfTestValidators); logic.add (new TestSource (name, start, end)); diff --git a/src/ripple/validators/impl/Utilities.cpp b/src/ripple/validators/impl/Utilities.cpp index dc6c8eb8c..6406b03ab 100644 --- a/src/ripple/validators/impl/Utilities.cpp +++ b/src/ripple/validators/impl/Utilities.cpp @@ -136,74 +136,5 @@ void Utilities::parseResultLine ( } } -//-------------------------------------------------------------------------- - -beast::String Utilities::itos (int i, int fieldSize) -{ - return beast::String::fromNumber (i).paddedLeft (beast::beast_wchar('0'), fieldSize); -} - -beast::String Utilities::timeToString (beast::Time const& t) -{ - if (t.isNotNull ()) - { - return - itos (t.getYear(), 4) + "-" + - itos (t.getMonth(), 2) + "-" + - itos (t.getDayOfMonth (), 2) + " " + - itos (t.getHours () , 2) + ":" + - itos (t.getMinutes (), 2) + ":" + - itos (t.getSeconds(), 2); - } - - return beast::String::empty; -} - -int Utilities::stoi (beast::String& s, int fieldSize, int minValue, int maxValue, - beast::beast_wchar delimiter) -{ - int const needed (fieldSize + ((delimiter != 0) ? 1 : 0)); - beast::String const v (s.substring (0, needed)); - s = s.substring (v.length ()); - if (s.length() == needed) - { - int const v (s.getIntValue()); - if (s.startsWith (itos (v, fieldSize)) && - v >= minValue && v <= maxValue && - (delimiter == 0 || s.endsWithChar (delimiter))) - { - return v; - } - } - return -1; // fail -} - -beast::Time Utilities::stringToTime (beast::String s) -{ - if (s.isNotEmpty ()) - { - int const year (stoi (s, 4, 1970, 9999, '-')); - int const mon (stoi (s, 2, 0, 11, '-')); - int const day (stoi (s, 2, 1, 31, ' ')); - int const hour (stoi (s, 2, 0, 23, ':')); - int const min (stoi (s, 2, 0, 59, ':')); - int const sec (stoi (s, 2, 0, 59, 0 )); - if (year != -1 && - mon != -1 && - day != -1 && - hour != -1 && - min != -1 && - sec != -1) - { - // local time - return beast::Time (year, mon, day, hour, min, sec, 0, true); - } - } - - return beast::Time (0); -} - -//------------------------------------------------------------------------------ - } } diff --git a/src/ripple/validators/impl/Utilities.h b/src/ripple/validators/impl/Utilities.h index 1a1a8e10e..3ebf457fd 100644 --- a/src/ripple/validators/impl/Utilities.h +++ b/src/ripple/validators/impl/Utilities.h @@ -121,15 +121,6 @@ public: std::string const& line, beast::Journal journal = beast::Journal()); - // helpers - static beast::String itos (int i, int fieldSize = 0); - static int stoi (beast::String& s, int fieldSize, int minValue, int maxValue, - beast::beast_wchar delimiter); - - // conversion betwen Time and String - static beast::String timeToString (beast::Time const& t); - static beast::Time stringToTime (beast::String s); - struct Helpers; /** Parse a string into a Source::Item.