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
     1.1 --- a/src/cx/string.h	Tue Aug 30 19:34:22 2022 +0200
     1.2 +++ b/src/cx/string.h	Tue Aug 30 19:55:56 2022 +0200
     1.3 @@ -576,21 +576,6 @@
     1.4          cxstring s2
     1.5  );
     1.6  
     1.7 -/**
     1.8 - * Creates a duplicate of the specified string.
     1.9 - *
    1.10 - * The new string will contain a copy allocated by standard
    1.11 - * \c malloc(). So developers \em must pass the return value to cx_strfree().
    1.12 - *
    1.13 - * \note The returned string is guaranteed to be zero-terminated and can safely
    1.14 - * be passed to other APIs.
    1.15 - *
    1.16 - * @param string the string to duplicate
    1.17 - * @return a duplicate of the string
    1.18 - * @see cx_strdup_a()
    1.19 - */
    1.20 -__attribute__((__warn_unused_result__))
    1.21 -cxmutstr cx_strdup(cxstring string);
    1.22  
    1.23  /**
    1.24   * Creates a duplicate of the specified string.
    1.25 @@ -612,6 +597,21 @@
    1.26  );
    1.27  
    1.28  /**
    1.29 + * Creates a duplicate of the specified string.
    1.30 + *
    1.31 + * The new string will contain a copy allocated by standard
    1.32 + * \c malloc(). So developers \em must pass the return value to cx_strfree().
    1.33 + *
    1.34 + * \note The returned string is guaranteed to be zero-terminated and can safely
    1.35 + * be passed to other APIs.
    1.36 + *
    1.37 + * @param string the string to duplicate
    1.38 + * @return a duplicate of the string
    1.39 + * @see cx_strdup_a()
    1.40 + */
    1.41 +#define cx_strdup(string) cx_strdup_a(cxDefaultAllocator, string)
    1.42 +
    1.43 +/**
    1.44   * Omits leading and trailing spaces.
    1.45   *
    1.46   * \note the returned string references the same memory, thus you
    1.47 @@ -717,32 +717,6 @@
    1.48   * The pattern is taken literally and is no regular expression.
    1.49   * Replaces at most \p replmax occurrences.
    1.50   *
    1.51 - * The returned string will be allocated by \c malloc() and \em must be passed
    1.52 - * to cx_strfree() eventually.
    1.53 - *
    1.54 - * If allocation fails, or the input string is empty,
    1.55 - * the returned string will point to \c NULL.
    1.56 - *
    1.57 - * @param str the string where replacements should be applied
    1.58 - * @param pattern the pattern to search for
    1.59 - * @param replacement the replacement string
    1.60 - * @param replmax maximum number of replacements
    1.61 - * @return the resulting string after applying the replacements
    1.62 - */
    1.63 -__attribute__((__warn_unused_result__))
    1.64 -cxmutstr cx_strreplace(
    1.65 -        cxstring str,
    1.66 -        cxstring pattern,
    1.67 -        cxstring replacement,
    1.68 -        size_t replmax
    1.69 -);
    1.70 -
    1.71 -/**
    1.72 - * Replaces a pattern in a string with another string.
    1.73 - *
    1.74 - * The pattern is taken literally and is no regular expression.
    1.75 - * Replaces at most \p replmax occurrences.
    1.76 - *
    1.77   * The returned string will be allocated by \p allocator.
    1.78   *
    1.79   * If allocation fails, or the input string is empty,
    1.80 @@ -764,6 +738,27 @@
    1.81          size_t replmax
    1.82  );
    1.83  
    1.84 +/**
    1.85 + * Replaces a pattern in a string with another string.
    1.86 + *
    1.87 + * The pattern is taken literally and is no regular expression.
    1.88 + * Replaces at most \p replmax occurrences.
    1.89 + *
    1.90 + * The returned string will be allocated by \c malloc() and \em must be passed
    1.91 + * to cx_strfree() eventually.
    1.92 + *
    1.93 + * If allocation fails, or the input string is empty,
    1.94 + * the returned string will point to \c NULL.
    1.95 + *
    1.96 + * @param str the string where replacements should be applied
    1.97 + * @param pattern the pattern to search for
    1.98 + * @param replacement the replacement string
    1.99 + * @param replmax maximum number of replacements
   1.100 + * @return the resulting string after applying the replacements
   1.101 + */
   1.102 +#define cx_strreplace(str, pattern, replacement, replmax) \
   1.103 +cx_strreplace_a(cxDefaultAllocator, str, pattern, replacement, replmax)
   1.104 +
   1.105  #ifdef __cplusplus
   1.106  } // extern "C"
   1.107  #endif

mercurial