From df4ec096491ded6d58b9ee094d6942e3188c2d4a Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 23 Nov 2025 17:26:48 +0100 Subject: fix: lib: `visit` may now throw exceptions. Signed-off-by: Amlal El Mahrouss --- dev/lib/fix/fix.hpp | 51 +++++++++++++++++++++++---------------------------- 1 file changed, 23 insertions(+), 28 deletions(-) (limited to 'dev/lib/fix') diff --git a/dev/lib/fix/fix.hpp b/dev/lib/fix/fix.hpp index 08360d5..0c6685d 100644 --- a/dev/lib/fix/fix.hpp +++ b/dev/lib/fix/fix.hpp @@ -151,6 +151,9 @@ namespace ocl::fix return this->visit(in); } + /// @brief Visit a FIX message and parse it into a basic_range_data object. + /// @param in The input FIX message as a string. + /// @warning This function may throw exceptions. basic_range_data visit(const std::basic_string& in) { thread_local basic_range_data ret{}; @@ -160,37 +163,29 @@ namespace ocl::fix std::basic_string in_tmp{"", in.size()}; - try + for (auto& ch : in) { - for (auto& ch : in) + if (ch != basic_visitor::soh) { - if (ch != basic_visitor::soh) - { - in_tmp += ch; - continue; - } - - std::basic_string key = in_tmp.substr(0, in_tmp.find(basic_visitor::eq)); - std::basic_string val = in_tmp.substr(in_tmp.find(basic_visitor::eq) + 1); - - if (ret.magic_.empty()) - { - ret.magic_ = val; - ret.magic_len_ = ret.magic_.size(); - } - else - { - ret.body_.emplace_back(std::make_pair(key, val)); - ret.body_len_ += in_tmp.size(); - } - - in_tmp.clear(); + in_tmp += ch; + continue; } - } - catch (...) - { + + std::basic_string key = in_tmp.substr(0, in_tmp.find(basic_visitor::eq)); + std::basic_string val = in_tmp.substr(in_tmp.find(basic_visitor::eq) + 1); + + if (ret.magic_.empty()) + { + ret.magic_ = val; + ret.magic_len_ = ret.magic_.size(); + } + else + { + ret.body_.emplace_back(std::make_pair(key, val)); + ret.body_len_ += in_tmp.size(); + } + in_tmp.clear(); - return ret; } in_tmp.clear(); @@ -210,7 +205,7 @@ namespace ocl::fix using fix_tag_type = std::uint32_t; using range_data = basic_range_data; - using visitor = basic_visitor; + using visitor = basic_visitor; } // namespace ocl::fix #endif // ifndef _OCL_FIX_PARSER_HPP \ No newline at end of file -- cgit v1.2.3