Commit b3d50a3c authored by Paul Asmuth's avatar Paul Asmuth
Browse files

add plist::flatten

parent 73a8d3d8
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -88,5 +88,26 @@ bool is_value_quoted(const Property& prop, const std::string& cmp) {
  return prop.kind == PropertyKind::VALUE && prop.value == cmp;
}

std::vector<std::string> flatten(const Property& prop) {
  switch (prop.kind) {
    case PropertyKind::VALUE_LITERAL:
    case PropertyKind::VALUE:
      return {prop.value};
    case PropertyKind::TUPLE:
    case PropertyKind::LIST:
      break;
    default:
      return {};
  }

  std::vector<std::string> flat;
  for (const auto& n : *prop.next) {
    auto next = flatten(n);
    flat.insert(flat.end(), next.begin(), next.end());
  }

  return flat;
}

} // namespace plist
+2 −0
Original line number Diff line number Diff line
@@ -46,5 +46,7 @@ bool is_value_literal(const Property& prop, const std::string& cmp);
bool is_value_quoted(const Property& prop);
bool is_value_quoted(const Property& prop, const std::string& cmp);

std::vector<std::string> flatten(const Property& prop);

} // namespace plist