forked from enlightenment/efl
Eina stringshare: Added Eina_Stringshare a stringshare visual hint.
It's interchangeable with const char *, it's juts there as a visual hint for functions expecting stringshared values. Docs are not enough... SVN revision: 67641
This commit is contained in:
parent
56dc6e9571
commit
ade018086c
|
@ -212,3 +212,9 @@
|
||||||
* Added EINA_C_ARRAY_LENGTH, a macro that returns the length of a
|
* Added EINA_C_ARRAY_LENGTH, a macro that returns the length of a
|
||||||
standard C array.
|
standard C array.
|
||||||
|
|
||||||
|
2012-01-31 Tom Hacohen
|
||||||
|
|
||||||
|
* Added an Eina_Stringshare type. It's just a typedef of "const char *"
|
||||||
|
this is a same kind of visual hint for the purpose of the pointer,
|
||||||
|
but again, the two types are interchangeable.
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
* #EINA_FALSE if the strings were the same after shared.
|
* #EINA_FALSE if the strings were the same after shared.
|
||||||
*/
|
*/
|
||||||
static inline Eina_Bool
|
static inline Eina_Bool
|
||||||
eina_stringshare_replace(const char **p_str, const char *news)
|
eina_stringshare_replace(Eina_Stringshare *p_str, Eina_Stringshare news)
|
||||||
{
|
{
|
||||||
if (*p_str == news) return EINA_FALSE;
|
if (*p_str == news) return EINA_FALSE;
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ eina_stringshare_replace(const char **p_str, const char *news)
|
||||||
* #EINA_FALSE if the strings were the same after shared.
|
* #EINA_FALSE if the strings were the same after shared.
|
||||||
*/
|
*/
|
||||||
static inline Eina_Bool
|
static inline Eina_Bool
|
||||||
eina_stringshare_replace_length(const char **p_str, const char *news, unsigned int slen)
|
eina_stringshare_replace_length(Eina_Stringshare *p_str, Eina_Stringshare news, unsigned int slen)
|
||||||
{
|
{
|
||||||
if (*p_str == news) return EINA_FALSE;
|
if (*p_str == news) return EINA_FALSE;
|
||||||
|
|
||||||
|
|
|
@ -148,6 +148,15 @@
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef Eina_Stringshare
|
||||||
|
*
|
||||||
|
* Interchangeable with "const char *" but still a good visual hint for the
|
||||||
|
* purpose. Maybe in the far far future we'll even add strict type checking.
|
||||||
|
*
|
||||||
|
* @since 1.2.0
|
||||||
|
*/
|
||||||
|
typedef const char * Eina_Stringshare;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Retrieve an instance of a string for use in a program.
|
* @brief Retrieve an instance of a string for use in a program.
|
||||||
|
@ -168,7 +177,7 @@
|
||||||
*
|
*
|
||||||
* @see eina_share_common_add()
|
* @see eina_share_common_add()
|
||||||
*/
|
*/
|
||||||
EAPI const char *eina_stringshare_add_length(const char *str, unsigned int slen) EINA_WARN_UNUSED_RESULT;
|
EAPI Eina_Stringshare eina_stringshare_add_length(const char *str, unsigned int slen) EINA_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Retrieve an instance of a string for use in a program.
|
* @brief Retrieve an instance of a string for use in a program.
|
||||||
|
@ -188,7 +197,7 @@ EAPI const char *eina_stringshare_add_length(const char *str, unsigned in
|
||||||
*
|
*
|
||||||
* @see eina_stringshare_add_length()
|
* @see eina_stringshare_add_length()
|
||||||
*/
|
*/
|
||||||
EAPI const char *eina_stringshare_add(const char *str) EINA_WARN_UNUSED_RESULT;
|
EAPI Eina_Stringshare eina_stringshare_add(const char *str) EINA_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Retrieve an instance of a string for use in a program
|
* @brief Retrieve an instance of a string for use in a program
|
||||||
|
@ -209,7 +218,7 @@ EAPI const char *eina_stringshare_add(const char *str) EINA_WARN_UNUSED_R
|
||||||
*
|
*
|
||||||
* @see eina_stringshare_nprintf()
|
* @see eina_stringshare_nprintf()
|
||||||
*/
|
*/
|
||||||
EAPI const char *eina_stringshare_printf(const char *fmt, ...) EINA_WARN_UNUSED_RESULT EINA_PRINTF(1, 2);
|
EAPI Eina_Stringshare eina_stringshare_printf(const char *fmt, ...) EINA_WARN_UNUSED_RESULT EINA_PRINTF(1, 2);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Retrieve an instance of a string for use in a program
|
* @brief Retrieve an instance of a string for use in a program
|
||||||
|
@ -231,7 +240,7 @@ EAPI const char *eina_stringshare_printf(const char *fmt, ...) EINA_WARN_
|
||||||
*
|
*
|
||||||
* @see eina_stringshare_nprintf()
|
* @see eina_stringshare_nprintf()
|
||||||
*/
|
*/
|
||||||
EAPI const char *eina_stringshare_vprintf(const char *fmt, va_list args) EINA_WARN_UNUSED_RESULT;
|
EAPI Eina_Stringshare eina_stringshare_vprintf(const char *fmt, va_list args) EINA_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Retrieve an instance of a string for use in a program
|
* @brief Retrieve an instance of a string for use in a program
|
||||||
|
@ -251,7 +260,7 @@ EAPI const char *eina_stringshare_vprintf(const char *fmt, va_list args)
|
||||||
*
|
*
|
||||||
* @see eina_stringshare_printf()
|
* @see eina_stringshare_printf()
|
||||||
*/
|
*/
|
||||||
EAPI const char *eina_stringshare_nprintf(unsigned int len, const char *fmt, ...) EINA_WARN_UNUSED_RESULT EINA_PRINTF(2, 3);
|
EAPI Eina_Stringshare eina_stringshare_nprintf(unsigned int len, const char *fmt, ...) EINA_WARN_UNUSED_RESULT EINA_PRINTF(2, 3);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increment references of the given shared string.
|
* Increment references of the given shared string.
|
||||||
|
@ -267,7 +276,7 @@ EAPI const char *eina_stringshare_nprintf(unsigned int len, const char *f
|
||||||
*
|
*
|
||||||
* There is no unref since this is the work of eina_share_common_del().
|
* There is no unref since this is the work of eina_share_common_del().
|
||||||
*/
|
*/
|
||||||
EAPI const char *eina_stringshare_ref(const char *str);
|
EAPI Eina_Stringshare eina_stringshare_ref(Eina_Stringshare str);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Note that the given string has lost an instance.
|
* @brief Note that the given string has lost an instance.
|
||||||
|
@ -282,7 +291,7 @@ EAPI const char *eina_stringshare_ref(const char *str);
|
||||||
* Note that if the given pointer is not shared or NULL, bad things
|
* Note that if the given pointer is not shared or NULL, bad things
|
||||||
* will happen, likely a segmentation fault.
|
* will happen, likely a segmentation fault.
|
||||||
*/
|
*/
|
||||||
EAPI void eina_stringshare_del(const char *str);
|
EAPI void eina_stringshare_del(Eina_Stringshare str);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Note that the given string @b must be shared.
|
* @brief Note that the given string @b must be shared.
|
||||||
|
@ -296,7 +305,7 @@ EAPI void eina_stringshare_del(const char *str);
|
||||||
* things will happen, likely a segmentation fault. If in doubt, try
|
* things will happen, likely a segmentation fault. If in doubt, try
|
||||||
* strlen().
|
* strlen().
|
||||||
*/
|
*/
|
||||||
EAPI int eina_stringshare_strlen(const char *str) EINA_PURE EINA_WARN_UNUSED_RESULT;
|
EAPI int eina_stringshare_strlen(Eina_Stringshare str) EINA_PURE EINA_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Dump the contents of the share_common.
|
* @brief Dump the contents of the share_common.
|
||||||
|
@ -306,8 +315,8 @@ EAPI int eina_stringshare_strlen(const char *str) EINA_PURE EINA_
|
||||||
*/
|
*/
|
||||||
EAPI void eina_stringshare_dump(void);
|
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(Eina_Stringshare *p_str, Eina_Stringshare 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);
|
static inline Eina_Bool eina_stringshare_replace_length(Eina_Stringshare *p_str, Eina_Stringshare news, unsigned int slen) EINA_ARG_NONNULL(1);
|
||||||
|
|
||||||
#include "eina_inline_stringshare.x"
|
#include "eina_inline_stringshare.x"
|
||||||
|
|
||||||
|
|
|
@ -577,7 +577,7 @@ eina_stringshare_shutdown(void)
|
||||||
*============================================================================*/
|
*============================================================================*/
|
||||||
|
|
||||||
EAPI void
|
EAPI void
|
||||||
eina_stringshare_del(const char *str)
|
eina_stringshare_del(Eina_Stringshare str)
|
||||||
{
|
{
|
||||||
int slen;
|
int slen;
|
||||||
|
|
||||||
|
@ -611,13 +611,13 @@ eina_stringshare_del(const char *str)
|
||||||
CRITICAL("EEEK trying to del non-shared stringshare \"%s\"", str);
|
CRITICAL("EEEK trying to del non-shared stringshare \"%s\"", str);
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI const char *
|
EAPI Eina_Stringshare
|
||||||
eina_stringshare_add_length(const char *str, unsigned int slen)
|
eina_stringshare_add_length(const char *str, unsigned int slen)
|
||||||
{
|
{
|
||||||
if ((!str) || (slen <= 0))
|
if ((!str) || (slen <= 0))
|
||||||
return "";
|
return "";
|
||||||
else if (slen == 1)
|
else if (slen == 1)
|
||||||
return (const char *)_eina_stringshare_single + ((*str) << 1);
|
return (Eina_Stringshare) _eina_stringshare_single + ((*str) << 1);
|
||||||
else if (slen < 4)
|
else if (slen < 4)
|
||||||
{
|
{
|
||||||
const char *s;
|
const char *s;
|
||||||
|
@ -632,7 +632,7 @@ eina_stringshare_add_length(const char *str, unsigned int slen)
|
||||||
sizeof(char), sizeof(char));
|
sizeof(char), sizeof(char));
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI const char *
|
EAPI Eina_Stringshare
|
||||||
eina_stringshare_add(const char *str)
|
eina_stringshare_add(const char *str)
|
||||||
{
|
{
|
||||||
int slen;
|
int slen;
|
||||||
|
@ -653,7 +653,7 @@ eina_stringshare_add(const char *str)
|
||||||
return eina_stringshare_add_length(str, slen);
|
return eina_stringshare_add_length(str, slen);
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI const char *
|
EAPI Eina_Stringshare
|
||||||
eina_stringshare_printf(const char *fmt, ...)
|
eina_stringshare_printf(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
|
@ -677,7 +677,7 @@ eina_stringshare_printf(const char *fmt, ...)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI const char *
|
EAPI Eina_Stringshare
|
||||||
eina_stringshare_vprintf(const char *fmt, va_list args)
|
eina_stringshare_vprintf(const char *fmt, va_list args)
|
||||||
{
|
{
|
||||||
char *tmp;
|
char *tmp;
|
||||||
|
@ -698,7 +698,7 @@ eina_stringshare_vprintf(const char *fmt, va_list args)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI const char *
|
EAPI Eina_Stringshare
|
||||||
eina_stringshare_nprintf(unsigned int len, const char *fmt, ...)
|
eina_stringshare_nprintf(unsigned int len, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
|
@ -723,8 +723,8 @@ eina_stringshare_nprintf(unsigned int len, const char *fmt, ...)
|
||||||
return eina_stringshare_add_length(tmp, len);
|
return eina_stringshare_add_length(tmp, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI const char *
|
EAPI Eina_Stringshare
|
||||||
eina_stringshare_ref(const char *str)
|
eina_stringshare_ref(Eina_Stringshare str)
|
||||||
{
|
{
|
||||||
int slen;
|
int slen;
|
||||||
|
|
||||||
|
@ -765,7 +765,7 @@ eina_stringshare_ref(const char *str)
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI int
|
EAPI int
|
||||||
eina_stringshare_strlen(const char *str)
|
eina_stringshare_strlen(Eina_Stringshare str)
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
/* special cases */
|
/* special cases */
|
||||||
|
@ -781,7 +781,7 @@ eina_stringshare_strlen(const char *str)
|
||||||
if (str[3] == '\0')
|
if (str[3] == '\0')
|
||||||
return 3;
|
return 3;
|
||||||
|
|
||||||
len = eina_share_common_length(stringshare_share, (const char *)str);
|
len = eina_share_common_length(stringshare_share, (Eina_Stringshare) str);
|
||||||
len = (len > 0) ? len / (int)sizeof(char) : -1;
|
len = (len > 0) ? len / (int)sizeof(char) : -1;
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue