1 /* 2 * Copyright (c) 2021-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 OHOS_ABILITY_BASE_PATTERNS_MATCHER_H 16 #define OHOS_ABILITY_BASE_PATTERNS_MATCHER_H 17 18 #include "match_type.h" 19 20 #include <string> 21 #include <memory> 22 #include <regex> 23 #include "parcel.h" 24 #include "string_ex.h" 25 26 namespace OHOS { 27 namespace AAFwk { 28 class PatternsMatcher : public Parcelable, public std::enable_shared_from_this<PatternsMatcher> { 29 public: 30 /** 31 * @brief A parameterized constructor used to create a PatternsMatcher instance. 32 * 33 */ 34 PatternsMatcher(); 35 36 /** 37 * @brief A parameterized constructor used to create a PatternsMatcher instance. 38 * 39 * @param patternsMatcher Indicates patternsMatcher used to create a patternsMatcher instance. 40 */ 41 PatternsMatcher(const PatternsMatcher &patternsMatcher); 42 43 /** 44 * @brief A parameterized constructor used to create a PatternsMatcher instance. 45 * 46 * @param pattern Indicates pattern used to create a patternsMatcher instance. 47 * @param type Indicates type used to create a patternsMatcher instance. 48 */ 49 PatternsMatcher(std::string pattern, MatchType type); 50 ~PatternsMatcher(); 51 52 /** 53 * @brief Obtains the pattern. 54 * 55 * @return the specified pattern. 56 */ 57 std::string GetPattern() const; 58 59 /** 60 * @brief Obtains the specified type. 61 * 62 * @return the specified type. 63 */ 64 MatchType GetType() const; 65 66 /** 67 * @brief Match this PatternsMatcher against a string data. 68 * 69 * @param str The desired string to look for. 70 * @return Returns either a valid match constant. 71 */ 72 bool match(std::string str); 73 74 /** 75 * @brief Match this PatternsMatcher against an Pattern's data. 76 * 77 * @param pattern The desired data to look for. 78 * @param match The full data string to match against. 79 * @param type The desired tyoe to look for. 80 * 81 * @return Returns either a valid match constant. 82 */ 83 static bool MatchPattern(std::string pattern, std::string match, MatchType type); 84 85 /** 86 * @brief Marshals this Sequenceable object into a Parcel. 87 * 88 * @param outParcel Indicates the Parcel object to which the Sequenceable object will be marshaled. 89 */ 90 bool Marshalling(Parcel &parcel) const; 91 92 /** 93 * @brief Unmarshals this Sequenceable object from a Parcel. 94 * 95 * @param inParcel Indicates the Parcel object into which the Sequenceable object has been marshaled. 96 */ 97 static PatternsMatcher *Unmarshalling(Parcel &parcel); 98 99 private: 100 std::string pattern_; 101 MatchType type_; 102 103 private: 104 /** 105 * @brief Match this PatternsMatcher against an Pattern's data. 106 * 107 * @param pattern The desired data to look for. 108 * @param match The full data string to match against. 109 * 110 * @return Returns either a valid match constant. 111 */ 112 static bool GlobPattern(std::string pattern, std::string match); 113 114 bool ReadFromParcel(Parcel &parcel); 115 }; 116 } // namespace AAFwk 117 } // namespace OHOS 118 119 #endif // OHOS_ABILITY_BASE_PATTERN_MATCHER_H