Refactor `xy_ptr_replace()`

This commit is contained in:
Aoran Zeng 2025-10-28 13:44:42 +08:00
parent 985a6344b3
commit 066ac191a6
No known key found for this signature in database
GPG Key ID: 8F8BA8488E10ED98

View File

@ -9,7 +9,7 @@
* | BingChunMoLi <bingchunmoli@bingchunmoli.com>
* |
* Created On : <2023-08-28>
* Last Modified : <2025-10-15>
* Last Modified : <2025-10-28>
*
*
* xy:
@ -23,7 +23,7 @@
#ifndef XY_H
#define XY_H
#define _XY_Version "v0.2.1.1-2025/10/07"
#define _XY_Version "v0.2.2.0-2025/10/28"
#define _XY_Maintain_URL "https://github.com/RubyMetric/chsrc/blob/dev/lib/xy.h"
#define _XY_Maintain_URL2 "https://gitee.com/RubyMetric/chsrc/blob/dev/lib/xy.h"
@ -213,33 +213,31 @@ xy_malloc0 (size_t size)
}
/**
* @brief
*
* @param pptr
* *pptr NULL
* @param new_mem
*/
static inline void
xy_ptr_replace (char **pptr, char *new_mem)
{
xy_cant_be_null (pptr);
if (*pptr)
free (*pptr);
*pptr = new_mem;
}
/******************************************************
* String
******************************************************/
/**
* @brief
*
* @param old_ptr (char **)
* @param new_str
*/
static inline void
xy_ptr_replace (char **old_ptr, char *new_str)
{
if (old_ptr && *old_ptr)
{
char *temp = *old_ptr;
*old_ptr = new_str;
free (temp);
}
else if (old_ptr)
{
*old_ptr = new_str;
}
}
/**
* @brief str pat replace
* @brief str pat replace
*
* @flavor Ruby: String#gsub
*
@ -626,9 +624,7 @@ xy_str_delete_suffix (const char *str, const char *suffix)
static char *
xy_str_strip (const char *str)
{
if (!str)
xy_cant_be_null (str);
xy_cant_be_null (str);
const char *start = str;
while (*start && strchr ("\n\r\v\t\f ", *start))