Skip to content

Commit d4d6ae6

Browse files
AnonTokioccmywish
authored andcommitted
feat(path): add path join
1 parent f10a49d commit d4d6ae6

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lib/xy.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,6 +1370,30 @@ xy_normalize_path (const char *path)
13701370
return new;
13711371
}
13721372

1373+
/**
1374+
* @flavor Ruby: Pathname#join
1375+
*
1376+
* @memory SAFE
1377+
* return caller-free
1378+
*/
1379+
static char *
1380+
xy_path_join (const char *path1, const char *path2)
1381+
{
1382+
char *sep = xy.on_windows ? "\\" : "/";
1383+
char *path1_norm = xy_normalize_path (path1);
1384+
char *path2_norm = xy_normalize_path (path2);
1385+
if (!xy_str_end_with (path1_norm, sep))
1386+
{
1387+
char *tmp = xy_2strcat (path1_norm, sep);
1388+
free (path1_norm);
1389+
path1_norm = tmp;
1390+
}
1391+
char *path_joined = xy_2strcat (path1_norm, path2_norm);
1392+
free (path1_norm);
1393+
free (path2_norm);
1394+
return path_joined;
1395+
}
1396+
13731397

13741398
/**
13751399
* @brief 返回一个路径的父目录名

src/chsrc-main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ chsrc_register_contributors ()
7272
chef_register_contributor ("@Mikachu2333", "Mikachu2333", "mikachu.23333@zohomail.com", NULL);
7373
chef_register_contributor ("@techoc", "Rui Yang", "techoc@foxmail.com", NULL);
7474
chef_register_contributor ("@BingChunMoLi", "BingChunMoLi", "bingchunmoli@bingchunmoli.com", NULL);
75+
chef_register_contributor ("@AnonTokio", "Anon Tokio", "anontokio@163.com", NULL);
7576
// 该 ID 为 Gitee ID
7677
chef_register_contributor ("@hezonglun", "HeZongLun", "hezonglun123456@outlook.com", NULL);
7778
chef_register_contributor ("@Young-Lord", "LY", "ly-niko@qq.com", NULL);

0 commit comments

Comments
 (0)