1 /* 2 * Copyright (c) 2023 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_GLOBAL_PHONE_NUMBER_MATCHED_H 16 #define OHOS_GLOBAL_PHONE_NUMBER_MATCHED_H 17 18 #include <string> 19 #include <unicode/regex.h> 20 #include <unordered_set> 21 #include <vector> 22 #include "phonenumbers/phonenumbermatch.h" 23 #include "phonenumbers/phonenumberutil.h" 24 #include "phonenumbers/shortnumberinfo.h" 25 #include "matched_number_info.h" 26 #include "phone_number_rule.h" 27 28 namespace OHOS { 29 namespace Global { 30 namespace I18n { 31 using i18n::phonenumbers::PhoneNumberUtil; 32 using i18n::phonenumbers::PhoneNumberMatch; 33 using i18n::phonenumbers::ShortNumberInfo; 34 class PhoneNumberMatched { 35 public: 36 PhoneNumberMatched(std::string& country); 37 ~PhoneNumberMatched(); 38 std::vector<int> GetMatchedPhoneNumber(icu::UnicodeString& message); 39 static const int CONTAIN; 40 static const int CONTAIN_OR_INTERSECT; 41 42 private: 43 bool AddPhoneNumber(std::string& number, int start, std::vector<PhoneNumberMatch*>& matchList, 44 std::string& country); 45 std::vector<MatchedNumberInfo> DeleteRepeatedInfo(std::vector<MatchedNumberInfo>& list); 46 std::vector<int> DealResult(std::vector<MatchedNumberInfo>& matchedNumberInfoList); 47 std::vector<int> DealWithoutFixed(icu::UnicodeString& message, std::string& country); 48 bool HandleWithShortAndShort(std::vector<MatchedNumberInfo>& result, std::string& country, 49 MatchedNumberInfo& info, std::pair<int, int>& pos, icu::UnicodeString& filteredString); 50 std::vector<MatchedNumberInfo> GetPossibleNumberInfos(std::string& country, 51 icu::UnicodeString& src, icu::UnicodeString& filteredString); 52 std::vector<PhoneNumberMatch*> FindNumbers(std::string& country, icu::UnicodeString& filteredString); 53 std::vector<MatchedNumberInfo> FindShortNumbers(std::string& country, icu::UnicodeString& message); 54 PhoneNumberMatch* HandleCodesRule(PhoneNumberMatch* phoneNumberMatch, icu::UnicodeString& message); 55 bool IsNumberWithOneBracket(icu::UnicodeString& message); 56 void DealNumberWithOneBracket(MatchedNumberInfo& info); 57 icu::UnicodeString DealStringWithOneBracket(icu::UnicodeString& message); 58 icu::UnicodeString HandleNegativeRule(icu::UnicodeString& src); 59 std::vector<MatchedNumberInfo> HandlePositiveRule(PhoneNumberMatch* match, icu::UnicodeString& message); 60 bool HandleBorderRule(PhoneNumberMatch* match, icu::UnicodeString& message); 61 void ReplaceSpecifiedPos(icu::UnicodeString& chs, int start, int end); 62 63 static const UChar32 REPLACE_CHAR; 64 PhoneNumberRule* phoneNumberRule; 65 PhoneNumberUtil* phoneNumberUtil; 66 ShortNumberInfo* shortNumberInfo; 67 std::string country; 68 }; 69 } // namespace I18n 70 } // namespace Global 71 } // namespace OHOS 72 #endif