Skip to content

Commit

Permalink
Merge pull request #165 from tencentyun/feature_huberyxxiao_ba149772
Browse files Browse the repository at this point in the history
修复qt环境下encode问题
  • Loading branch information
Huberyxiao authored Jul 16, 2024
2 parents d1063e7 + b36da04 commit ad5f0c4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion include/cos_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace qcloud_cos {

#define COS_CPP_SDK_VERSON "v5.5.12"
#define COS_CPP_SDK_VERSON "v5.5.13"

/// 路径分隔符
const char kPathDelimiter[] = "/";
Expand Down
2 changes: 2 additions & 0 deletions include/util/codec_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class CodecUtil {
static void BinToHex(const unsigned char* bin, unsigned int binLen,
char* hex);

static bool IsalnumAscii(int c);

static std::string EncodeKey(const std::string& key);

/**
Expand Down
9 changes: 7 additions & 2 deletions src/util/codec_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,16 @@ void CodecUtil::BinToHex(const unsigned char* bin, unsigned int binLen,
}
}

bool CodecUtil::IsalnumAscii(int c) {
// 使用 ASCII 码范围判断是否是字母或数字
return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9');
}

std::string CodecUtil::EncodeKey(const std::string& key) {
std::string encodedKey = "";
std::size_t length = key.length();
for (size_t i = 0; i < length; ++i) {
if (isalnum((unsigned char)key[i]) || (key[i] == '-') || (key[i] == '_') ||
if (IsalnumAscii((unsigned char)key[i]) || (key[i] == '-') || (key[i] == '_') ||
(key[i] == '.') || (key[i] == '~') || (key[i] == '/')) {
encodedKey += key[i];
} else {
Expand All @@ -50,7 +55,7 @@ std::string CodecUtil::UrlEncode(const std::string& str) {
std::string encodedUrl = "";
std::size_t length = str.length();
for (size_t i = 0; i < length; ++i) {
if (isalnum((unsigned char)str[i]) || (str[i] == '-') || (str[i] == '_') ||
if (IsalnumAscii((unsigned char)str[i]) || (str[i] == '-') || (str[i] == '_') ||
(str[i] == '.') || (str[i] == '~')) {
encodedUrl += str[i];
} else {
Expand Down

0 comments on commit ad5f0c4

Please sign in to comment.