1 /*
2  * Copyright 2022, The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <regex>
20 #include <string>
21 
22 namespace dmesg_parser {
23 
24 class DmesgParser {
25   public:
26     DmesgParser();
27     void ProcessLine(const std::string& line);
28     bool ReportReady() const;
29     std::string ReportType() const;
30     std::string ReportTitle() const;
31     std::string FlushReport();
32 
33   private:
34     std::string StripSensitiveData(const std::string& line) const;
35 
36     bool report_ready_;
37     std::string last_report_;
38     std::regex bug_pattern_, ignore_pattern_, addr64_pattern_;
39     std::regex task_line_pattern_, task_delimiter_pattern_;
40     std::string current_report_;
41     std::string current_task_, current_tool_, current_title_;
42 };
43 
44 }  // namespace dmesg_parser
45