• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     typedef std::uint64_t hash_t64;
46 
Hash_(char const * hashStr)47     static hash_t64 Hash_(char const *hashStr)
48     {
49         hash_t64 result {cellular_call_b};
50         while (*hashStr) {
51             result ^= *hashStr;
52             result *= cellular_call_p;
53             hashStr++;
54         }
55         return result;
56     }
57 
58     static constexpr hash_t64 HashCompileTime(char const *str, hash_t64 last_value = cellular_call_b)
59     {
60         return *str ? HashCompileTime(str + 1, (*str ^ last_value) * cellular_call_p) : last_value;
61     }
62 
63 private:
64     static constexpr hash_t64 cellular_call_p = 0x100000001B3ull;
65     static constexpr hash_t64 cellular_call_b = 0xCBF29CE484222325ull;
66 };
67 } // namespace Telephony
68 } // namespace OHOS
69 #endif // TELEPHONY_CELLULAR_CALL_STANDARDIZE_UTILS_H
70