diff options
author | monster <monster@ydb.tech> | 2022-07-07 14:41:37 +0300 |
---|---|---|
committer | monster <monster@ydb.tech> | 2022-07-07 14:41:37 +0300 |
commit | 06e5c21a835c0e923506c4ff27929f34e00761c2 (patch) | |
tree | 75efcbc6854ef9bd476eb8bf00cc5c900da436a2 /library/cpp/string_utils/parse_vector/vector_parser.h | |
parent | 03f024c4412e3aa613bb543cf1660176320ba8f4 (diff) | |
download | ydb-06e5c21a835c0e923506c4ff27929f34e00761c2.tar.gz |
fix ya.make
Diffstat (limited to 'library/cpp/string_utils/parse_vector/vector_parser.h')
-rw-r--r-- | library/cpp/string_utils/parse_vector/vector_parser.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/library/cpp/string_utils/parse_vector/vector_parser.h b/library/cpp/string_utils/parse_vector/vector_parser.h new file mode 100644 index 0000000000..5a861e5c32 --- /dev/null +++ b/library/cpp/string_utils/parse_vector/vector_parser.h @@ -0,0 +1,22 @@ +#pragma once + +#include <util/generic/vector.h> +#include <util/string/split.h> +#include <util/string/strip.h> + +//! Converts string to vector of type T variables +template <typename T, typename TStringType, typename TDelim = char> +bool TryParseStringToVector(const TStringType& input, TVector<T>& result, const TDelim delim = ',', const bool useEmpty = true) { + T currentValue; + for (const auto& t : StringSplitter(input).Split(delim)) { + auto sb = StripString(t.Token()); + if (!useEmpty && !sb) { + continue; + } + if (!TryFromString<T>(sb, currentValue)) { + return false; + } + result.push_back(currentValue); + } + return true; +} |