forked from enlightenment/efl
eina: add eina_slstr_copy_new_length.
Reviewers: SanghyeonLee, bu5hm4n, zmike, segfaultxavi, lauromoura, felipealmeida, raster Reviewed By: bu5hm4n, zmike Subscribers: #reviewers, #committers Tags: #efl Maniphest Tasks: T7832 Differential Revision: https://phab.enlightenment.org/D8800
This commit is contained in:
parent
202c945bd3
commit
2a3bf30abc
|
@ -108,6 +108,23 @@ eina_slstr_copy_new(const char *string)
|
|||
return copy;
|
||||
}
|
||||
|
||||
EAPI Eina_Slstr *
|
||||
eina_slstr_copy_new_length(const char *string, size_t len)
|
||||
{
|
||||
Eina_FreeQ *fq;
|
||||
char *copy;
|
||||
|
||||
if (!string) return NULL;
|
||||
|
||||
fq = _slstr_freeq_get(EINA_FALSE);
|
||||
EINA_SAFETY_ON_NULL_RETURN_VAL(fq, NULL);
|
||||
|
||||
copy = eina_strndup(string, len);
|
||||
if (!copy) return NULL;
|
||||
eina_freeq_ptr_add(fq, copy, free, len);
|
||||
return copy;
|
||||
}
|
||||
|
||||
EAPI Eina_Slstr *
|
||||
eina_slstr_steal_new(char *string)
|
||||
{
|
||||
|
|
|
@ -51,6 +51,25 @@ typedef const char Eina_Slstr;
|
|||
EAPI Eina_Slstr *
|
||||
eina_slstr_copy_new(const char *string);
|
||||
|
||||
/**
|
||||
* @brief Create a new short lived string by duplicating another string.
|
||||
*
|
||||
* @param[in] string An existing string, it will be copied.
|
||||
* @param[in] len How many charactere max to copy.
|
||||
* @return A new Eina_Slstr or NULL if out of memory.
|
||||
*
|
||||
* Usage example:
|
||||
* @code
|
||||
* char local[200];
|
||||
* sprintf(local, "Hello %d", value);
|
||||
* return eina_slstr_copy_new_length(local, 5);
|
||||
* @endcode
|
||||
*
|
||||
* @since 1.19
|
||||
*/
|
||||
EAPI Eina_Slstr *
|
||||
eina_slstr_copy_new_length(const char *string, size_t len);
|
||||
|
||||
/**
|
||||
* @brief Create a new short lived string by taking ownership of a string.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue