improve path_basename_ex

This commit is contained in:
lixianjing 2023-09-15 17:58:44 +08:00
parent 6b31eb8f7a
commit cff44143a6
3 changed files with 14 additions and 9 deletions

View File

@ -1,4 +1,6 @@
# 最新动态
2023/09/15
* 修复 path\_basename\_ex 的对于混合斜杆不支持的问题(感谢智明提供补丁)
2023/09/14
* 修复label自动换行并且置顶时文本会往下移动几个像素的问题(感谢颖健提供补丁)

View File

@ -32,15 +32,11 @@ ret_t path_basename_ex(const char* path, bool_t remove_ext_name, char* result, i
return_value_if_fail(path != NULL && result != NULL, RET_BAD_PARAMS);
memset(result, 0x00, size);
p = strrchr(path, TK_PATH_SEP);
if (p == NULL) {
p = strrchr(path, TK_PATH_SEP == '/' ? '\\' : '/');
}
if (p == NULL) {
p = path;
} else {
p++;
}
p = path + tk_strlen(path) - 1;
while (!IS_PATH_SEP(*p) && p >= path) {
p--;
};
p++;
real_size = strlen(p);
return_value_if_fail(real_size < size, RET_BAD_PARAMS);

View File

@ -21,6 +21,13 @@ TEST(Path, basename) {
TEST(Path, basename_ex) {
char result[MAX_PATH + 1];
ASSERT_EQ(path_basename_ex("/a\\b/c/test.bin", TRUE, result, sizeof(result)), RET_OK);
ASSERT_EQ(string(result), string("test"));
ASSERT_EQ(path_basename_ex("\\a\\b/c\\test.bin", TRUE, result, sizeof(result)), RET_OK);
ASSERT_EQ(string(result), string("test"));
ASSERT_EQ(path_basename_ex("/a/test.bin", TRUE, result, sizeof(result)), RET_OK);
ASSERT_EQ(string(result), string("test"));