@@ -1440,8 +1440,11 @@ std::optional<uint32_t> ParseKeyPathNum(std::span<const char> elem, bool& apostr
14401440[[nodiscard]] bool ParseKeyPath (const std::vector<std::span<const char >>& split, std::vector<KeyPath>& out, bool & apostrophe, std::string& error, bool allow_multipath)
14411441{
14421442 KeyPath path;
1443- std::optional<size_t > multipath_segment_index;
1444- std::vector<uint32_t > multipath_values;
1443+ struct MultipathSubstitutes {
1444+ size_t placeholder_index;
1445+ std::vector<uint32_t > values;
1446+ };
1447+ std::optional<MultipathSubstitutes> substitutes;
14451448
14461449 for (size_t i = 1 ; i < split.size (); ++i) {
14471450 const std::span<const char >& elem = split[i];
@@ -1452,7 +1455,7 @@ std::optional<uint32_t> ParseKeyPathNum(std::span<const char> elem, bool& apostr
14521455 error = strprintf (" Key path value '%s' specifies multipath in a section where multipath is not allowed" , std::string (elem.begin (), elem.end ()));
14531456 return false ;
14541457 }
1455- if (multipath_segment_index ) {
1458+ if (substitutes ) {
14561459 error = " Multiple multipath key path specifiers found" ;
14571460 return false ;
14581461 }
@@ -1464,6 +1467,7 @@ std::optional<uint32_t> ParseKeyPathNum(std::span<const char> elem, bool& apostr
14641467 return false ;
14651468 }
14661469
1470+ substitutes.emplace ();
14671471 std::unordered_set<uint32_t > seen_substitutes;
14681472 for (const auto & num : nums) {
14691473 const auto & op_num = ParseKeyPathNum (num, apostrophe, error);
@@ -1473,25 +1477,25 @@ std::optional<uint32_t> ParseKeyPathNum(std::span<const char> elem, bool& apostr
14731477 error = strprintf (" Duplicated key path value %u in multipath specifier" , *op_num);
14741478 return false ;
14751479 }
1476- multipath_values .emplace_back (*op_num);
1480+ substitutes-> values .emplace_back (*op_num);
14771481 }
14781482
14791483 path.emplace_back (); // Placeholder for multipath segment
1480- multipath_segment_index = path.size ()- 1 ;
1484+ substitutes-> placeholder_index = path.size () - 1 ;
14811485 } else {
14821486 const auto & op_num = ParseKeyPathNum (elem, apostrophe, error);
14831487 if (!op_num) return false ;
14841488 path.emplace_back (*op_num);
14851489 }
14861490 }
14871491
1488- if (!multipath_segment_index ) {
1492+ if (!substitutes ) {
14891493 out.emplace_back (std::move (path));
14901494 } else {
14911495 // Replace the multipath placeholder with each value while generating paths
1492- for (uint32_t substitute : multipath_values ) {
1496+ for (uint32_t substitute : substitutes-> values ) {
14931497 KeyPath branch_path = path;
1494- branch_path[*multipath_segment_index ] = substitute;
1498+ branch_path[substitutes-> placeholder_index ] = substitute;
14951499 out.emplace_back (std::move (branch_path));
14961500 }
14971501 }
0 commit comments