summaryrefslogtreecommitdiff
path: root/src/lib/eina
diff options
context:
space:
mode:
authorMarcel Hollerbach <marcel-hollerbach@t-online.de>2017-01-03 10:52:27 +0100
committerMarcel Hollerbach <marcel-hollerbach@t-online.de>2017-01-05 14:08:23 +0100
commit2f1d0fb18924b5c100dd2a5b149b4af505c87566 (patch)
treeea9f0fff3e50f54d1670ff4e7db727109b8df7ca /src/lib/eina
parente998529f2e20ca70bf1ebc463473aedab153f84e (diff)
eina_strbuf: add eina_strbuf_free_return
Summary: For a function which just composes a string with strbuf its quite usefull to return the string while its freed. This makes a function like: { Eina_Strbuf *buf; char *path; buf = eina_strbuf_new(); eina_strbuf_append(buf, "test"); eina_strbuf_append_printf(buf, "%s-%d.edj", "test", 0); path = eina_strbuf_string_steal(buf); eina_strbuf_free(buf); return path; } To: { Eina_Strbuf *buf; buf = eina_strbuf_new(); eina_strbuf_append(buf, "test"); eina_strbuf_append_printf(buf, "%s-%d.edj", "test", 0); return eina_strbuf_free_return(buf); } Which is a bit more handy. Test Plan: just run make check Reviewers: raster, cedric Subscribers: jpeg Differential Revision: https://phab.enlightenment.org/D4545
Diffstat (limited to 'src/lib/eina')
-rw-r--r--src/lib/eina/eina_strbuf.c11
-rw-r--r--src/lib/eina/eina_strbuf.h13
2 files changed, 24 insertions, 0 deletions
diff --git a/src/lib/eina/eina_strbuf.c b/src/lib/eina/eina_strbuf.c
index 81ab30a45f..b784a701ab 100644
--- a/src/lib/eina/eina_strbuf.c
+++ b/src/lib/eina/eina_strbuf.c
@@ -220,6 +220,17 @@ eina_strbuf_substr_get(Eina_Strbuf *buf, size_t pos, size_t len)
220 return eina_strbuf_manage_new(str); 220 return eina_strbuf_manage_new(str);
221} 221}
222 222
223EAPI char*
224eina_strbuf_free_return(Eina_Strbuf *buf)
225{
226 char *result;
227
228 result = eina_strbuf_string_steal(buf);
229 eina_strbuf_free(buf);
230
231 return result;
232}
233
223/* Unicode */ 234/* Unicode */
224 235
225#include "eina_strbuf_template_c.x" 236#include "eina_strbuf_template_c.x"
diff --git a/src/lib/eina/eina_strbuf.h b/src/lib/eina/eina_strbuf.h
index 94d16f8c3a..9c2506c816 100644
--- a/src/lib/eina/eina_strbuf.h
+++ b/src/lib/eina/eina_strbuf.h
@@ -718,6 +718,19 @@ EAPI Eina_Slice eina_strbuf_slice_get(const Eina_Strbuf *buf) EINA_WARN_UNUSED_R
718 */ 718 */
719EAPI Eina_Rw_Slice eina_strbuf_rw_slice_get(const Eina_Strbuf *buf) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1); 719EAPI Eina_Rw_Slice eina_strbuf_rw_slice_get(const Eina_Strbuf *buf) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1);
720 720
721
722/**
723 * @brief Get the string of the buffer and free the buffer
724 *
725 * @param buf the buffer to get the string from and which will be freed
726 *
727 * @return The string contained by bug. The caller must release the memory of the returned string by calling
728 * free().
729 *
730 * @since 1.19
731 */
732EAPI char* eina_strbuf_free_return(Eina_Strbuf *buf) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1);
733
721/** 734/**
722 * @} 735 * @}
723 */ 736 */