1 /* 2 * Copyright (C) 2021 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 TELEPHONY_CELLULAR_CALL_STANDARDIZE_UTILS_H 17 #define TELEPHONY_CELLULAR_CALL_STANDARDIZE_UTILS_H 18 19 #include <string> 20 21 #include "telephony_log_wrapper.h" 22 23 namespace OHOS { 24 namespace Telephony { 25 class StandardizeUtils { 26 public: 27 /** 28 * StandardizeUtils constructor 29 */ 30 StandardizeUtils() = default; 31 32 /** 33 * ~StandardizeUtils destructor 34 */ 35 ~StandardizeUtils() = default; 36 37 /** 38 * Strips separators from a phone number string 39 * 40 * @param string phone number to strip 41 * @return phone string stripped of separators. 42 */ 43 std::string RemoveSeparatorsPhoneNumber(const std::string &phoneNum); 44 45 /** 46 * make sure there is a + in front of toa_international phone number 47 * 48 * @param string phone number 49 * @param int32_t toa 50 */ 51 std::string FormatNumberAndToa(const std::string &phoneNumber, const int32_t callToa); 52 53 void ExtractAddressAndPostDial(const std::string &phoneString, std::string &networkAddress, std::string &postDial); 54 55 static std::vector<std::string> Split(const std::string &str, const std::string &flag); 56 57 typedef std::uint64_t hash_t64; 58 Hash_(char const * hashStr)59 static hash_t64 Hash_(char const *hashStr) 60 { 61 hash_t64 result {cellular_call_b}; 62 while (*hashStr) { 63 result ^= *hashStr; 64 result *= cellular_call_p; 65 hashStr++; 66 } 67 return result; 68 } 69 70 static constexpr hash_t64 HashCompileTime(char const *str, hash_t64 last_value = cellular_call_b) 71 { 72 return *str ? HashCompileTime(str + 1, (*str ^ last_value) * cellular_call_p) : last_value; 73 } 74 IsDtmfKey(char c)75 static bool IsDtmfKey(char c) 76 { 77 return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'D') || c == '*' || c == '#'; 78 } 79 IsPauseKey(char c)80 static bool IsPauseKey(char c) 81 { 82 return c == ','; 83 } 84 IsWaitKey(char c)85 static bool IsWaitKey(char c) 86 { 87 return c == ';'; 88 } 89 90 private: 91 static constexpr hash_t64 cellular_call_p = 0x100000001B3ull; 92 static constexpr hash_t64 cellular_call_b = 0xCBF29CE484222325ull; 93 }; 94 } // namespace Telephony 95 } // namespace OHOS 96 #endif // TELEPHONY_CELLULAR_CALL_STANDARDIZE_UTILS_H 97