some function can be macros using the default allocator

Tue, 30 Aug 2022 19:55:56 +0200

author
Mike Becker <universe@uap-core.de>
date
Tue, 30 Aug 2022 19:55:56 +0200
changeset 578
0b2c0cb280a9
parent 577
26447d59a5ab
child 579
bbc46dcd5255

some function can be macros using the default allocator

src/cx/string.h file | annotate | diff | comparison | revisions
--- 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

mercurial