From ffd1c68d812eb1777914968dd67a522cf0c78e3a Mon Sep 17 00:00:00 2001 From: wxnzb <3127484862@qq.com> Date: Sat, 11 Jan 2025 19:07:17 +0800 Subject: [PATCH 1/4] variable-length arguments in configuration --- src/config.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config.cc b/src/config.cc index 9d8891f9..37190fa9 100644 --- a/src/config.cc +++ b/src/config.cc @@ -74,8 +74,8 @@ Status StringValue::SetValue(const std::string& value) { Status StringValueArray::SetValue(const std::string& value) { auto values = SplitString(value, delimiter_); if (!values_.empty()) { // if the value_ is not empty, check the number of parameters - if (values.size() != values_.size()) { - return Status::InvalidArgument("The number of parameters does not match."); + if (values.size() < values_.size()) { + return Status::InvalidArgument("The number of parameters is less than required."); } } else { // if the value_ is empty, resize the value_ to the size of the values values_.resize(values.size()); From 3e2f46acde6c70e6c21007e6a663326570b01130 Mon Sep 17 00:00:00 2001 From: wxnzb <3127484862@qq.com> Date: Sat, 18 Jan 2025 20:16:50 +0800 Subject: [PATCH 2/4] variable-length-configuration --- src/config.cc | 23 +++++++++++++---------- src/config.h | 3 ++- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/config.cc b/src/config.cc index 37190fa9..a23fe758 100644 --- a/src/config.cc +++ b/src/config.cc @@ -71,18 +71,21 @@ Status StringValue::SetValue(const std::string& value) { return Status::OK(); } -Status StringValueArray::SetValue(const std::string& value) { +Status StringValueArray::SetValue(const std::string& value) { return SetValue(value, false); } + +Status StringValueArray::SetValue(const std::string& value, bool check) { auto values = SplitString(value, delimiter_); - if (!values_.empty()) { // if the value_ is not empty, check the number of parameters - if (values.size() < values_.size()) { - return Status::InvalidArgument("The number of parameters is less than required."); + if (check) { + if (values.size() != values_.size()) { + return Status::InvalidArgument("The number of parameters does not match."); + } + } else { + if (values_.empty()) { + values_.resize(values.size()); + } + for (size_t i = 0; i < values.size(); i++) { + values_[i] = std::move(values[i]); } - } else { // if the value_ is empty, resize the value_ to the size of the values - values_.resize(values.size()); - } - - for (int i = 0; i < values.size(); i++) { - values_[i] = std::move(values[i]); } return Status::OK(); } diff --git a/src/config.h b/src/config.h index dad56b87..96b5256a 100644 --- a/src/config.h +++ b/src/config.h @@ -84,9 +84,10 @@ class StringValueArray : public BaseValue { std::string Value() const override { return pstd::StringConcat(values_, delimiter_); }; + Status SetValue(const std::string& value, bool check); + private: Status SetValue(const std::string& value) override; - std::vector values_; char delimiter_ = 0; }; From 2ab8978063cec1f9c6b68a7a5598e526df1ef3dd Mon Sep 17 00:00:00 2001 From: wxnzb <3127484862@qq.com> Date: Sat, 18 Jan 2025 20:22:23 +0800 Subject: [PATCH 3/4] variable-length-configuration --- src/config.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.cc b/src/config.cc index a23fe758..e7f967ff 100644 --- a/src/config.cc +++ b/src/config.cc @@ -81,7 +81,7 @@ Status StringValueArray::SetValue(const std::string& value, bool check) { } } else { if (values_.empty()) { - values_.resize(values.size()); + values_.resize(values.size()); } for (size_t i = 0; i < values.size(); i++) { values_[i] = std::move(values[i]); From e3862a6caeff10238a562e0e9a10349f8ca7f663 Mon Sep 17 00:00:00 2001 From: wxnzb <3127484862@qq.com> Date: Sat, 18 Jan 2025 20:44:31 +0800 Subject: [PATCH 4/4] variable-length-configuration --- src/config.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.cc b/src/config.cc index e7f967ff..3d78379c 100644 --- a/src/config.cc +++ b/src/config.cc @@ -80,7 +80,7 @@ Status StringValueArray::SetValue(const std::string& value, bool check) { return Status::InvalidArgument("The number of parameters does not match."); } } else { - if (values_.empty()) { + if (values.size() != values_.size()) { values_.resize(values.size()); } for (size_t i = 0; i < values.size(); i++) {