From: luozheng <1732036298@qq.com> Date: Mon, 23 Sep 2024 12:36:18 +0000 (+0800) Subject: 添加将16进制字符串转UTF字符串函数 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=refs%2Fchanges%2F1006%2F3;p=mirrors%2FFD230.git 添加将16进制字符串转UTF字符串函数 --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/player/include/PlayersPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/player/include/PlayersPresenter.h index 42d8c5a02..0d7035bc9 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/player/include/PlayersPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/player/include/PlayersPresenter.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-08-05 15:20:03 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-09-23 16:17:55 + * @LastEditTime: 2024-09-23 20:24:49 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/player/include/PlayersPresenter.h */ @@ -84,6 +84,7 @@ public: List& GetCase(); char *GetCase(int16_t index); void AddCase(PlayerCaseInfo testCaseInfo); + std::string hex_to_string(const std::string &hex_str); private: List *playersCaseList_{nullptr}; diff --git a/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersPresenter.cpp index 198f93461..55b4c5e10 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersPresenter.cpp @@ -567,6 +567,23 @@ int PlayersListGroup::GetAllFiles(std::list &playersList) return OHOS_SUCCESS; } +//将16进制字符串转UTF-8字符串 +std::string PlayersListGroup::hex_to_string(const std::string &hex_str) +{ + size_t length = hex_str.length(); + std::string result; + result.reserve(length / 2); // 预分配内存以容纳结果字符串,避免在 push_back 时频繁重新分配 + + for (size_t i = 0; i < length / 2; i++) { + // 从十六进制字符串中提取每两个字符 + std::string byteString = hex_str.substr(i * 2, 2); // 获取两个字符的子串 + + // 将十六进制字符串转换为字符 + result.push_back(static_cast(strtol(byteString.c_str(), nullptr, 16))); + } + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "hex_to_string:%s",result.c_str()); + return result; // 返回结果字符串 +} ButtonOnClickListener::~ButtonOnClickListener() { }