@@ -1440,8 +1440,11 @@ std::optional<uint32_t> ParseKeyPathNum(std::span<const char> elem, bool& apostr
1440
1440
[[nodiscard]] bool ParseKeyPath (const std::vector<std::span<const char >>& split, std::vector<KeyPath>& out, bool & apostrophe, std::string& error, bool allow_multipath)
1441
1441
{
1442
1442
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;
1445
1448
1446
1449
for (size_t i = 1 ; i < split.size (); ++i) {
1447
1450
const std::span<const char >& elem = split[i];
@@ -1452,7 +1455,7 @@ std::optional<uint32_t> ParseKeyPathNum(std::span<const char> elem, bool& apostr
1452
1455
error = strprintf (" Key path value '%s' specifies multipath in a section where multipath is not allowed" , std::string (elem.begin (), elem.end ()));
1453
1456
return false ;
1454
1457
}
1455
- if (multipath_segment_index ) {
1458
+ if (substitutes ) {
1456
1459
error = " Multiple multipath key path specifiers found" ;
1457
1460
return false ;
1458
1461
}
@@ -1464,6 +1467,7 @@ std::optional<uint32_t> ParseKeyPathNum(std::span<const char> elem, bool& apostr
1464
1467
return false ;
1465
1468
}
1466
1469
1470
+ substitutes.emplace ();
1467
1471
std::unordered_set<uint32_t > seen_substitutes;
1468
1472
for (const auto & num : nums) {
1469
1473
const auto & op_num = ParseKeyPathNum (num, apostrophe, error);
@@ -1473,25 +1477,25 @@ std::optional<uint32_t> ParseKeyPathNum(std::span<const char> elem, bool& apostr
1473
1477
error = strprintf (" Duplicated key path value %u in multipath specifier" , *op_num);
1474
1478
return false ;
1475
1479
}
1476
- multipath_values .emplace_back (*op_num);
1480
+ substitutes-> values .emplace_back (*op_num);
1477
1481
}
1478
1482
1479
1483
path.emplace_back (); // Placeholder for multipath segment
1480
- multipath_segment_index = path.size ()- 1 ;
1484
+ substitutes-> placeholder_index = path.size () - 1 ;
1481
1485
} else {
1482
1486
const auto & op_num = ParseKeyPathNum (elem, apostrophe, error);
1483
1487
if (!op_num) return false ;
1484
1488
path.emplace_back (*op_num);
1485
1489
}
1486
1490
}
1487
1491
1488
- if (!multipath_segment_index ) {
1492
+ if (!substitutes ) {
1489
1493
out.emplace_back (std::move (path));
1490
1494
} else {
1491
1495
// Replace the multipath placeholder with each value while generating paths
1492
- for (uint32_t substitute : multipath_values ) {
1496
+ for (uint32_t substitute : substitutes-> values ) {
1493
1497
KeyPath branch_path = path;
1494
- branch_path[*multipath_segment_index ] = substitute;
1498
+ branch_path[substitutes-> placeholder_index ] = substitute;
1495
1499
out.emplace_back (std::move (branch_path));
1496
1500
}
1497
1501
}
0 commit comments