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 void ExtractAddressAndPostDial(const std::string &phoneString, std::string &networkAddress, std::string &postDial); 46 47 typedef std::uint64_t hash_t64; 48 Hash_(char const * hashStr)49 static hash_t64 Hash_(char const *hashStr) 50 { 51 hash_t64 result {cellular_call_b}; 52 while (*hashStr) { 53 result ^= *hashStr; 54 result *= cellular_call_p; 55 hashStr++; 56 } 57 return result; 58 } 59 60 static constexpr hash_t64 HashCompileTime(char const *str, hash_t64 last_value = cellular_call_b) 61 { 62 return *str ? HashCompileTime(str + 1, (*str ^ last_value) * cellular_call_p) : last_value; 63 } 64 IsDtmfKey(char c)65 static bool IsDtmfKey(char c) 66 { 67 return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'D') || c == '*' || c == '#'; 68 } 69 IsPauseKey(char c)70 static bool IsPauseKey(char c) 71 { 72 return c == ','; 73 } 74 IsWaitKey(char c)75 static bool IsWaitKey(char c) 76 { 77 return c == ';'; 78 } 79 80 private: 81 static constexpr hash_t64 cellular_call_p = 0x100000001B3ull; 82 static constexpr hash_t64 cellular_call_b = 0xCBF29CE484222325ull; 83 }; 84 } // namespace Telephony 85 } // namespace OHOS 86 #endif // TELEPHONY_CELLULAR_CALL_STANDARDIZE_UTILS_H 87