# HG changeset patch # User Mike Becker # Date 1661882156 -7200 # Node ID 0b2c0cb280a95b3410574f943227624fb093b470 # Parent 26447d59a5abdf000b857bb30f10b2c86b55091c some function can be macros using the default allocator diff -r 26447d59a5ab -r 0b2c0cb280a9 src/cx/string.h --- a/src/cx/string.h Tue Aug 30 19:34:22 2022 +0200 +++ b/src/cx/string.h Tue Aug 30 19:55:56 2022 +0200 @@ -576,21 +576,6 @@ cxstring s2 ); -/** - * Creates a duplicate of the specified string. - * - * The new string will contain a copy allocated by standard - * \c malloc(). So developers \em must pass the return value to cx_strfree(). - * - * \note The returned string is guaranteed to be zero-terminated and can safely - * be passed to other APIs. - * - * @param string the string to duplicate - * @return a duplicate of the string - * @see cx_strdup_a() - */ -__attribute__((__warn_unused_result__)) -cxmutstr cx_strdup(cxstring string); /** * Creates a duplicate of the specified string. @@ -612,6 +597,21 @@ ); /** + * Creates a duplicate of the specified string. + * + * The new string will contain a copy allocated by standard + * \c malloc(). So developers \em must pass the return value to cx_strfree(). + * + * \note The returned string is guaranteed to be zero-terminated and can safely + * be passed to other APIs. + * + * @param string the string to duplicate + * @return a duplicate of the string + * @see cx_strdup_a() + */ +#define cx_strdup(string) cx_strdup_a(cxDefaultAllocator, string) + +/** * Omits leading and trailing spaces. * * \note the returned string references the same memory, thus you @@ -717,32 +717,6 @@ * The pattern is taken literally and is no regular expression. * Replaces at most \p replmax occurrences. * - * The returned string will be allocated by \c malloc() and \em must be passed - * to cx_strfree() eventually. - * - * If allocation fails, or the input string is empty, - * the returned string will point to \c NULL. - * - * @param str the string where replacements should be applied - * @param pattern the pattern to search for - * @param replacement the replacement string - * @param replmax maximum number of replacements - * @return the resulting string after applying the replacements - */ -__attribute__((__warn_unused_result__)) -cxmutstr cx_strreplace( - cxstring str, - cxstring pattern, - cxstring replacement, - size_t replmax -); - -/** - * Replaces a pattern in a string with another string. - * - * The pattern is taken literally and is no regular expression. - * Replaces at most \p replmax occurrences. - * * The returned string will be allocated by \p allocator. * * If allocation fails, or the input string is empty, @@ -764,6 +738,27 @@ size_t replmax ); +/** + * Replaces a pattern in a string with another string. + * + * The pattern is taken literally and is no regular expression. + * Replaces at most \p replmax occurrences. + * + * The returned string will be allocated by \c malloc() and \em must be passed + * to cx_strfree() eventually. + * + * If allocation fails, or the input string is empty, + * the returned string will point to \c NULL. + * + * @param str the string where replacements should be applied + * @param pattern the pattern to search for + * @param replacement the replacement string + * @param replmax maximum number of replacements + * @return the resulting string after applying the replacements + */ +#define cx_strreplace(str, pattern, replacement, replmax) \ +cx_strreplace_a(cxDefaultAllocator, str, pattern, replacement, replmax) + #ifdef __cplusplus } // extern "C" #endif