From 16602d0e7f8a90b6755d5a79f6ac4fc323401338 Mon Sep 17 00:00:00 2001 From: Mikachu2333 Date: Tue, 7 Oct 2025 18:41:33 +0800 Subject: [PATCH] =?UTF-8?q?refactor(lib):=20=E9=87=8D=E5=91=BD=E5=90=8D?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E6=9B=BF=E6=8D=A2=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将函数名从 `xy_str_swap` 更改为 `xy_str_replace`,以更准确地反映其实际功能。 该函数并非简单交换两个字符串,而是用新字符串替换旧字符串的内容。 此更改涉及多个文件中的调用点,包括路径处理和文件读取相关的逻辑。 --- lib/xy.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/xy.h b/lib/xy.h index 77cd60f..9e4e822 100644 --- a/lib/xy.h +++ b/lib/xy.h @@ -215,7 +215,7 @@ xy_malloc0 (size_t size) * @param new_str 新的字符串指针 */ static inline void -xy_str_swap (char **old_ptr, char *new_str) +xy_str_replace (char **old_ptr, char *new_str) { if (old_ptr && *old_ptr) { @@ -749,7 +749,7 @@ xy_file_read (const char *path) buf[read_bytes] = '\0'; char *formatted_str = xy_str_gsub (buf, "\r\n", "\n"); - xy_str_swap (&formatted_str, xy_str_gsub (formatted_str, "\r", "\n")); + xy_str_replace (&formatted_str, xy_str_gsub (formatted_str, "\r", "\n")); free (buf); @@ -1258,12 +1258,12 @@ xy_normalize_path (const char *path) char *tmp = xy_str_delete_prefix (new, "~"); char *joined = xy_2strcat (xy_os_home, tmp); free (tmp); - xy_str_swap (&new, joined); + xy_str_replace (&new, joined); } if (xy.on_windows) { - xy_str_swap (&new, xy_str_gsub (new, "/", "\\")); + xy_str_replace (&new, xy_str_gsub (new, "/", "\\")); } return new; } @@ -1282,10 +1282,10 @@ xy_parent_dir (const char *path) char *dir = xy_normalize_path (path); /* 不管是否为Windows,全部统一使用 / 作为路径分隔符,方便后续处理 */ - xy_str_swap (&dir, xy_str_gsub (dir, "\\", "/")); + xy_str_replace (&dir, xy_str_gsub (dir, "\\", "/")); if (xy_str_end_with (dir, "/")) - xy_str_swap (&dir, xy_str_delete_suffix (dir, "/")); + xy_str_replace (&dir, xy_str_delete_suffix (dir, "/")); char *last = NULL; @@ -1300,7 +1300,7 @@ xy_parent_dir (const char *path) /* Windows上重新使用 \ 作为路径分隔符 */ if (xy.on_windows) { - xy_str_swap (&dir, xy_str_gsub (dir, "/", "\\")); + xy_str_replace (&dir, xy_str_gsub (dir, "/", "\\")); } return dir; }