• 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 #include "tools.h"
17 #include <codecvt>
18 #include <locale>
19 #include <map>
20 #include <string>
21 
22 namespace OHOS {
23 const std::string EMPTY_DEVICEID = "";
24 constexpr int NON_ANONYMIZE_LENGTH = 6;
25 // template<typename T>
DeleteAllMark(const std::u16string & str,const std::u16string & mark)26 std::u16string DeleteAllMark(const std::u16string& str, const std::u16string& mark)
27 {
28     std::u16string s = str;
29     size_t nSize = mark.size();
30     while (true) {
31         size_t pos = s.find(mark);
32         if (pos == std::string::npos) {
33             return s;
34         }
35         s.erase(pos, nSize);
36     }
37     return s;
38 }
39 
40 // template<typename T>
DeleteBlank(const std::u16string & str)41 std::u16string DeleteBlank(const std::u16string& str)
42 {
43     std::u16string res = DeleteAllMark(str, u" ");
44     res = DeleteAllMark(res, u"/t");
45     res = DeleteAllMark(res, u"/n");
46     return DeleteAllMark(res, u"/r");
47 }
48 
AnonymizeDeviceId(const std::string & deviceId)49 std::string AnonymizeDeviceId(const std::string& deviceId)
50 {
51     if (deviceId.length() < NON_ANONYMIZE_LENGTH) {
52         return EMPTY_DEVICEID;
53     }
54     std::string anonymizeDeviceId = deviceId.substr(0, NON_ANONYMIZE_LENGTH);
55     anonymizeDeviceId.append("******");
56     return anonymizeDeviceId;
57 }
58 }