Flutter Engine
 
Loading...
Searching...
No Matches
filter.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6#include <fstream>
7#include "third_party/abseil-cpp/absl/strings/str_cat.h"
8
9absl::StatusOr<Filter> Filter::Open(std::string_view path) {
10 std::ifstream input;
11 input.open(path);
12 absl::StatusOr<Filter> result = Open(input);
13 input.close();
14 return result;
15}
16
17absl::StatusOr<Filter> Filter::Open(std::istream& input) {
18 if (!input.good()) {
19 return absl::InvalidArgumentError("stream not good");
20 }
21 std::string regex;
22 bool first = true;
23 std::string line;
24 while (input.good()) {
25 std::getline(input, line);
26 if (line.length() <= 0) {
27 continue;
28 }
29 if (line[0] == '#') {
30 // Comments.
31 continue;
32 }
33 if (!first) {
34 absl::StrAppend(&regex, "|");
35 } else {
36 first = false;
37 }
38 absl::StrAppend(&regex, line);
39 }
40
41 return Filter(regex);
42}
43
44Filter::Filter(std::string_view regex) : re_(std::make_unique<RE2>(regex)) {}
45
46bool Filter::Matches(std::string_view input) const {
47 return RE2::FullMatch(input, *re_);
48}
static absl::StatusOr< Filter > Open(std::string_view path)
Definition filter.cc:9
bool Matches(std::string_view input) const
Definition filter.cc:46
Filter(const Filter &)=delete
static int input(yyscan_t yyscanner)
Definition ref_ptr.h:261