1/*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15#ifndef LOG_PARSE_H
16#define LOG_PARSE_H
17
18#include <list>
19#include <map>
20#include <set>
21#include <stack>
22#include <string>
23
24#include "common_defines.h"
25namespace OHOS {
26namespace HiviewDFX {
27class LogParse {
28public:
29    LogParse() {};
30    ~LogParse() {};
31    LogParse(const LogParse&) = delete;
32    LogParse& operator=(const LogParse&) = delete;
33    bool IsIgnoreLibrary(const std::string& val) const;
34    static std::string MatchExceptionLibrary(const std::string& val);
35    void SetFrame(std::stack<std::string>& stack, std::map<std::string, std::string>& eventInfo) const;
36    std::string GetFilterTrace(const std::string& info, std::vector<std::string>& trace,
37        std::string eventType) const;
38    std::stack<std::string> GetStackTop(const std::vector<std::string>& validStack, const size_t num) const;
39
40public:
41    static const std::string UNMATCHED_EXCEPTION;
42
43private:
44    bool HasExceptionList(const std::string& line) const;
45    std::vector<std::string> GetValidStack(size_t num, std::stack<std::string>& inStack) const;
46    std::list<std::vector<std::string>> StackToMultipart(std::stack<std::string>& inStack, size_t num) const;
47    bool GetValidStack(int num, std::stack<std::string>& inStack, std::stack<std::string>& outStack) const;
48    void MatchIgnoreLibrary(std::stack<std::string> inStack, std::stack<std::string>& outStack, size_t num) const;
49    std::string GetValidBlock(std::stack<std::string> inStack, std::vector<std::string>& lastPart) const;
50
51private:
52    static const int STACK_LEN_MAX = 30;
53    static const std::map<std::string, std::set<std::string>> ignoreList_;
54    static const std::set<std::string> exceptionList_;
55};
56}
57}
58#endif