1 /* 2 * Copyright (c) 2025 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 OHOS_MECHBODY_CONTROLLER_UTILS_H 17 #define OHOS_MECHBODY_CONTROLLER_UTILS_H 18 19 #include "mechbody_controller_utils.h" 20 21 #include <cmath> 22 #include <string> 23 24 #include "mechbody_controller_log.h" 25 26 namespace OHOS { 27 namespace MechBodyController { 28 const std::string TAG = "McUtils"; 29 constexpr size_t INT32_SHORT_ID_LEN = 20; 30 constexpr size_t INT32_MIN_ID_LEN = 6; 31 constexpr size_t INT32_PLAINTEXT_LEN = 4; 32 constexpr float DEGREE_CONSTANT_180_FLOAT = 180.0f; 33 GetAnonymStr(const std::string & value)34std::string GetAnonymStr(const std::string &value) 35 { 36 std::string res; 37 std::string tmpStr("******"); 38 size_t strLen = value.length(); 39 if (strLen < INT32_MIN_ID_LEN) { 40 return tmpStr; 41 } 42 43 if (strLen <= INT32_SHORT_ID_LEN) { 44 res += value[0]; 45 res += tmpStr; 46 res += value[strLen - 1]; 47 } else { 48 res.append(value, 0, INT32_PLAINTEXT_LEN); 49 res += tmpStr; 50 res.append(value, strLen - INT32_PLAINTEXT_LEN, INT32_PLAINTEXT_LEN); 51 } 52 53 return res; 54 } 55 GetAnonymInt32(const int32_t value)56std::string GetAnonymInt32(const int32_t value) 57 { 58 std::string tmpStr = std::to_string(value); 59 return GetAnonymStr(tmpStr); 60 } 61 GetAnonymUint32(const uint32_t value)62std::string GetAnonymUint32(const uint32_t value) 63 { 64 std::string tmpStr = std::to_string(value); 65 return GetAnonymStr(tmpStr); 66 } 67 RadToDegree(float radius)68float RadToDegree(float radius) 69 { 70 return radius * DEGREE_CONSTANT_180_FLOAT / M_PI; 71 } 72 } // namespace MechBodyController 73 } // namespace OHOS 74 #endif // OHOS_MECHBODY_CONTROLLER_UTILS_H 75