From de0eef861083d56d1d9d1e34fa5a5eb6893669cf Mon Sep 17 00:00:00 2001 From: discomfitor Date: Sun, 18 Jul 2010 07:39:21 +0000 Subject: [PATCH] +eina_stringshare_replace_length to replace a stringshared string with a given length of another string git-svn-id: http://svn.enlightenment.org/svn/e/trunk/eina@50320 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- src/include/eina_inline_stringshare.x | 33 +++++++++++++++++++++++++++++++-- src/include/eina_stringshare.h | 1 + src/lib/eina_stringshare.c | 2 +- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/include/eina_inline_stringshare.x b/src/include/eina_inline_stringshare.x index 233df99..438218b 100644 --- a/src/include/eina_inline_stringshare.x +++ b/src/include/eina_inline_stringshare.x @@ -26,11 +26,11 @@ */ /** - * Replace the previously stringshared pointer with a new content. + * Replace the previously stringshared pointer with new content. * * The string pointed by @a p_str should be previously stringshared or * @c NULL and it will be eina_stringshare_del(). The new string will - * be eina_stringshare_add() and then assigned to @c *p_str. + * be passed to eina_stringshare_add() and then assigned to @c *p_str. * * @param p_str pointer to the stringhare to be replaced. Must not be * @c NULL, but @c *p_str may be @c NULL as it is a valid @@ -54,6 +54,35 @@ eina_stringshare_replace(const char **p_str, const char *news) } /** + * Replace the previously stringshared pointer with a new content. + * + * The string pointed by @a p_str should be previously stringshared or + * @c NULL and it will be eina_stringshare_del(). The new string will + * be passed to eina_stringshare_add_length() and then assigned to @c *p_str. + * + * @param p_str pointer to the stringhare to be replaced. Must not be + * @c NULL, but @c *p_str may be @c NULL as it is a valid + * stringshare handle. + * @param news new string to be stringshared, may be @c NULL. + * @param slen The string size (<= strlen(str)). + * + * @return #EINA_TRUE if the strings were different and thus replaced, + * #EINA_FALSE if the strings were the same after shared. + */ +static inline Eina_Bool +eina_stringshare_replace_length(const char **p_str, const char *news, unsigned int slen) +{ + if (*p_str == news) return EINA_FALSE; + + news = eina_stringshare_add_length(news, slen); + eina_stringshare_del(*p_str); + if (*p_str == news) + return EINA_FALSE; + *p_str = news; + return EINA_TRUE; +} + +/** * @} */ diff --git a/src/include/eina_stringshare.h b/src/include/eina_stringshare.h index 94c61e6..72b9a1b 100644 --- a/src/include/eina_stringshare.h +++ b/src/include/eina_stringshare.h @@ -73,6 +73,7 @@ EAPI int eina_stringshare_strlen(const char *str) EINA_CONST EINA_WARN_UNUSED_RE EAPI void eina_stringshare_dump(void); static inline Eina_Bool eina_stringshare_replace(const char **p_str, const char *news) EINA_ARG_NONNULL(1); +static inline Eina_Bool eina_stringshare_replace_length(const char **p_str, const char *news, unsigned int slen) EINA_ARG_NONNULL(1); #include "eina_inline_stringshare.x" diff --git a/src/lib/eina_stringshare.c b/src/lib/eina_stringshare.c index a4dd5e5..939c199 100644 --- a/src/lib/eina_stringshare.c +++ b/src/lib/eina_stringshare.c @@ -1101,7 +1101,7 @@ eina_stringshare_threads_shutdown(void) * it is added to the strings to be searched and a duplicated string * of @p str is returned. * - * This function does not check string size, but uses the give the + * This function does not check string size, but uses the * exact given size. This can be used to stringshare part of a larger * buffer or substring. * -- 2.7.4