From 19f680547b04f0ba1e2dc528697ec5a78563a06d Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Mon, 23 Sep 2024 20:36:18 +0800 Subject: [PATCH] =?utf8?q?=E6=B7=BB=E5=8A=A0=E5=B0=8616=E8=BF=9B=E5=88=B6?= =?utf8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E8=BD=ACUTF=E5=AD=97=E7=AC=A6?= =?utf8?q?=E4=B8=B2=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/player/include/PlayersPresenter.h | 3 ++- .../nativeui/player/src/PlayersPresenter.cpp | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) 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() { } -- 2.17.1