mirror of
https://github.com/RubyMetric/chsrc.git
synced 2025-04-09 16:20:36 +08:00
Rename to xy_unix_path_to_win_if_on_win
This commit is contained in:
parent
b92c68ebed
commit
87858ed7a8
@ -90,6 +90,9 @@ main (int argc, char const *argv[])
|
|||||||
assert(xy_file_exist("chsrc.png"));
|
assert(xy_file_exist("chsrc.png"));
|
||||||
assert(xy_file_exist(xy_win_powershell_profile));
|
assert(xy_file_exist(xy_win_powershell_profile));
|
||||||
assert(false==xy_file_exist(xy_win_powershellv5_profile));
|
assert(false==xy_file_exist(xy_win_powershellv5_profile));
|
||||||
|
|
||||||
|
puts (xy_unix_path_to_win_if_on_win(" \n ~/haha/test/123 \n\r "));
|
||||||
|
|
||||||
xy_success("测试全部通过");
|
xy_success("测试全部通过");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
28
xy.h
28
xy.h
@ -517,9 +517,9 @@ _xy_win_powershellv5_profile ()
|
|||||||
* @note Windows上,`path` 不要夹带变量名,因为最终 access() 不会帮你转换
|
* @note Windows上,`path` 不要夹带变量名,因为最终 access() 不会帮你转换
|
||||||
*/
|
*/
|
||||||
static bool
|
static bool
|
||||||
xy_file_exist (char* path)
|
xy_file_exist (const char* path)
|
||||||
{
|
{
|
||||||
char* newpath = path;
|
const char* newpath = path;
|
||||||
if (xy_on_windows)
|
if (xy_on_windows)
|
||||||
{
|
{
|
||||||
if (xy_str_start_with(path, "~")) {
|
if (xy_str_start_with(path, "~")) {
|
||||||
@ -530,16 +530,24 @@ xy_file_exist (char* path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static const char*
|
/**
|
||||||
xy_unix_path_to_win (const char* path)
|
* 该函数即使在非Windows下也可调用,作用是删除路径左右两边多出来的空白符
|
||||||
|
*/
|
||||||
|
static char*
|
||||||
|
xy_unix_path_to_win_if_on_win (const char* path)
|
||||||
{
|
{
|
||||||
path = xy_str_strip(path); // 防止开发者多写了空格
|
char* new = xy_str_strip(path); // 防止开发者多写了空白符
|
||||||
if (xy_str_start_with(path, "~/")){
|
|
||||||
// 或 %USERPROFILE%
|
// 这个函数仅在Windows上才进行替换
|
||||||
path = xy_strjoin(3, xy_os_home, "\\", xy_str_delete_prefix(path, "~/"));
|
if (xy_on_windows) {
|
||||||
path = xy_str_gsub(path, "/", "\\");
|
if (xy_str_start_with(new, "~/")){
|
||||||
|
// 或 %USERPROFILE%
|
||||||
|
new = xy_strjoin(3, xy_os_home, "\\", xy_str_delete_prefix(new, "~/"));
|
||||||
|
}
|
||||||
|
new = xy_str_gsub(new, "/", "\\");
|
||||||
}
|
}
|
||||||
return path;
|
|
||||||
|
return new;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user