1cb7eb8c9Sopenharmony_ci/*
2cb7eb8c9Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd.
3cb7eb8c9Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4cb7eb8c9Sopenharmony_ci * you may not use this file except in compliance with the License.
5cb7eb8c9Sopenharmony_ci * You may obtain a copy of the License at
6cb7eb8c9Sopenharmony_ci *
7cb7eb8c9Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8cb7eb8c9Sopenharmony_ci *
9cb7eb8c9Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10cb7eb8c9Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11cb7eb8c9Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12cb7eb8c9Sopenharmony_ci * See the License for the specific language governing permissions and
13cb7eb8c9Sopenharmony_ci * limitations under the License.
14cb7eb8c9Sopenharmony_ci */
15cb7eb8c9Sopenharmony_ci
16cb7eb8c9Sopenharmony_ci#include "utils_log.h"
17cb7eb8c9Sopenharmony_ci
18cb7eb8c9Sopenharmony_cinamespace OHOS {
19cb7eb8c9Sopenharmony_cistd::string GetFileNameFromFullPath(const char *str)
20cb7eb8c9Sopenharmony_ci{
21cb7eb8c9Sopenharmony_ci    std::string fullPath(str);
22cb7eb8c9Sopenharmony_ci    size_t pos = fullPath.find_last_of("/");
23cb7eb8c9Sopenharmony_ci    return (pos == std::string::npos) ? std::string() : fullPath.substr(pos + 1);
24cb7eb8c9Sopenharmony_ci}
25cb7eb8c9Sopenharmony_ci
26cb7eb8c9Sopenharmony_cistd::string GetAnonyString(const std::string &value)
27cb7eb8c9Sopenharmony_ci{
28cb7eb8c9Sopenharmony_ci    constexpr size_t INT32_SHORT_ID_LENGTH = 20;
29cb7eb8c9Sopenharmony_ci    constexpr size_t INT32_PLAINTEXT_LENGTH = 4;
30cb7eb8c9Sopenharmony_ci    constexpr size_t INT32_MIN_ID_LENGTH = 3;
31cb7eb8c9Sopenharmony_ci    std::string res;
32cb7eb8c9Sopenharmony_ci    std::string tmpStr("********");
33cb7eb8c9Sopenharmony_ci    size_t strLen = value.length();
34cb7eb8c9Sopenharmony_ci    if (strLen < INT32_MIN_ID_LENGTH) {
35cb7eb8c9Sopenharmony_ci        return tmpStr;
36cb7eb8c9Sopenharmony_ci    }
37cb7eb8c9Sopenharmony_ci
38cb7eb8c9Sopenharmony_ci    if (strLen <= INT32_SHORT_ID_LENGTH) {
39cb7eb8c9Sopenharmony_ci        res += value[0];
40cb7eb8c9Sopenharmony_ci        res += tmpStr;
41cb7eb8c9Sopenharmony_ci        res += value[strLen - 1];
42cb7eb8c9Sopenharmony_ci    } else {
43cb7eb8c9Sopenharmony_ci        res.append(value, 0, INT32_PLAINTEXT_LENGTH);
44cb7eb8c9Sopenharmony_ci        res += tmpStr;
45cb7eb8c9Sopenharmony_ci        res.append(value, INT32_PLAINTEXT_LENGTH + tmpStr.length(), strLen - INT32_PLAINTEXT_LENGTH - tmpStr.length());
46cb7eb8c9Sopenharmony_ci    }
47cb7eb8c9Sopenharmony_ci
48cb7eb8c9Sopenharmony_ci    return res;
49cb7eb8c9Sopenharmony_ci}
50cb7eb8c9Sopenharmony_ci} // namespace OHOS
51