eina_stringshare: add slice_get()
This commit is contained in:
parent
9062bbd8e0
commit
77faebde67
|
@ -116,6 +116,23 @@ eina_stringshare_replace_length(Eina_Stringshare **p_str, const char *news, unsi
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the read-only memory slice for this stringshare.
|
||||||
|
*
|
||||||
|
* @param str the stringshare to get a slice.
|
||||||
|
* @return A read-only slice.
|
||||||
|
*/
|
||||||
|
static inline Eina_Slice
|
||||||
|
eina_stringshare_slice_get(Eina_Stringshare *str)
|
||||||
|
{
|
||||||
|
Eina_Slice ret;
|
||||||
|
|
||||||
|
ret.len = eina_stringshare_strlen(str);
|
||||||
|
ret.mem = str;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -54,6 +54,7 @@
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
#include "eina_types.h"
|
#include "eina_types.h"
|
||||||
|
#include "eina_slice.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @page eina_stringshare_example_01_page
|
* @page eina_stringshare_example_01_page
|
||||||
|
@ -335,6 +336,8 @@ EAPI void eina_stringshare_dump(void);
|
||||||
static inline Eina_Bool eina_stringshare_replace(Eina_Stringshare **p_str, const char *news) EINA_ARG_NONNULL(1);
|
static inline Eina_Bool eina_stringshare_replace(Eina_Stringshare **p_str, const char *news) EINA_ARG_NONNULL(1);
|
||||||
static inline Eina_Bool eina_stringshare_replace_length(Eina_Stringshare **p_str, const char *news, unsigned int slen) EINA_ARG_NONNULL(1);
|
static inline Eina_Bool eina_stringshare_replace_length(Eina_Stringshare **p_str, const char *news, unsigned int slen) EINA_ARG_NONNULL(1);
|
||||||
|
|
||||||
|
static inline Eina_Slice eina_stringshare_slice_get(Eina_Stringshare *str) EINA_PURE EINA_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
#include "eina_inline_stringshare.x"
|
#include "eina_inline_stringshare.x"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -36,6 +36,7 @@ START_TEST(eina_stringshare_simple)
|
||||||
{
|
{
|
||||||
const char *t0;
|
const char *t0;
|
||||||
const char *t1;
|
const char *t1;
|
||||||
|
Eina_Slice slice;
|
||||||
|
|
||||||
eina_init();
|
eina_init();
|
||||||
|
|
||||||
|
@ -53,6 +54,10 @@ START_TEST(eina_stringshare_simple)
|
||||||
fail_if(t0 == NULL);
|
fail_if(t0 == NULL);
|
||||||
fail_if((int)strlen(TEST0) != eina_stringshare_strlen(t0));
|
fail_if((int)strlen(TEST0) != eina_stringshare_strlen(t0));
|
||||||
|
|
||||||
|
slice = eina_stringshare_slice_get(t0);
|
||||||
|
fail_if(slice.mem != t0);
|
||||||
|
fail_if(slice.len != strlen(TEST0));
|
||||||
|
|
||||||
eina_stringshare_del(t0);
|
eina_stringshare_del(t0);
|
||||||
eina_stringshare_del(t0);
|
eina_stringshare_del(t0);
|
||||||
eina_stringshare_del(t1);
|
eina_stringshare_del(t1);
|
||||||
|
|
Loading…
Reference in New Issue