From be6db5d69ab30dc16b9ca2cbdd53cdd21a783551 Mon Sep 17 00:00:00 2001 From: Oleg Pipikin Date: Wed, 30 Mar 2022 19:48:29 +0300 Subject: [PATCH] Fix for str_to_container if string value has whitespaces (#10224) * Fix for str_to_container if string value has whitespaces * Add test * Add trim for leading and trailing whitespaces * Apply comments * Apply comments 2 * Apply comments 3 --- src/frontends/ir/src/rt_info_deserializer.cpp | 2 +- src/frontends/ir/src/utils.cpp | 15 +++++++++++++++ src/frontends/ir/src/utils.hpp | 3 +++ .../ir_serialization/rt_info_deserialization.cpp | 4 ++-- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/frontends/ir/src/rt_info_deserializer.cpp b/src/frontends/ir/src/rt_info_deserializer.cpp index 5d8fff73eac..4da107033cc 100644 --- a/src/frontends/ir/src/rt_info_deserializer.cpp +++ b/src/frontends/ir/src/rt_info_deserializer.cpp @@ -17,7 +17,7 @@ void RTInfoDeserializer::on_adapter(const std::string& name, ValueAccessor return; if (auto a = as_type>>(&adapter)) { std::set ss; - str_to_container(val, ss); + str_to_set_of_strings(val, ss); a->set(ss); } else { IE_THROW() << "Not implemented"; diff --git a/src/frontends/ir/src/utils.cpp b/src/frontends/ir/src/utils.cpp index 15bf031443a..6207eb261c5 100644 --- a/src/frontends/ir/src/utils.cpp +++ b/src/frontends/ir/src/utils.cpp @@ -98,4 +98,19 @@ bool get_dimension_from_attribute(const pugi::xml_node& node, const std::string& return true; } +void str_to_set_of_strings(const std::string& value, std::set& res) { + std::stringstream ss(value); + std::string field; + while (getline(ss, field, ',')) { + // trim leading and trailing whitespaces + auto strBegin = field.find_first_not_of(" "); + if (strBegin == std::string::npos) + IE_THROW() << "Cannot get a set of strings from \"" << value << "\". Value \"" << field + << "\" is incorrect"; + auto strRange = field.find_last_not_of(" ") - strBegin + 1; + + res.insert(field.substr(strBegin, strRange)); + } +} + } // namespace ov diff --git a/src/frontends/ir/src/utils.hpp b/src/frontends/ir/src/utils.hpp index d3ed15ef306..f8f53da7ebd 100644 --- a/src/frontends/ir/src/utils.hpp +++ b/src/frontends/ir/src/utils.hpp @@ -32,6 +32,9 @@ void str_to_container(const std::string& value, T& res) { res.insert(res.end(), val); } } +// separated function for set to keep whitespaces in values +// because stringstream splits its values with whitespace delimiter +void str_to_set_of_strings(const std::string& value, std::set& res); template bool getParameters(const pugi::xml_node& node, const std::string& name, std::vector& value) { diff --git a/src/tests/functional/inference_engine/ir_serialization/rt_info_deserialization.cpp b/src/tests/functional/inference_engine/ir_serialization/rt_info_deserialization.cpp index 6902ee30b47..7b2bc95c24d 100644 --- a/src/tests/functional/inference_engine/ir_serialization/rt_info_deserialization.cpp +++ b/src/tests/functional/inference_engine/ir_serialization/rt_info_deserialization.cpp @@ -472,7 +472,7 @@ TEST_F(RTInfoDeserialization, NodeV11) { - + @@ -553,7 +553,7 @@ TEST_F(RTInfoDeserialization, NodeV11) { auto result = f->get_result(); check_old_api_map_order(result->get_rt_info(), std::vector({0, 3, 1, 2})); auto round = result->get_input_node_ptr(0); - check_fused_names(round->get_rt_info(), "Round1,Round2"); + check_fused_names(round->get_rt_info(), "Round 1,Round 2"); // read IR v11 with new API {