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 <regex> 20 #include <set> 21 #include <map> 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(const std::set<Pattern> &patternsToCheck, 30 const PasteData &pasteData, bool hasHTML, bool hasPlain); 31 static bool IsValid(const std::set<Pattern> &patterns); 32 private: 33 static std::string ExtractHtmlContent(const std::string &html_str); 34 static void DetectPlainText(std::set<Pattern> &patternsOut, const std::set<Pattern> &PatternsIn, 35 const std::string &plainText); 36 37 static std::map<uint32_t, std::string> patterns_; 38 }; 39 } // namespace OHOS::MiscServices 40 #endif // PASTE_BOARD_PATTERN_H