5#ifndef FLUTTER_TOOLS_LICENSES_CPP_SRC_CATALOG_H_
6#define FLUTTER_TOOLS_LICENSES_CPP_SRC_CATALOG_H_
8#include "flutter/third_party/re2/re2/re2.h"
9#include "flutter/third_party/re2/re2/set.h"
10#include "third_party/abseil-cpp/absl/container/flat_hash_map.h"
11#include "third_party/abseil-cpp/absl/status/statusor.h"
33 std::string matched_text) {
34 return Match(matcher, std::move(matched_text));
38 std::string_view matched_text) {
39 return Match(matcher, matched_text);
44 if (matched_text_.empty()) {
45 return owned_matched_text_;
52 Match(std::string_view matcher, std::string_view matched_text)
53 : matcher_(matcher), matched_text_(matched_text) {}
54 Match(std::string_view matcher, std::string matched_text)
55 : matcher_(matcher), owned_matched_text_(
std::move(matched_text)) {}
57 std::string_view matcher_;
58 std::string_view matched_text_;
59 std::string owned_matched_text_;
62 static absl::StatusOr<Catalog>
Open(std::string_view data_dir);
65 static absl::StatusOr<Catalog>
Make(
const std::vector<Entry>& entries);
72 absl::StatusOr<std::vector<Match>>
FindMatch(std::string_view query)
const;
75 static absl::StatusOr<Entry>
ParseEntry(std::istream& is);
78 explicit Catalog(RE2::Set selector,
79 std::vector<std::unique_ptr<RE2>> matchers,
80 std::vector<std::string> names);
82 std::vector<std::unique_ptr<RE2>> matchers_;
83 std::vector<std::string> names_;
static Match MakeWithView(std::string_view matcher, std::string_view matched_text)
std::string_view GetMatcher() const
std::string_view GetMatchedText() const
static Match MakeWithString(std::string_view matcher, std::string matched_text)
static absl::StatusOr< Entry > ParseEntry(std::istream &is)
VisibleForTesting.
static absl::StatusOr< Catalog > Open(std::string_view data_dir)
absl::StatusOr< std::vector< Match > > FindMatch(std::string_view query) const
Tries to identify a match for the query across the Catalog.
static absl::StatusOr< Catalog > Make(const std::vector< Entry > &entries)
Make a Catalog for testing.