mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-11-30 02:58:26 +08:00
improve dirname
This commit is contained in:
parent
77d0c9ba65
commit
8d0a94e6bf
@ -1,4 +1,8 @@
|
||||
# 最新动态
|
||||
|
||||
2022/09/16
|
||||
* path_dirname 处理斜杠和反斜杠的混用的路径时候不正常的问题(感谢智明提供补丁)
|
||||
|
||||
2022/09/14
|
||||
* 支持在添加idle和添加timer是指定ID(感谢智明提供补丁)
|
||||
|
||||
|
@ -80,13 +80,19 @@ ret_t path_extname(const char* path, char* result, int32_t size) {
|
||||
|
||||
ret_t path_dirname(const char* path, char* result, int32_t size) {
|
||||
const char* p = NULL;
|
||||
const char* p1 = NULL;
|
||||
int32_t real_size = 0;
|
||||
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 == '/' ? '\\' : '/');
|
||||
p = strrchr(path, '\\');
|
||||
p1 = strrchr(path, '/');
|
||||
if (p == NULL && p1 != NULL) {
|
||||
p = p1;
|
||||
} else if (p != NULL && p1 != NULL) {
|
||||
if (p - p1 < 0) {
|
||||
p = p1;
|
||||
}
|
||||
}
|
||||
|
||||
if (p != NULL) {
|
||||
|
@ -57,15 +57,33 @@ TEST(Path, extname) {
|
||||
}
|
||||
|
||||
TEST(Path, dirname) {
|
||||
char result[MAX_PATH + 1];
|
||||
char result[MAX_PATH + 1] = {0};
|
||||
ASSERT_EQ(path_dirname("/a/test.bin", result, sizeof(result)), RET_OK);
|
||||
ASSERT_EQ(string(result), string("/a/"));
|
||||
|
||||
memset(result, 0x0, sizeof(result));
|
||||
ASSERT_EQ(path_dirname("/a/b/test.bin", result, sizeof(result)), RET_OK);
|
||||
ASSERT_EQ(string(result), string("/a/b/"));
|
||||
|
||||
memset(result, 0x0, sizeof(result));
|
||||
ASSERT_EQ(path_dirname("test.bin", result, sizeof(result)), RET_FAIL);
|
||||
ASSERT_EQ(string(result), string(""));
|
||||
|
||||
memset(result, 0x0, sizeof(result));
|
||||
ASSERT_EQ(path_dirname("e:\\a\\b/c/d", result, sizeof(result)), RET_OK);
|
||||
ASSERT_EQ(string(result), string("e:\\a\\b/c/"));
|
||||
|
||||
memset(result, 0x0, sizeof(result));
|
||||
ASSERT_EQ(path_dirname("e:\\a\\b/c\\d", result, sizeof(result)), RET_OK);
|
||||
ASSERT_EQ(string(result), string("e:\\a\\b/c\\"));
|
||||
|
||||
memset(result, 0x0, sizeof(result));
|
||||
ASSERT_EQ(path_dirname("e:/a/b\\c\\d", result, sizeof(result)), RET_OK);
|
||||
ASSERT_EQ(string(result), string("e:/a/b\\c\\"));
|
||||
|
||||
memset(result, 0x0, sizeof(result));
|
||||
ASSERT_EQ(path_dirname("e:/a/b\\c/d", result, sizeof(result)), RET_OK);
|
||||
ASSERT_EQ(string(result), string("e:/a/b\\c/"));
|
||||
}
|
||||
|
||||
TEST(Path, exe) {
|
||||
|
Loading…
Reference in New Issue
Block a user