OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[core] Migrate common utils to use string view insted of string (#35410)
Pawel Raasz85d271d2ba5e
diff --git a/src/bindings/python/src/pyopenvino/graph/dimension.cpp b/src/bindings/python/src/pyopenvino/graph/dimension.cppindex 7e21f0ee7ba..a64dba833ed 100644--- a/src/bindings/python/src/pyopenvino/graph/dimension.cpp+++ b/src/bindings/python/src/pyopenvino/graph/dimension.cpp@@ -42,7 +42,7 @@ void regclass_graph_Dimension(py::module m) {:type max_dimension: int)");- dim.def(py::init<const std::string&>(), py::arg("str"));+ dim.def(py::init<std::string_view>(), py::arg("str"));dim.def_static("dynamic", &ov::Dimension::dynamic);diff --git a/src/common/snippets/include/snippets/utils/debug_caps_config.hpp b/src/common/snippets/include/snippets/utils/debug_caps_config.hppindex 60f27574c4c..4371e1238ac 100644--- a/src/common/snippets/include/snippets/utils/debug_caps_config.hpp+++ b/src/common/snippets/include/snippets/utils/debug_caps_config.hpp@@ -1,7 +1,6 @@// Copyright (C) 2018-2026 Intel Corporation// SPDX-License-Identifier: Apache-2.0//-#include <cstddef>#include <cstdint>#ifdef SNIPPETS_DEBUG_CAPS@@ -137,7 +136,9 @@ private:~MultipleStringPropertySetter() override = default;bool parseAndSet(const std::string& str) override {- propertyValues = ov::util::split(ov::util::to_lower(str), ',');+ const auto lower = ov::util::to_lower(str);+ const auto parts = ov::util::split(lower, ",");+ propertyValues.assign(parts.begin(), parts.end());return true;}@@ -167,8 +168,8 @@ private:~BitsetFilterPropertySetter() override = default;bool parseAndSet(const std::string& str) override {- const auto& tokens =- str.empty() ? std::vector<std::string>{"all"} : ov::util::split(ov::util::to_lower(str), ',');+ const auto lower = ov::util::to_lower(str);+ const auto tokens = str.empty() ? std::vector<std::string_view>{"all"} : ov::util::split(lower, ",");property.reset();for (const auto& token : tokens) {const bool tokenVal = (token.front() != '-');diff --git a/src/common/snippets/src/utils/debug_caps_config.cpp b/src/common/snippets/src/utils/debug_caps_config.cppindex 6fd6d85c382..a903b4dc29a 100644--- a/src/common/snippets/src/utils/debug_caps_config.cpp+++ b/src/common/snippets/src/utils/debug_caps_config.cpp@@ -32,7 +32,7 @@ void DebugCapsConfig::readProperties() {}void DebugCapsConfig::PropertyGroup::parseAndSet(const std::string& str) {- const auto& options = ov::util::split(str, ' ');+ const auto& options = ov::util::split(str, " ");const auto& propertySetters = getPropertySetters();bool failed = false;auto getHelp = [propertySetters]() {@@ -47,7 +47,7 @@ void DebugCapsConfig::PropertyGroup::parseAndSet(const std::string& str) {if (option.empty()) {continue;}- const auto& parts = ov::util::split(option, '=');+ const auto& parts = ov::util::split(option, "=");if (parts.size() > 2) {failed = true;break;@@ -59,7 +59,7 @@ void DebugCapsConfig::PropertyGroup::parseAndSet(const std::string& str) {return setter->getPropertyName() == propertyName;});if (foundSetter == propertySetters.end() ||- !(*foundSetter)->parseAndSet(parts.size() == 1 ? "" : parts.back())) {+ !(*foundSetter)->parseAndSet(parts.size() == 1 ? "" : std::string(parts.back()))) {failed = true;break;}diff --git a/src/common/util/include/openvino/util/common_util.hpp b/src/common/util/include/openvino/util/common_util.hppindex ac5baaca71d..d078b1b5b25 100644--- a/src/common/util/include/openvino/util/common_util.hpp+++ b/src/common/util/include/openvino/util/common_util.hpp@@ -7,17 +7,17 @@#include <algorithm>#include <array>#include <cctype>+#include <charconv>#include <cstdint>#include <cstring>#include <filesystem>#include <numeric>+#include <optional>#include <sstream>#include <string>#include <vector>-namespace ov {-namespace util {-+namespace ov::util {/*** @brief Join container's elements to string using user string as separator.*@@ -56,9 +56,9 @@ std::string vector_to_string(const std::vector<T, A>& v) {return "[ " + ov::util::join(v) + " ]";}-std::string to_lower(const std::string& s);+std::string to_lower(std::string_view s);-std::string to_upper(const std::string& s);+std::string to_upper(std::string_view s);inline size_t hash_combine(size_t val, const size_t seed) {return seed ^ (val + 0x9e3779b9 + (seed << 6) + (seed >> 2));@@ -104,43 +104,33 @@ constexpr uint64_t u64_hash_combine(uint64_t seed, std::initializer_list<uint64_}/**- * @brief trim from start (in place)- * @param s - string to trim+ * @brief Return a string view with leading whitespace removed.+ *+ * @param s A string view to trim.+ * @return A string view with leading whitespace removed.*/-inline std::string ltrim(const std::string& s) {- std::string ret = s;- ret.erase(ret.begin(), std::find_if(ret.begin(), ret.end(), [](int c) {- return !std::isspace(c);- }));- return ret;+constexpr std::string_view ltrim(std::string_view s) {+ const auto not_ws_pos = s.find_first_not_of(" \t\n\r\f\v");+ return not_ws_pos == std::string_view::npos ? std::string_view() : s.substr(not_ws_pos);}/**- * @brief trim from end (in place)- * @param s - string to trim+ * @brief Return a string view with trailing whitespace removed.+ * @param s A string view to trim.+ * @return A string view with trailing whitespace removed.*/-inline std::string rtrim(const std::string& s) {- std::string ret = s;- ret.erase(std::find_if(ret.rbegin(),- ret.rend(),- [](int c) {- return !std::isspace(c);- })- .base(),- ret.end());- return ret;+constexpr std::string_view rtrim(std::string_view s) {+ const auto not_ws_pos = s.find_last_not_of(" \t\n\r\f\v");+ return not_ws_pos == std::string_view::npos ? std::string_view() : s.substr(0, not_ws_pos + 1);}/**- * @brief Trims std::string from both ends (in place)- * @ingroup ov_dev_api_error_debug- * @param s A reference to a std::tring to trim- * @return A reference to a trimmed std::string+ * @brief Return a string view with leading and trailing whitespace removed.+ * @param s A string view to trim.+ * @return A string view with leading and trailing whitespace removed.*/-inline std::string trim(const std::string& s) {- std::string ret = ltrim(s);- ret = rtrim(ret);- return ret;+constexpr std::string_view trim(std::string_view s) {+ return ltrim(rtrim(s));}/**@@ -148,30 +138,20 @@ inline std::string trim(const std::string& s) {* @param src - string to check* @param with - given substring* @return true if string end with given substring+ * @{*/-inline bool ends_with(const std::string& src, const char* with) {- int wl = static_cast<int>(strlen(with));- int so = static_cast<int>(src.length()) - wl;- if (so < 0)- return false;- return 0 == strncmp(with, &src[so], wl);+constexpr bool ends_with(std::string_view src, std::string_view with) {+ return src.size() >= with.size() && src.substr(src.size() - with.size()) == with;}-/**- * @brief check string/wstring end with given substring- * @param src - string/wstring to check- * @param with - given substring- * @return true if string end with given substring- */template <typename T>-inline bool ends_with(const std::basic_string<T>& str, const std::basic_string<T>& suffix) {- return str.length() >= suffix.length() && 0 == str.compare(str.length() - suffix.length(), suffix.length(), suffix);+constexpr bool ends_with(std::basic_string_view<T> src, std::basic_string_view<T> with) {+ return src.size() >= with.size() && src.substr(src.size() - with.size()) == with;}--std::vector<std::string> split(const std::string& s, char delimiter, bool trim = false);+/** @} */template <typename T>-T ceil_div(const T& x, const T& y) {+constexpr T ceil_div(const T& x, const T& y) {return (x == 0 ? 0 : (1 + (x - 1) / y));}@@ -183,7 +163,7 @@ T ceil_div(const T& x, const T& y) {* @return True if value found in the container, false otherwise.*/template <typename R, typename V>-bool contains(const R& container, const V& value) {+constexpr bool contains(const R& container, const V& value) {return std::find(std::begin(container), std::end(container), value) != std::end(container);}@@ -192,17 +172,17 @@ bool contains(const R& container, const V& value) {* @param vec - vector with values* @return result of multiplication*/-template <typename T, typename A>-T product(const std::vector<T, A>& vec) {- return vec.empty() ? T{0} : std::accumulate(vec.begin(), vec.end(), T{1}, std::multiplies<T>());+template <typename Container>+auto product(const Container& container) {+ using T = typename Container::value_type;+ return container.empty() ? T{0} : std::accumulate(container.begin(), container.end(), T{1}, std::multiplies<T>());}/**- * @brief Associative containers doesnt work with remove_if algorithm- * @tparam ContainerT- * @tparam PredicateT- * @param data An associative container- * @param predicate A predicate to remove values conditionally+ * @brief Removes elements from the container that satisfy the given predicate.+ *+ * @param data The container from which to remove elements.+ * @param predicate A callable that check element and return true if the element should be removed, or false otherwise.*/template <typename Container, typename PredicateT>inline void erase_if(Container& data, const PredicateT& predicate) {@@ -215,7 +195,17 @@ inline void erase_if(Container& data, const PredicateT& predicate) {}}-std::string filter_lines_by_prefix(const std::string& str, const std::string& prefix);+/**+ * @brief Filters lines in a string view based on a given prefix.+ *+ * This function iterates through each line in the input string view and returns a string containing+ * only the lines that start with the specified `prefix`.+ *+ * @param sv The input string view containing multiple lines.+ * @param prefix The prefix to filter lines by.+ * @return A string containing only the lines that start with the given prefix.+ */+std::string filter_lines_by_prefix(std::string_view sv, std::string_view prefix);template <class T = void, class... Args>constexpr std::array<std::conditional_t<std::is_void_v<T>, std::common_type_t<Args...>, T>, sizeof...(Args)> make_array(@@ -341,5 +331,115 @@ constexpr bool mul_overflow(T x, T y, T& result) {return false;#endif}-} // namespace util-} // namespace ov++/**+ * @brief This function attempts to parse the input string view `sv` into a number of type `T`.+ *+ * @tparam T The type of the number to convert to. Must be an arithmetic type.+ * @param sv The string view to convert.+ * @return std::optional<T> The parsed number if successful, or `std::nullopt` if the conversion fails.+ */+template <class T>+std::optional<T> view_to_number(std::string_view sv) noexcept {+ static_assert(std::is_arithmetic_v<T>, "T must be an arithmetic type");+ if constexpr (std::is_integral_v<T>) {+ T value{};+ const auto result = std::from_chars(sv.data(), sv.data() + sv.size(), value);+ return result.ec == std::errc() ? std::make_optional(value) : std::nullopt;+ } else {+ StringViewStreamBuf buf{sv};+ std::istream stream{&buf};+ stream.imbue(std::locale::classic());+ T value{};+ stream >> value;+ return stream ? std::make_optional<T>(value) : std::nullopt;+ }+}++/**+ * @brief Transforms a string view into a container.+ *+ * This function splits the input string view `sv` using the specified separator `sep` and inserts the parsed values+ * into the provided `result` container.+ * An optional unary transformation can be applied to the field before insertion.+ *+ * @param sv The input string view to parse.+ * @param output_it The iterator to store the parsed values.+ * @param sep The separator used to split the string view.+ * @param unary The callable used to transform each field. Defaults to no transformation.+ * @return Iterator The output iterator after inserting the parsed values.+ */+template <typename Iterator, typename UnaryOp = std::nullptr_t>+constexpr Iterator view_transform(std::string_view sv, Iterator output_it, std::string_view sep, UnaryOp unary = {}) {+ for (bool has_next = !sv.empty(); has_next; ++output_it) {+ const auto sep_pos = sv.find(sep);+ if constexpr (const auto field = sv.substr(0, sep_pos); std::is_same_v<UnaryOp, std::nullptr_t>) {+ *output_it = field;+ } else {+ *output_it = unary(field);+ }+ has_next = sep_pos != std::string_view::npos;+ sv = has_next ? sv.substr(sep_pos + sep.size()) : std::string_view{};+ }+ return output_it;+}++/**+ * @brief Transforms a string view into a container.+ *+ * This function splits the input string view `sv` using the specified separator `sep` and inserts the parsed values+ * into the provided `result` container if predicate returns true for the field.+ * An optional unary transformation can be applied to the field before insertion.+ *+ * @param sv The input string view to parse.+ * @param output_it The iterator to store the parsed values.+ * @param sep The separator used to split the string view.+ * @param predicate The callable used to validate each field.+ * @param unary The callable used to transform each field. Defaults to no transformation.+ * @return Iterator The output iterator after inserting the parsed values.+ */+template <typename Iterator, typename Predicate, typename UnaryOp = std::nullptr_t>+constexpr Iterator view_transform_if(std::string_view sv,+ Iterator output_it,+ std::string_view sep,+ Predicate predicate,+ UnaryOp unary = {}) {+ for (bool has_next = !sv.empty(); has_next; ++output_it) {+ const auto sep_pos = sv.find(sep);+ if (const auto field = sv.substr(0, sep_pos); predicate(field)) {+ if constexpr (std::is_same_v<UnaryOp, std::nullptr_t>) {+ *output_it = field;+ } else {+ *output_it = unary(field);+ }+ }+ has_next = sep_pos != std::string_view::npos;+ sv = has_next ? sv.substr(sep_pos + sep.size()) : std::string_view{};+ }+ return output_it;+}++/**+ * @brief Splits a string view into a vector of string views, optionally validating each field.+ *+ * This function splits the input string view `sv` using the specified separator `sep` and inserts the parsed values+ * into the provided `result` container.+ * An optional `predicate` can be provided to validate each field before insertion.+ *+ * @tparam Predicate A callable type used to validate each field. Defaults to `std::nullptr_t`, no validation.+ * @param sv The input string view to parse.+ * @param sep The separator used to split the string view. Defaults to ",".+ * @param predicate The callable used to validate each field. Defaults to no validation.+ * @return Container The container with the parsed string views.+ */+template <typename Predicate = std::nullptr_t>+std::vector<std::string_view> split(std::string_view sv, std::string_view sep = ",", Predicate predicate = {}) {+ std::vector<std::string_view> result{};+ if constexpr (std::is_same_v<Predicate, std::nullptr_t>) {+ view_transform(sv, std::back_inserter(result), sep);+ } else {+ view_transform_if(sv, std::back_inserter(result), sep, predicate);+ }+ return result;+}+} // namespace ov::utildiff --git a/src/common/util/include/openvino/util/weights_path.hpp b/src/common/util/include/openvino/util/weights_path.hppdeleted file mode 100644index 97dccb10a3f..00000000000--- a/src/common/util/include/openvino/util/weights_path.hpp+++ /dev/null@@ -1,15 +0,0 @@-// Copyright (C) 2018-2026 Intel Corporation-// SPDX-License-Identifier: Apache-2.0-//--#pragma once--#include "openvino/util/common_util.hpp"--namespace ov {-namespace util {--bool validate_weights_path(const std::string& weights_path);--} // namespace util-} // namespace ovdiff --git a/src/common/util/include/openvino/util/xml_parse_utils.hpp b/src/common/util/include/openvino/util/xml_parse_utils.hppindex 1c10077bf59..8849e4e48c2 100644--- a/src/common/util/include/openvino/util/xml_parse_utils.hpp+++ b/src/common/util/include/openvino/util/xml_parse_utils.hpp@@ -12,6 +12,7 @@#include <cstdlib>#include <fstream>#include <memory>+#include <optional>#include <pugixml.hpp>#include <sstream>#include <string>@@ -28,13 +29,11 @@*/#define FOREACH_CHILD(c, p, tag) for (auto c = p.child(tag); !c.empty(); c = c.next_sibling(tag))-namespace ov {-namespace util {+namespace ov::util::pugixml {/*** @brief XML helpers function to extract values from `pugi::xml_node`*/-namespace pugixml {/*** @brief Gets the integer attribute from `pugi::xml_node`@@ -242,6 +241,13 @@ inline ParseResult parse_xml(const std::filesystem::path& file_path) {return {std::move(nullptr), std::string("Error loading XML file: ") + e.what()};}}-} // namespace pugixml-} // namespace util-} // namespace ov++/**+ * @brief Get the string view on attribute value.+ *+ * @param node The XML node.+ * @param name The attribute name.+ * @return String view on attribute value if attribute exists, std::nullopt otherwise.+ */+std::optional<std::string_view> get_attribute_view(const pugi::xml_node& node, std::string_view name);+} // namespace ov::util::pugixmldiff --git a/src/common/util/src/common_util.cpp b/src/common/util/src/common_util.cppindex d388c90bf37..0a360d81b3c 100644--- a/src/common/util/src/common_util.cpp+++ b/src/common/util/src/common_util.cpp@@ -5,50 +5,28 @@#include "openvino/util/common_util.hpp"#include <algorithm>+#include <iterator>-std::string ov::util::to_lower(const std::string& s) {- std::string rc = s;- std::transform(rc.begin(), rc.end(), rc.begin(), ::tolower);+std::string ov::util::to_lower(std::string_view s) {+ std::string rc{s};+ std::transform(rc.begin(), rc.end(), rc.begin(), [](unsigned char c) {+ return std::tolower(c);+ });return rc;}-std::string ov::util::to_upper(const std::string& s) {- std::string rc = s;- std::transform(rc.begin(), rc.end(), rc.begin(), ::toupper);+std::string ov::util::to_upper(std::string_view s) {+ std::string rc{s};+ std::transform(rc.begin(), rc.end(), rc.begin(), [](unsigned char c) {+ return std::toupper(c);+ });return rc;}-std::vector<std::string> ov::util::split(const std::string& src, char delimiter, bool do_trim) {- size_t pos;- std::string token;- size_t start = 0;- std::vector<std::string> rc;- while ((pos = src.find(delimiter, start)) != std::string::npos) {- token = src.substr(start, pos - start);- start = pos + 1;- if (do_trim) {- token = trim(token);- }- rc.push_back(token);- }- if (start <= src.size()) {- token = src.substr(start);- if (do_trim) {- token = trim(token);- }- rc.push_back(token);- }- return rc;-}--std::string ov::util::filter_lines_by_prefix(const std::string& str, const std::string& prefix) {- auto lines = ov::util::split(str, '\n');- std::stringstream res;- const char* const prefix_c = prefix.c_str();- for (const auto& line : lines) {- if (line.find(prefix_c) == 0) {- res << line + '\n';- }- }+std::string ov::util::filter_lines_by_prefix(std::string_view sv, std::string_view prefix) {+ std::ostringstream res;+ view_transform_if(sv, std::ostream_iterator<std::string_view>(res, "\n"), "\n", [&prefix](auto&& field) {+ return field.find(prefix) == 0;+ });return res.str();}diff --git a/src/common/util/src/weights_path.cpp b/src/common/util/src/weights_path.cppdeleted file mode 100644index 10232b5f114..00000000000--- a/src/common/util/src/weights_path.cpp+++ /dev/null@@ -1,13 +0,0 @@-// Copyright (C) 2018-2026 Intel Corporation-// SPDX-License-Identifier: Apache-2.0-//--#include "openvino/util/weights_path.hpp"--bool ov::util::validate_weights_path(const std::string& weights_path) {- if (weights_path.empty() || !ov::util::ends_with(weights_path, ".bin")) {- return false;- }-- return true;-}diff --git a/src/common/util/src/xml_parse_utils.cpp b/src/common/util/src/xml_parse_utils.cppindex b248b3a25cc..02d8c0620b9 100644--- a/src/common/util/src/xml_parse_utils.cpp+++ b/src/common/util/src/xml_parse_utils.cpp@@ -10,8 +10,17 @@#include <set>#include <string>-namespace ov {-namespace util {+namespace ov::util {+namespace {++inline pugi::xml_attribute get_node_attr(const pugi::xml_node& node, std::string_view name) {+#ifdef PUGIXML_HAS_STRING_VIEW+ return node.attribute(name);+#else+ return node.attribute(std::string(name).c_str());+#endif+}+} // namespaceint pugixml::get_int_attr(const pugi::xml_node& node, const char* str) {auto attr = node.attribute(str);@@ -232,5 +241,14 @@ int pugixml::get_int_child(const pugi::xml_node& node, const char* str, int defVreturn atoi(child.child_value());}-} // namespace util-} // namespace ov+std::optional<std::string_view> pugixml::get_attribute_view(const pugi::xml_node& node, std::string_view name) {+ if (!node) {+ return std::nullopt;+ } else if (const auto attr = get_node_attr(node, name); !attr.empty()) {+ return std::make_optional<std::string_view>(attr.value());+ } else {+ return std::nullopt;+ }+}++} // namespace ov::utildiff --git a/src/core/dev_api/openvino/core/shape_util.hpp b/src/core/dev_api/openvino/core/shape_util.hppindex 50619b2ac59..8ad0c779b36 100644--- a/src/core/dev_api/openvino/core/shape_util.hpp+++ b/src/core/dev_api/openvino/core/shape_util.hpp@@ -8,7 +8,6 @@#include "openvino/core/shape.hpp"#include "openvino/op/util/attr_types.hpp"-#include "openvino/util/common_util.hpp"namespace ov {namespace util {diff --git a/src/core/include/openvino/core/dimension.hpp b/src/core/include/openvino/core/dimension.hppindex 043fc53c703..47d1c6c1e4f 100644--- a/src/core/include/openvino/core/dimension.hpp+++ b/src/core/include/openvino/core/dimension.hpp@@ -35,8 +35,20 @@ public:/// \brief Construct a dimension from string./// \param str String to parse to dimension.+ /// \deprecated Use string view version of constructor instead. It will be removed in 2027.0 release.+#ifdef IN_OV_COMPONENT+ OPENVINO_DEPRECATED("This ctor is deprecated, use string_view version. Will be removed in 2027.0 release")+#endifDimension(const std::string& str);+ /// \brief Construct a dimension from string view.+ /// \param sv String view to parse to dimension.+ /// \{+ explicit Dimension(std::string_view sv);+ template <class T, typename = std::enable_if_t<std::is_convertible_v<std::decay_t<T>, std::string_view>>>+ explicit Dimension(T&& sv) : Dimension(std::string_view(sv)) {}+ /// \}+/// \brief Construct a dynamic dimension with range [0, ...]Dimension() = default;diff --git a/src/core/src/dimension.cpp b/src/core/src/dimension.cppindex a10caee1eaf..f25f555db2c 100644--- a/src/core/src/dimension.cpp+++ b/src/core/src/dimension.cpp@@ -41,22 +41,10 @@ std::shared_ptr<ov::Symbol> merge_symbols(std::shared_ptr<ov::Symbol> lhs,return nullptr;}-int64_t stringToInt64(const std::string& valStr) {- int64_t ret{0};- std::istringstream ss(valStr);- if (!ss.eof()) {- ss >> ret;- }- return ret;-}--bool check_all_digits(const std::string& value) {- auto val = ov::util::trim(value);- for (const auto& c : val) {- if (!std::isdigit(c) || c == '-')- return false;- }- return true;+bool check_all_digits(std::string_view value) {+ return std::all_of(value.begin(), value.end(), [](unsigned char c) {+ return std::isdigit(c);+ });}Dimension::value_type dimension_length(Interval::value_type vt) {return vt == Interval::s_max ? -1 : vt;@@ -85,45 +73,38 @@ Dimension::Dimension(value_type dimension)Dimension::Dimension(value_type min_dimension, value_type max_dimension): m_dimension(min_dimension == -1 ? 0 : min_dimension, max_dimension == -1 ? Interval::s_max : max_dimension) {}-Dimension::Dimension(const std::string& value) {- auto val = ov::util::trim(value);- if (val == "?" || val == "-1") {- m_dimension = {0, Interval::s_max};- return;- }- if (val.find("..") == std::string::npos) {- OPENVINO_ASSERT(check_all_digits(val), "Cannot parse dimension: \"" + val + "\"");- m_dimension = {stringToInt64(val)};+Dimension::Dimension(const std::string& value) : Dimension(std::string_view(value)) {}++Dimension::Dimension(std::string_view sv) {+ auto trimmed_value = ov::util::trim(sv);+ if (trimmed_value == "?" || trimmed_value == "-1") {return;}- std::string min_value_str = val.substr(0, val.find(".."));- min_value_str = ov::util::trim(min_value_str);+ const auto interval_pos = trimmed_value.find("..");+ auto dim_str = trimmed_value.substr(0, interval_pos);- int64_t min_value;- if (min_value_str.empty())- min_value = 0;- else {- OPENVINO_ASSERT(check_all_digits(min_value_str), "Cannot parse min bound: \"" + min_value_str + "\"");- min_value = stringToInt64(min_value_str);- }-- std::string max_value_str = val.substr(val.find("..") + 2);- max_value_str = ov::util::trim(max_value_str);+ const auto no_interval = interval_pos == std::string_view::npos;+ OPENVINO_ASSERT(check_all_digits(dim_str),+ "Cannot parse ",+ (no_interval) ? "dimension: \"" : "min bound: \"",+ dim_str,+ "\"");+ const auto lower = util::view_to_number<value_type>(dim_str).value_or(0);- int64_t max_value;- if (max_value_str.empty())- max_value = Interval::s_max;- else {- OPENVINO_ASSERT(check_all_digits(max_value_str), "Cannot parse max bound: \"" + max_value_str + "\"");- max_value = stringToInt64(max_value_str);+ if (no_interval) {+ m_dimension = Interval(lower);+ } else {+ dim_str = trimmed_value.substr(interval_pos + 2);+ OPENVINO_ASSERT(check_all_digits(dim_str), "Cannot parse max bound: \"", dim_str, "\"");+ const auto upper = util::view_to_number<value_type>(dim_str).value_or(Interval::s_max);+ m_dimension = Interval(lower, upper);}- m_dimension = Interval(min_value, max_value);}std::string Dimension::to_string() const {std::stringstream dim_str_stream;- dim_str_stream << Dimension(m_dimension);+ dim_str_stream << *this;return dim_str_stream.str();}diff --git a/src/core/src/layout.cpp b/src/core/src/layout.cppindex 06b6d2ac2fd..0b1abf8d955 100644--- a/src/core/src/layout.cpp+++ b/src/core/src/layout.cpp@@ -37,7 +37,7 @@ static const std::map<std::string, std::string>& dim_aliases() {return DIM_ALIASES;}-static std::string to_internal_name(const std::string& dim_name) {+static std::string to_internal_name(std::string_view dim_name) {auto name = ov::util::to_upper(dim_name);auto it = dim_aliases().find(name);if (it != dim_aliases().end()) {@@ -46,17 +46,21 @@ static std::string to_internal_name(const std::string& dim_name) {return name;}-static void validate_name(const std::string& dim_name) {+static void validate_name(std::string_view dim_name) {OPENVINO_ASSERT(!dim_name.empty(), "Layout dimension name can't be empty");bool has_alphanumeric = false;for (const auto& c : dim_name) {bool is_alnum = std::isalnum(c);has_alphanumeric |= is_alnum;OPENVINO_ASSERT(is_alnum || c == '_',- "Layout name is invalid (" + dim_name + "). Only english letters, digits and _ is allowed");+ "Layout name is invalid (",+ dim_name,+ "). Only english letters, digits and _ is allowed");}OPENVINO_ASSERT(has_alphanumeric,- "Layout name is invalid (" + dim_name + "). Name shall have alphanumeric characters");+ "Layout name is invalid (",+ dim_name,+ "). Name shall have alphanumeric characters");}Layout::Layout() : m_dynamic(true), m_left_size(0), m_right_size(0) {}@@ -81,11 +85,11 @@ Layout::Layout(const std::string& layout_str) {m_dynamic = false;return;}- auto is_advanced_syntax = [](const std::string& layout) {+ auto is_advanced_syntax = [](const auto& layout) {return layout.length() >= 2 && layout.front() == '[' && layout.back() == ']';};- auto assign_name = [&](const std::string& name, int64_t index) {+ auto assign_name = [&](std::string_view name, int64_t index) {auto dim_name = to_internal_name(name);validate_name(name);OPENVINO_ASSERT(m_names.count(dim_name) == 0,@@ -101,18 +105,18 @@ Layout::Layout(const std::string& layout_str) {std::istringstream ss(sub_name);std::string name;while (std::getline(ss, name, ',')) {- name = ov::util::trim(name);- if (name != "?") {- assign_name(name, index);+ auto trim_name = ov::util::trim(name);+ if (trim_name != "?") {+ assign_name(trim_name, index);}- index++;+ ++index;}return index;};layout = layout.substr(1, layout.length() - 2); // remove []auto ellipsis = layout.find(ELLIPSIS);if (ellipsis == std::string::npos) {- auto last_index = parse_commas(layout);+ auto last_index = parse_commas(static_cast<std::string>(layout));m_dynamic = false;m_left_size = last_index;} else {@@ -121,16 +125,18 @@ Layout::Layout(const std::string& layout_str) {auto left_layout = ov::util::trim(layout.substr(0, ellipsis));if (!left_layout.empty()) {OPENVINO_ASSERT(left_layout.at(left_layout.length() - 1) == ',',- "Layout: Invalid left side (" + layout + ")");+ "Layout: Invalid left side (",+ layout,+ ")");left_layout = left_layout.substr(0, left_layout.length() - 1);- left_index = parse_commas(left_layout);+ left_index = parse_commas(static_cast<std::string>(left_layout));}auto right_layout = ov::util::trim(layout.substr(ellipsis + ELLIPSIS_LEN));if (!right_layout.empty()) {- OPENVINO_ASSERT(right_layout.at(0) == ',', "Layout: Invalid right side (" + layout + ")");+ OPENVINO_ASSERT(right_layout.at(0) == ',', "Layout: Invalid right side (", layout, ")");right_layout = right_layout.substr(1, right_layout.length() - 1);right_index = std::count(right_layout.begin(), right_layout.end(), ',') + 1;- parse_commas(right_layout, -right_index);+ parse_commas(static_cast<std::string>(right_layout), -right_index);}m_dynamic = true;m_left_size = left_index;diff --git a/src/core/src/op/fake_convert.cpp b/src/core/src/op/fake_convert.cppindex 248e0b5e1b8..c13c1df7b63 100644--- a/src/core/src/op/fake_convert.cpp+++ b/src/core/src/op/fake_convert.cpp@@ -9,6 +9,7 @@#include "itt.hpp"#include "openvino/reference/convert.hpp"#include "openvino/reference/fake_convert.hpp"+#include "openvino/util/common_util.hpp"namespace ov::op::v13 {namespace {diff --git a/src/core/src/partial_shape.cpp b/src/core/src/partial_shape.cppindex 2cd52f3d719..1fcab9edac0 100644--- a/src/core/src/partial_shape.cpp+++ b/src/core/src/partial_shape.cpp@@ -28,20 +28,24 @@ ov::PartialShape::PartialShape(const Shape& shape)ov::PartialShape::PartialShape(const std::string& value) {auto val = ov::util::trim(value);- if (val[0] == '[' && val[val.size() - 1] == ']')- val = val.substr(1, val.size() - 2);- val = ov::util::trim(val);- if (val == "...") {- m_rank_is_static = false;- m_dimensions = std::vector<Dimension>();- return;+ if (!val.empty() && val[0] == '[' && val[val.size() - 1] == ']') {+ val.remove_prefix(1);+ val.remove_suffix(1);+ val = ov::util::trim(val);}- m_rank_is_static = true;- std::stringstream ss(val);- std::string field;- while (getline(ss, field, ',')) {- OPENVINO_ASSERT(!field.empty(), "Cannot get vector of dimensions! \"" + value + "\" is incorrect");- m_dimensions.emplace_back(field);++ if (m_rank_is_static = (val != "..."); m_rank_is_static) {+ util::view_transform_if(+ val,+ std::back_inserter(m_dimensions),+ ",",+ [&value](auto&& dim_field) {+ OPENVINO_ASSERT(!dim_field.empty(), "Cannot get vector of dimensions! \"", value, "\" is incorrect");+ return true;+ },+ [](auto&& dim_field) {+ return Dimension{dim_field};+ });}}diff --git a/src/core/src/shape.cpp b/src/core/src/shape.cppindex 349a1311e8e..9323150f735 100644--- a/src/core/src/shape.cpp+++ b/src/core/src/shape.cpp@@ -15,17 +15,6 @@ std::ostream& ov::operator<<(std::ostream& s, const Shape& shape) {return s;}-namespace {-size_t stringToSizeT(const std::string& valStr) {- size_t ret{0};- std::istringstream ss(valStr);- if (!ss.eof()) {- ss >> ret;- }- return ret;-}-} // namespace-ov::Shape::Shape() : std::vector<size_t>() {}ov::Shape::Shape(const std::initializer_list<size_t>& axis_lengths) : std::vector<size_t>(axis_lengths) {}@@ -38,17 +27,23 @@ ov::Shape::Shape(size_t n, size_t initial_value) : std::vector<size_t>(n, initiaov::Shape::Shape(const std::string& value) {auto val = ov::util::trim(value);- if (val[0] == '[' && val[val.size() - 1] == ']')- val = val.substr(1, val.size() - 2);- val = ov::util::trim(val);- std::vector<size_t> dims;- std::stringstream ss(val);- std::string field;- while (getline(ss, field, ',')) {- OPENVINO_ASSERT(!field.empty(), "Cannot get vector of dimensions! \"" + value + "\" is incorrect");- dims.insert(dims.end(), stringToSizeT(field));+ if (!val.empty() && val[0] == '[' && val[val.size() - 1] == ']') {+ val.remove_prefix(1);+ val.remove_suffix(1);+ val = ov::util::trim(val);}- *this = dims;++ util::view_transform_if(+ val,+ std::back_inserter(*this),+ ",",+ [](auto&& dim_field) {+ OPENVINO_ASSERT(!dim_field.empty(), "Cannot get vector of dimensions! \"", dim_field, "\" is incorrect");+ return true;+ },+ [](auto&& dim_field) {+ return util::view_to_number<size_t>(util::trim(dim_field)).value_or(0);+ });}ov::Shape::~Shape() = default;diff --git a/src/core/src/shape_util.cpp b/src/core/src/shape_util.cppindex ed029e794d6..ebfaf602a61 100644--- a/src/core/src/shape_util.cpp+++ b/src/core/src/shape_util.cpp@@ -8,6 +8,7 @@#include "openvino/core/partial_shape.hpp"#include "openvino/core/validation_util.hpp"+#include "openvino/util/common_util.hpp"namespace ov {template <class TContainer, class TAxes>diff --git a/src/core/tests/dimension.cpp b/src/core/tests/dimension.cppindex 098442a2dc7..2259c88dcf4 100644--- a/src/core/tests/dimension.cpp+++ b/src/core/tests/dimension.cpp@@ -7,8 +7,7 @@#include "openvino/core/partial_shape.hpp"#include "openvino/core/symbol.hpp"-using namespace std;-using namespace ov;+namespace ov::test {TEST(dimension, broadcast_merge_static_1_and_10) {Dimension result;@@ -167,3 +166,57 @@ TEST(dimension, dimension_symbolic_equality) {ov::symbol::set_equal(A, D);EXPECT_TRUE(ov::symbol::are_equal(B, C));}++TEST(dimension, from_string_static) {+ Dimension dim("10");+ EXPECT_TRUE(dim.is_static());+ EXPECT_EQ(dim.get_length(), 10);+ EXPECT_EQ(dim.get_min_length(), 10);+ EXPECT_EQ(dim.get_max_length(), 10);+}++TEST(dimension, from_string_dynamic) {+ {+ Dimension dim("?");+ EXPECT_TRUE(dim.is_dynamic());+ EXPECT_EQ(dim.get_min_length(), 0);+ EXPECT_EQ(dim.get_max_length(), -1);+ }+ {+ Dimension dim("-1");+ EXPECT_TRUE(dim.is_dynamic());+ EXPECT_EQ(dim.get_min_length(), 0);+ EXPECT_EQ(dim.get_max_length(), -1);+ }+}++TEST(dimension, from_string_interval) {+ {+ Dimension dim("2..10");+ EXPECT_TRUE(dim.is_dynamic());+ EXPECT_EQ(dim.get_min_length(), 2);+ EXPECT_EQ(dim.get_max_length(), 10);+ }+ {+ Dimension dim("..10");+ EXPECT_TRUE(dim.is_dynamic());+ EXPECT_EQ(dim.get_min_length(), 0);+ EXPECT_EQ(dim.get_max_length(), 10);+ }+ {+ Dimension dim("2..");+ EXPECT_TRUE(dim.is_dynamic());+ EXPECT_EQ(dim.get_min_length(), 2);+ EXPECT_EQ(dim.get_max_length(), -1);+ }+}++TEST(dimension, from_string_interval_invalid) {+ {+ Dimension dim("12..2");+ EXPECT_TRUE(dim.is_dynamic());+ EXPECT_EQ(dim.get_min_length(), -1);+ EXPECT_EQ(dim.get_max_length(), -1);+ }+}+} // namespace ov::testdiff --git a/src/core/xml_util/src/xml_deserialize_util.cpp b/src/core/xml_util/src/xml_deserialize_util.cppindex 474e395c606..50176e3c842 100644--- a/src/core/xml_util/src/xml_deserialize_util.cpp+++ b/src/core/xml_util/src/xml_deserialize_util.cpp@@ -81,14 +81,6 @@ bool get_partial_shape_from_attribute(const pugi::xml_node& node, const std::strreturn true;}-bool get_dimension_from_attribute(const pugi::xml_node& node, const std::string& name, Dimension& value) {- std::string param;- if (!getStrAttribute(node, name, param))- return false;- value = Dimension(param);- return true;-}-void str_to_set_of_strings(const std::string& value, std::set<std::string>& res) {std::stringstream ss(value);std::string field;@@ -750,10 +742,9 @@ void XmlDeserializer::on_adapter(const std::string& name, ov::ValueAccessor<voidreturn;a->set(shape);} else if (auto a = ov::as_type<ov::AttributeAdapter<Dimension>>(&adapter)) {- Dimension dim;- if (!get_dimension_from_attribute(m_node.child("data"), name, dim))- return;- a->set(dim);+ if (const auto dim_str = util::pugixml::get_attribute_view(m_node.child("data"), name); dim_str.has_value()) {+ a->set(Dimension(*dim_str));+ }} else if (auto a = ov::as_type<ov::AttributeAdapter<ov::Shape>>(&adapter)) {std::vector<size_t> shape;if (!getParameters<size_t>(m_node.child("data"), name, shape))diff --git a/src/frontends/ir/src/utils.cpp b/src/frontends/ir/src/utils.cppindex 6e740da6df7..bec1c547f25 100644--- a/src/frontends/ir/src/utils.cpp+++ b/src/frontends/ir/src/utils.cpp@@ -10,7 +10,8 @@namespace ov {void operator>>(const std::stringstream& in, ov::element::Type& type) {- type = ov::element::Type(ov::util::trim(in.str()));+ const std::string type_name{util::trim(in.str())};+ type = element::Type(type_name);}} // namespace ovdiff --git a/src/inference/src/shared_context_manager.cpp b/src/inference/src/shared_context_manager.cppindex eb56a19ac6a..bcf6e961b1b 100644--- a/src/inference/src/shared_context_manager.cpp+++ b/src/inference/src/shared_context_manager.cpp@@ -5,6 +5,7 @@#include "shared_context_manager.hpp"#include "openvino/runtime/icache_manager.hpp"+#include "openvino/util/common_util.hpp"namespace ov {@@ -34,12 +35,8 @@ void SharedContextManager::set_context(uint64_t id, std::weak_ptr<ov::wsh::Conte}void SharedContextManager::erase_expired() {- for (auto it = m_weight_contexts.begin(); it != m_weight_contexts.end();) {- if (it->second.expired()) {- it = m_weight_contexts.erase(it);- } else {- ++it;- }- }+ util::erase_if(m_weight_contexts, [](const auto& ctx_entry) {+ return ctx_entry.second.expired();+ });}} // namespace ovdiff --git a/src/plugins/intel_cpu/src/utils/debug_caps_config.h b/src/plugins/intel_cpu/src/utils/debug_caps_config.hindex 939ccfd5a4d..d50047b9075 100644--- a/src/plugins/intel_cpu/src/utils/debug_caps_config.h+++ b/src/plugins/intel_cpu/src/utils/debug_caps_config.h@@ -90,7 +90,7 @@ public:virtual ~PropertyGroup() = default;void parseAndSet(const std::string& str) {- const auto& options = ov::util::split(str, ' ');+ const auto& options = ov::util::split(str, " ");const auto& propertySetters = getPropertySetters();bool failed = false;auto getHelp = [propertySetters]() {@@ -106,7 +106,7 @@ public:if (option.empty()) {continue;}- const auto& parts = ov::util::split(option, '=');+ const auto& parts = ov::util::split(option, "=");if (parts.size() > 2) {failed = true;break;@@ -118,7 +118,7 @@ public:return setter->getPropertyName() == propertyName;});if (foundSetter == propertySetters.end() ||- !(*foundSetter)->parseAndSet(parts.size() == 1 ? "" : parts.back())) {+ !(*foundSetter)->parseAndSet(parts.size() == 1 ? "" : std::string(parts.back()))) {failed = true;break;}@@ -210,7 +210,7 @@ private:bool parseAndSet(const std::string& str) override {const auto& tokens =- str.empty() ? std::vector<std::string>{"all"} : ov::util::split(ov::util::to_lower(str), ',');+ str.empty() ? std::vector<std::string_view>{"all"} : ov::util::split(ov::util::to_lower(str), ",");property.reset();for (const auto& token : tokens) {const bool tokenVal = (token.front() != '-');diff --git a/src/plugins/intel_gpu/src/graph/program.cpp b/src/plugins/intel_gpu/src/graph/program.cppindex d783140eecc..a822866b82c 100644--- a/src/plugins/intel_gpu/src/graph/program.cpp+++ b/src/plugins/intel_gpu/src/graph/program.cpp@@ -8,7 +8,6 @@#include "openvino/core/type.hpp"#include "openvino/runtime/system_conf.hpp"#include "openvino/runtime/threading/cpu_streams_info.hpp"-#include "openvino/util/weights_path.hpp"#include "openvino/util/file_util.hpp"#include "intel_gpu/runtime/memory.hpp"@@ -1970,7 +1969,6 @@ void program::load(cldnn::BinaryInputBuffer& ib,weights_memory = std::make_shared<WeightsMemory>(model_ptr);}} else if (!weights_path.empty()) {- ov::util::validate_weights_path(weights_path);weights_memory = std::make_shared<WeightsMemory>(ov::load_mmap_object(ov::util::make_path(weights_path)));} else {OPENVINO_THROW("Weights path or model is required for cache mode OPTIMIZE_SIZE");diff --git a/src/plugins/intel_gpu/src/plugin/compiled_model.cpp b/src/plugins/intel_gpu/src/plugin/compiled_model.cppindex 4cfc59ccd6a..fce3963fd3f 100644--- a/src/plugins/intel_gpu/src/plugin/compiled_model.cpp+++ b/src/plugins/intel_gpu/src/plugin/compiled_model.cpp@@ -6,7 +6,6 @@#include "openvino/runtime/intel_gpu/properties.hpp"#include "openvino/runtime/internal_properties.hpp"#include "openvino/runtime/plugin_config.hpp"-#include "openvino/util/weights_path.hpp"#include "intel_gpu/graph/serialization/binary_buffer.hpp"#include "intel_gpu/runtime/itt.hpp"diff --git a/src/plugins/intel_gpu/src/plugin/plugin.cpp b/src/plugins/intel_gpu/src/plugin/plugin.cppindex dfee4d4c19e..d79702e484e 100644--- a/src/plugins/intel_gpu/src/plugin/plugin.cpp+++ b/src/plugins/intel_gpu/src/plugin/plugin.cpp@@ -41,7 +41,6 @@#include "common_utils/parallel_mem_streambuf.hpp"#include "openvino/runtime/weightless_properties_utils.hpp"#include "openvino/util/file_util.hpp"-#include "openvino/util/weights_path.hpp"#include "transformations/common_optimizations/dimension_tracking.hpp"#include "transformations/init_node_info.hpp"#include "transformations/rt_info/fused_names_attribute.hpp"@@ -173,9 +172,9 @@ std::shared_ptr<ov::Model> Plugin::clone_and_transform_model(const std::shared_p// Set weightless cache attribute only for non IR (e.g. onnxruntime) models// This is a temporary solution. A common way of handling weightless caching will be defined later.if (config_copy.get_enable_weightless()) {- const std::string& weights_path = config.get_weights_path();+ const auto weight_path = ov::util::make_path(config.get_weights_path());- if (!ov::util::validate_weights_path(weights_path) && !is_weightless_cache_attributes_set(cloned_model))+ if (weight_path.extension() != ".bin" && !is_weightless_cache_attributes_set(cloned_model))set_weightless_cache_attributes(cloned_model);}@@ -427,9 +426,9 @@ std::shared_ptr<ov::ICompiledModel> Plugin::import_model(std::istream& model,}if (ov::util::is_weightless_enabled(config.get_user_properties()).value_or(false)) {- const std::string& weights_path = config.get_weights_path();+ const auto& weights_path = ov::util::make_path(config.get_weights_path());- if (!ov::util::validate_weights_path(weights_path)) {+ if (weights_path.extension() != ".bin") {// This is non IR case, e.g. onnxruntime.// This may not be required. Constant nodes should have the information already.// This is a temporary solution. A more robust solution will be implemented in future.diff --git a/src/plugins/intel_npu/tests/functional/behavior/ov_plugin/internal_properties_tests.cpp b/src/plugins/intel_npu/tests/functional/behavior/ov_plugin/internal_properties_tests.cppindex bd376c22c84..8f91e9ace98 100644--- a/src/plugins/intel_npu/tests/functional/behavior/ov_plugin/internal_properties_tests.cpp+++ b/src/plugins/intel_npu/tests/functional/behavior/ov_plugin/internal_properties_tests.cpp@@ -1,5 +1,4 @@-//-// Copyright (C) Intel Corporation+// Copyright (C) 2018-2026 Intel Corporation// SPDX-License-Identifier: Apache-2.0//@@ -18,7 +17,7 @@ std::string OVPropertiesTestsNPU::getTestCaseName(const testing::TestParamInfo<Pstd::ostringstream result;result << "target_device=" << target_device << "_";if (!properties.empty()) {- result << "properties=" << util::join(util::split(util::to_string(properties), ' '), "_");+ result << "properties=" << util::join(util::split(util::to_string(properties), " "), "_");}return result.str();}@@ -46,7 +45,7 @@ std::string OVPropertiesTestsWithCompileModelPropsNPU::getTestCaseName(std::ostringstream result;result << "target_device=" << target_device << "_";if (!properties.empty()) {- result << "properties=" << util::join(util::split(util::to_string(properties), ' '), "_");+ result << "properties=" << util::join(util::split(util::to_string(properties), " "), "_");}return result.str();}diff --git a/src/plugins/intel_npu/tests/functional/behavior/ov_plugin/internal_properties_tests.hpp b/src/plugins/intel_npu/tests/functional/behavior/ov_plugin/internal_properties_tests.hppindex dd087baaf67..7415d457474 100644--- a/src/plugins/intel_npu/tests/functional/behavior/ov_plugin/internal_properties_tests.hpp+++ b/src/plugins/intel_npu/tests/functional/behavior/ov_plugin/internal_properties_tests.hpp@@ -1,4 +1,3 @@-//// Copyright (C) 2018-2026 Intel Corporation// SPDX-License-Identifier: Apache-2.0//diff --git a/src/plugins/proxy/src/plugin.cpp b/src/plugins/proxy/src/plugin.cppindex 535e494f2d0..711703b7a3a 100644--- a/src/plugins/proxy/src/plugin.cpp+++ b/src/plugins/proxy/src/plugin.cpp@@ -51,13 +51,6 @@ bool compare_containers(const std::unordered_set<std::string>& c1, const std::unreturn true;}-size_t string_to_size_t(const std::string& s) {- std::stringstream sstream(s);- size_t idx;- sstream >> idx;- return idx;-}-bool is_device_in_config(const ov::AnyMap& config) {return config.find(ov::device::id.name()) != config.end();}@@ -200,10 +193,12 @@ void ov::proxy::Plugin::set_property(const ov::AnyMap& properties) {// Biggest number means minimum prioritysize_t min_priority(0);for (auto&& dev_priority : it->second.as<std::vector<std::string>>()) {- auto dev_prior = ov::util::split(dev_priority, ':');+ auto dev_prior = ov::util::split(dev_priority, ":");OPENVINO_ASSERT(dev_prior.size() == 2,"Cannot set ov::proxy::device_priorities property. Format is incorrect.");- auto priority = string_to_size_t(dev_prior[1]);+ const auto priority_opt = util::view_to_number<size_t>(dev_prior[1]);+ OPENVINO_ASSERT(priority_opt, "Cannot parse ov::proxy::device_priorities value from: ", dev_prior[1]);+ const auto priority = *priority_opt;if (priority > min_priority)min_priority = priority;priority_order.push_back(std::pair<std::string, size_t>{dev_prior[0], priority});@@ -587,7 +582,7 @@ std::vector<std::vector<std::string>> ov::proxy::Plugin::get_hidden_devices() co// Add fallback devices use device_id for individual fallback propertyauto fallback = get_internal_property(ov::device::priorities.name(), device_id).as<std::string>();if (!fallback.empty()) {- for (const auto& fallback_dev : ov::util::split(fallback, ' ')) {+ for (const auto& fallback_dev : ov::util::split(fallback, " ")) {if (fallback_dev != device)devices.emplace_back(fallback_dev);elsediff --git a/src/tests/functional/base_func_tests/src/behavior/compiled_model/properties.cpp b/src/tests/functional/base_func_tests/src/behavior/compiled_model/properties.cppindex b653da0b6be..fd2585a0bff 100644--- a/src/tests/functional/base_func_tests/src/behavior/compiled_model/properties.cpp+++ b/src/tests/functional/base_func_tests/src/behavior/compiled_model/properties.cpp@@ -34,7 +34,7 @@ std::string OVClassCompiledModelPropertiesTests::getTestCaseName(testing::TestPastd::ostringstream result;result << "targetDevice=" << targetDevice << "_";if (!properties.empty()) {- result << "properties=" << util::join(util::split(util::to_string(properties), ' '), "_");+ result << "properties=" << util::join(util::split(util::to_string(properties), " "), "_");}return result.str();}@@ -62,7 +62,7 @@ std::string OVCompileModelGetExecutionDeviceTests::getTestCaseName(testing::Teststd::ostringstream result;result << "device_name=" << target_device << "_";if (!compileModelProperties.empty()) {- result << "_compileModelProp=" << util::join(util::split(util::to_string(compileModelProperties), ' '), "_");+ result << "_compileModelProp=" << util::join(util::split(util::to_string(compileModelProperties), " "), "_");}result << "_expectedDevice=" << userConfig.second;return result.str();@@ -488,7 +488,7 @@ TEST_P(OVClassCompiledModelGetPropertyTest_EXEC_DEVICES, CanGetExecutionDeviceInTEST_P(OVCompileModelGetExecutionDeviceTests, CanGetExecutionDeviceInfo) {ov::CompiledModel exeNetWork;auto deviceList = core->get_available_devices();- std::vector<std::string> expected_devices = util::split(expectedDeviceName, ',');+ const auto expected_devices = util::split(expectedDeviceName);std::vector<std::string> updatedExpectDevices;updatedExpectDevices.assign(expected_devices.begin(), expected_devices.end());for (auto& iter : compileModelProperties) {diff --git a/src/tests/functional/base_func_tests/src/behavior/ov_plugin/caching_tests.cpp b/src/tests/functional/base_func_tests/src/behavior/ov_plugin/caching_tests.cppindex 45eaa4e013c..43677e7f11a 100644--- a/src/tests/functional/base_func_tests/src/behavior/ov_plugin/caching_tests.cpp+++ b/src/tests/functional/base_func_tests/src/behavior/ov_plugin/caching_tests.cpp@@ -766,7 +766,7 @@ std::string CompiledKernelsCacheTest::getTestCaseName(testing::TestParamInfo<comstd::ostringstream result;result << "device_name=" << deviceName << "_";if (!properties.empty()) {- result << "properties=" << util::join(util::split(util::to_string(properties), ' '), "_");+ result << "properties=" << util::join(util::split(util::to_string(properties), " "), "_");}result << userConfig.second;return result.str();diff --git a/src/tests/functional/base_func_tests/src/behavior/ov_plugin/properties_tests.cpp b/src/tests/functional/base_func_tests/src/behavior/ov_plugin/properties_tests.cppindex 2458d014f91..45da5befad6 100644--- a/src/tests/functional/base_func_tests/src/behavior/ov_plugin/properties_tests.cpp+++ b/src/tests/functional/base_func_tests/src/behavior/ov_plugin/properties_tests.cpp@@ -19,7 +19,7 @@ std::string OVPropertiesTests::getTestCaseName(testing::TestParamInfo<Propertiesstd::ostringstream result;result << "target_device=" << target_device << "_";if (!properties.empty()) {- result << "properties=" << util::join(util::split(util::to_string(properties), ' '), "_");+ result << "properties=" << util::join(util::split(util::to_string(properties), " "), "_");}return result.str();}@@ -45,10 +45,10 @@ std::string OVSetPropComplieModleGetPropTests::getTestCaseName(testing::TestParastd::ostringstream result;result << "target_device=" << target_device << "_";if (!properties.empty()) {- result << "properties=" << util::join(util::split(util::to_string(properties), ' '), "_");+ result << "properties=" << util::join(util::split(util::to_string(properties), " "), "_");}if (!compileModelProperties.empty()) {- result << "_compileModelProp=" << util::join(util::split(util::to_string(compileModelProperties), ' '), "_");+ result << "_compileModelProp=" << util::join(util::split(util::to_string(compileModelProperties), " "), "_");}return result.str();}@@ -66,7 +66,7 @@ std::string OVPropertiesTestsWithCompileModelProps::getTestCaseName(testing::Tesstd::ostringstream result;result << "target_device=" << target_device << "_";if (!properties.empty()) {- result << "properties=" << util::join(util::split(util::to_string(properties), ' '), "_");+ result << "properties=" << util::join(util::split(util::to_string(properties), " "), "_");}return result.str();}diff --git a/src/tests/functional/plugin/shared/src/low_precision_transformations/eliminate_fake_quantize_transformation.cpp b/src/tests/functional/plugin/shared/src/low_precision_transformations/eliminate_fake_quantize_transformation.cppindex 5388b4ff5c6..d857322df83 100644--- a/src/tests/functional/plugin/shared/src/low_precision_transformations/eliminate_fake_quantize_transformation.cpp+++ b/src/tests/functional/plugin/shared/src/low_precision_transformations/eliminate_fake_quantize_transformation.cpp@@ -61,8 +61,9 @@ TEST_P(EliminateFakeQuantizeTransformation, CompareWithRefImpl) {const auto& nameIt = it.second.find("originalLayersNames");const auto& fused_name = nameIt->second.as<std::string>();- const auto names = ov::util::split(fused_name, ',', true);- for (const auto& name : names) {+ const auto names = ov::util::split(fused_name, ",");+ for (const auto& not_trimmed_name : names) {+ const auto name = std::string(ov::util::trim(not_trimmed_name));ASSERT_TRUE(absent.find(name) == absent.end());exist.erase(name);}diff --git a/src/tests/test_utils/common_test_utils/tests/common_util_test.cpp b/src/tests/test_utils/common_test_utils/tests/common_util_test.cppnew file mode 100644index 00000000000..b80a2ec61c4--- /dev/null+++ b/src/tests/test_utils/common_test_utils/tests/common_util_test.cpp@@ -0,0 +1,177 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include <gmock/gmock.h>++#include "common_test_utils/common_utils.hpp"+#include "openvino/util/common_util.hpp"+namespace ov::test {++using CommonUtilsTest = testing::Test;++TEST_F(CommonUtilsTest, ltrim) {+ EXPECT_EQ("space test", util::ltrim(" space test"));+ EXPECT_EQ("tab,linefeed test", util::ltrim("\t\ntab,linefeed test"));+ EXPECT_EQ("", util::ltrim(""));+ EXPECT_EQ("", util::ltrim(" \r "));+ EXPECT_EQ("carriage test ", util::ltrim("\rcarriage test "));+ EXPECT_EQ("vertical tab test ", util::ltrim("\v vertical tab test "));+}++TEST_F(CommonUtilsTest, rtrim) {+ EXPECT_EQ("space test", util::rtrim("space test "));+ EXPECT_EQ("\ttab,linefeed test", util::rtrim("\ttab,linefeed test\t\n"));+ EXPECT_EQ("", util::rtrim(""));+ EXPECT_EQ("", util::rtrim(" \r "));+ EXPECT_EQ(" carriage test", util::rtrim(" carriage test \r"));+ EXPECT_EQ("\v vertical tab test", util::rtrim("\v vertical tab test \v"));+}++TEST_F(CommonUtilsTest, trim) {+ EXPECT_EQ("space test", util::trim(" space test "));+ EXPECT_EQ("tab,linefeed test", util::trim("\t\ntab,linefeed test\t\n"));+ EXPECT_EQ("", util::trim(""));+ EXPECT_EQ("", util::trim(" \r "));+ EXPECT_EQ("carriage test", util::trim("\rcarriage test \r"));+ EXPECT_EQ("vertical tab test", util::trim("\v vertical tab test \v"));+}++TEST_F(CommonUtilsTest, parse_views_into_container_empty_fields) {+ std::vector<std::string_view> res;+ util::view_transform(" 1, , 2, 3", std::back_inserter(res), ",");+ EXPECT_EQ((std::vector<std::string_view>{" 1"," ", " 2", " 3"}), res);+}++TEST_F(CommonUtilsTest, parse_views_into_container_trailing_separator) {+ std::vector<std::string_view> res;+ util::view_transform("1,2,", std::back_inserter(res), ",");+ EXPECT_EQ((std::vector<std::string_view>{"1", "2", ""}), res);+}++TEST_F(CommonUtilsTest, parse_views_into_container_empty_input) {+ std::vector<std::string_view> res;+ util::view_transform("", std::back_inserter(res), ",");+ EXPECT_TRUE(res.empty());+}++TEST_F(CommonUtilsTest, parse_views_into_container_custom_check) {+ std::vector<std::string_view> res;+ util::view_transform_if(" 1,;2,; 3,; ", std::back_inserter(res), ",;", [](auto&& field) {+ OPENVINO_ASSERT(!field.empty(), "Cannot get vector of fields! \" 1,;2,; 3,; \" is incorrect");+ return true;+ });+ EXPECT_EQ((std::vector<std::string_view>{" 1", "2", " 3", " "}), res);+}++TEST_F(CommonUtilsTest, parse_views_into_container_custom_check_fail) {+ std::vector<std::string> res;+ EXPECT_THROW(util::view_transform_if(" 1,, 2, 3, ", std::back_inserter(res), ",", [](auto&& field) {+ OPENVINO_ASSERT(!field.empty(), "Cannot get vector of fields! \" 1, , 2, 3, \" is incorrect");+ return true;+ }, [](auto&& field) {+ return std::string{field};+ } ),+ ov::AssertFailure);+}++TEST_F(CommonUtilsTest, parse_views_into_container_arithmetic) {+ std::vector<int> res{5,5,5};+ util::view_transform("1,2,3", std::back_inserter(res), ",",+ [](auto&& field) { return util::view_to_number<int>(field).value_or(0); });+ EXPECT_EQ((std::vector<int>{5,5,5,1, 2, 3}), res);+}++TEST_F(CommonUtilsTest, parse_views_into_container_arithmetic_fail) {+ std::vector<int> res(3);+ ASSERT_NO_THROW(util::view_transform("1, a, 3 ", res.begin(),",",+ [](auto&& field) { return util::view_to_number<int>(field).value_or(0); }));+ EXPECT_EQ((std::vector<int>{1, 0, 0}), res);+}++TEST_F(CommonUtilsTest, parse_views_into_container_arithmetic_custom_check_fail) {+ std::vector<int> res;+ EXPECT_THROW(util::view_transform("1,,3", std::back_inserter(res), ",", [](auto&& field) {+ OPENVINO_ASSERT(!field.empty(), "Cannot get vector of fields! \" 1, a, 3 \" is incorrect");+ return true;+ }),+ ov::AssertFailure);+}++TEST_F(CommonUtilsTest, split_to_views_default_separator) {+ EXPECT_EQ((std::vector<std::string_view>{"1", "2", "3"}), util::split("1,2,3"));+}++TEST_F(CommonUtilsTest, split_to_views_custom_separator) {+ EXPECT_EQ((std::vector<std::string_view>{"1", "2", "3"}), util::split("1;2;3", ";"));+}++TEST_F(CommonUtilsTest, split_to_views_custom_check) {+ EXPECT_EQ((std::vector<std::string_view>{"1", "2", "3"}),+ util::split("1;2;3", ";", [](auto&& field) {+ OPENVINO_ASSERT(!field.empty(), "Cannot get vector of fields! \" 1;2;3 \" is incorrect");+ return true;+ }));+}++TEST_F(CommonUtilsTest, split_to_views_custom_check_fail) {+ EXPECT_THROW(util::split(+ "1;;3",+ ";",+ [](auto&& field) {+ OPENVINO_ASSERT(!field.empty(), "Cannot get vector of fields! \" 1;;3 \" is incorrect");+ return true;+ }),+ ov::AssertFailure);+}++TEST_F(CommonUtilsTest, split_to_views_lower) {+ const std::string test_str{"Test1,Test2,Test3"};+ EXPECT_EQ((std::vector<std::string_view>{"test1", "test2", "test3"}), util::split(util::to_lower(test_str)));+}++TEST_F(CommonUtilsTest, split_empty_strings) {+ using testing::ElementsAre;+ EXPECT_THAT(util::split(""), testing::IsEmpty());+ EXPECT_THAT(util::split(","), ElementsAre("", ""));+ EXPECT_THAT(util::split(",,"), ElementsAre("", "", ""));+ EXPECT_THAT(util::split("test,"), ElementsAre("test", ""));+ EXPECT_THAT(util::split(",test"), ElementsAre("", "test"));+}++TEST_F(CommonUtilsTest, view_to_integral_number){+ EXPECT_EQ(123, util::view_to_number<int>("123").value());+ EXPECT_EQ(-123, util::view_to_number<int>("-123").value());+ EXPECT_EQ(123, util::view_to_number<int>("123abc").value());+}++TEST_F(CommonUtilsTest, view_to_number_invalid_input){+ EXPECT_FALSE(util::view_to_number<int>("abc").has_value());+ EXPECT_FALSE(util::view_to_number<int>("").has_value());++ EXPECT_FALSE(util::view_to_number<float>("abc").has_value());+ EXPECT_FALSE(util::view_to_number<float>("").has_value());++ EXPECT_FALSE(util::view_to_number<double>("abc").has_value());+ EXPECT_FALSE(util::view_to_number<double>("").has_value());++ EXPECT_FALSE(util::view_to_number<long double>("abc").has_value());+ EXPECT_FALSE(util::view_to_number<long double>("").has_value());+}++TEST_F(CommonUtilsTest, view_to_floating_point_number){+ EXPECT_FLOAT_EQ(123.456f, util::view_to_number<float>("123.456").value());+ EXPECT_DOUBLE_EQ(123.456, util::view_to_number<double>("123.456").value());+ EXPECT_DOUBLE_EQ(-123.456, util::view_to_number<double>("-123.456").value());+}++TEST_F(CommonUtilsTest, ends_with) {+ EXPECT_TRUE(util::ends_with("test.cpp", ".cpp"));+ EXPECT_TRUE(util::ends_with("test.cpp", "cpp"));+ EXPECT_TRUE(util::ends_with("test.cpp", ""));+ EXPECT_FALSE(util::ends_with("test.cpp", ".h"));+ EXPECT_FALSE(util::ends_with("test.cpp", "cpp "));+ EXPECT_FALSE(util::ends_with("d", ".cpp"));+ EXPECT_FALSE(util::ends_with("test.bin.bak", ".bin"));+}+} // namespace ov::test