From bb25eab0787cd4ae23d4b1e750d06d766b0aeade Mon Sep 17 00:00:00 2001 From: John Colvin Date: Sun, 4 May 2025 15:13:18 +0000 Subject: [PATCH] cleanup: Remove dependency on quickfix for string to_lower We shouldn't depend on external libs for trivial things like converting strings to lower case. --- .../orderman/gateways/OkxExecutionGateway.cpp | 10 ++++++---- src/lib/utils/string_utils.h | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/lib/orderman/gateways/OkxExecutionGateway.cpp b/src/lib/orderman/gateways/OkxExecutionGateway.cpp index 393f820eb..c9cb1f081 100644 --- a/src/lib/orderman/gateways/OkxExecutionGateway.cpp +++ b/src/lib/orderman/gateways/OkxExecutionGateway.cpp @@ -21,7 +21,9 @@ #include "lib/orderman/orderman_utils/orderman_common.h" #include "lib/utils/Uuid.h" #include "lib/utils/bts_assert.h" +#include "lib/utils/string_utils.h" #include "lib/utils/thread_manager.h" + #include #include #include @@ -40,8 +42,6 @@ #include #include #include -#include -#include #include #include #include @@ -50,6 +50,8 @@ using json = nlohmann::json; namespace bts::orderman { +using bts::system::string_utils::copy_to_lower; + OkxExecutionGateway::OkxExecutionGateway(md::SecurityOracle o) : me_(std::make_unique(o)) { LOG(OrderMan, Info, "OkxExecutionAdapter::constructor "); @@ -777,8 +779,8 @@ void OkxExecutionGateway::launch_new_order(const CreateOrderMsg &msg) { order_type = "fok"; break; default: - order_type = - FIX::string_toLower(ord_full_name.substr(pos + suffix.size())); + order_type = copy_to_lower(ord_full_name.substr(pos + suffix.size())); + break; } const std::string ord_type = order_type; diff --git a/src/lib/utils/string_utils.h b/src/lib/utils/string_utils.h index 676a73abb..ebe6eb52c 100644 --- a/src/lib/utils/string_utils.h +++ b/src/lib/utils/string_utils.h @@ -17,6 +17,9 @@ bool parse_uint(Iter first, Iter last, UIntType &i); template bool parse_uint(const std::string &s, UIntType &i); +void to_lower(std::string &str); +std::string copy_to_lower(const std::string &str); + void to_upper(std::string &str); std::string copy_to_upper(const std::string &str); @@ -63,6 +66,21 @@ inline bool parse_uint(Iter first, Iter last, UIntType &i) { return true; } +inline void to_lower(std::string &str) { + for (char &c : str) { + c = tolower(c); + } +} + +inline std::string copy_to_lower(const std::string &str) { + std::string s; + s.reserve(str.size()); + for (char c : str) { + s.push_back(tolower(c)); + } + return s; +} + inline void to_upper(std::string &str) { for (char &c : str) { c = toupper(c);