@@ -215,7 +215,7 @@ xy_malloc0 (size_t size)
215215 * @param new_str 新的字符串指针
216216 */
217217static inline void
218- xy_str_replace (char * * old_ptr , char * new_str )
218+ xy_ptr_replace (char * * old_ptr , char * new_str )
219219{
220220 if (old_ptr && * old_ptr )
221221 {
@@ -618,7 +618,8 @@ static char *
618618xy_str_strip (const char * str )
619619{
620620 if (!str )
621- return xy_strdup ("" );
621+ xy_cant_be_null (str );
622+
622623
623624 const char * start = str ;
624625 while (* start && strchr ("\n\r\v\t\f " , * start ))
@@ -749,7 +750,7 @@ xy_file_read (const char *path)
749750 buf [read_bytes ] = '\0' ;
750751
751752 char * formatted_str = xy_str_gsub (buf , "\r\n" , "\n" );
752- xy_str_replace (& formatted_str , xy_str_gsub (formatted_str , "\r" , "\n" ));
753+ xy_ptr_replace (& formatted_str , xy_str_gsub (formatted_str , "\r" , "\n" ));
753754
754755 free (buf );
755756
@@ -1258,12 +1259,12 @@ xy_normalize_path (const char *path)
12581259 char * tmp = xy_str_delete_prefix (new , "~" );
12591260 char * joined = xy_2strcat (xy_os_home , tmp );
12601261 free (tmp );
1261- xy_str_replace (& new , joined );
1262+ xy_ptr_replace (& new , joined );
12621263 }
12631264
12641265 if (xy .on_windows )
12651266 {
1266- xy_str_replace (& new , xy_str_gsub (new , "/" , "\\" ));
1267+ xy_ptr_replace (& new , xy_str_gsub (new , "/" , "\\" ));
12671268 }
12681269 return new ;
12691270}
@@ -1282,10 +1283,10 @@ xy_parent_dir (const char *path)
12821283 char * dir = xy_normalize_path (path );
12831284
12841285 /* 不管是否为Windows,全部统一使用 / 作为路径分隔符,方便后续处理 */
1285- xy_str_replace (& dir , xy_str_gsub (dir , "\\" , "/" ));
1286+ xy_ptr_replace (& dir , xy_str_gsub (dir , "\\" , "/" ));
12861287
12871288 if (xy_str_end_with (dir , "/" ))
1288- xy_str_replace (& dir , xy_str_delete_suffix (dir , "/" ));
1289+ xy_ptr_replace (& dir , xy_str_delete_suffix (dir , "/" ));
12891290
12901291 char * last = NULL ;
12911292
@@ -1300,7 +1301,7 @@ xy_parent_dir (const char *path)
13001301 /* Windows上重新使用 \ 作为路径分隔符 */
13011302 if (xy .on_windows )
13021303 {
1303- xy_str_replace (& dir , xy_str_gsub (dir , "/" , "\\" ));
1304+ xy_ptr_replace (& dir , xy_str_gsub (dir , "/" , "\\" ));
13041305 }
13051306 return dir ;
13061307}
0 commit comments