1 /*
2  * Copyright (C) 2024 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 
16 #ifndef PASTE_BOARD_PATTERN_H
17 #define PASTE_BOARD_PATTERN_H
18 
19 #include <map>
20 #include <regex>
21 #include <set>
22 
23 #include "paste_data.h"
24 
25 namespace OHOS::MiscServices {
26 enum class Pattern : uint32_t { URL = 0, Number, EmailAddress, PatternCount };
27 class PatternDetection {
28 public:
29     static const std::set<Pattern> Detect(
30         const std::set<Pattern> &patternsToCheck, const PasteData &pasteData, bool hasHTML, bool hasPlain);
31     static bool IsValid(const std::set<Pattern> &patterns);
32 
33 private:
34     static std::string ExtractHtmlContent(const std::string &html_str);
35     static void DetectPlainText(
36         std::set<Pattern> &patternsOut, const std::set<Pattern> &PatternsIn, const std::string &plainText);
37 
38     static std::map<uint32_t, std::string> patterns_;
39 };
40 } // namespace OHOS::MiscServices
41 #endif // PASTE_BOARD_PATTERN_H