forked from enlightenment/efl
Eina unicode: Added eina_unicode_strndup.
SVN revision: 56807
This commit is contained in:
parent
5ceb0ce407
commit
9fcf0b3c46
|
@ -46,6 +46,8 @@ EAPI size_t eina_unicode_strnlen(const Eina_Unicode *ustr, int n) EINA_AR
|
|||
|
||||
EAPI Eina_Unicode *eina_unicode_strdup(const Eina_Unicode *text) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_MALLOC;
|
||||
|
||||
EAPI Eina_Unicode *eina_unicode_strndup(const Eina_Unicode *text, size_t n) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_MALLOC;
|
||||
|
||||
EAPI int eina_unicode_strcmp(const Eina_Unicode *a, const Eina_Unicode *b) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1, 2) EINA_PURE;
|
||||
|
||||
EAPI Eina_Unicode *eina_unicode_strcpy(Eina_Unicode *dest, const Eina_Unicode *source) EINA_ARG_NONNULL(1, 2);
|
||||
|
|
|
@ -108,20 +108,31 @@ eina_unicode_strnlen(const Eina_Unicode *ustr, int n)
|
|||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Same as strdup but cuts on n. Assumes n < len
|
||||
* @since 1.1.0
|
||||
*/
|
||||
EAPI Eina_Unicode *
|
||||
eina_unicode_strndup(const Eina_Unicode *text, size_t n)
|
||||
{
|
||||
Eina_Unicode *ustr;
|
||||
|
||||
ustr = (Eina_Unicode *) malloc((n + 1) * sizeof(Eina_Unicode));
|
||||
memcpy(ustr, text, n * sizeof(Eina_Unicode));
|
||||
ustr[n] = 0;
|
||||
return ustr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Same as the standard strdup just with Eina_Unicode instead of char.
|
||||
*/
|
||||
EAPI Eina_Unicode *
|
||||
eina_unicode_strdup(const Eina_Unicode *text)
|
||||
{
|
||||
Eina_Unicode *ustr;
|
||||
size_t len;
|
||||
|
||||
len = eina_unicode_strlen(text);
|
||||
ustr = (Eina_Unicode *)malloc((len + 1) * sizeof(Eina_Unicode));
|
||||
memcpy(ustr, text, len * sizeof(Eina_Unicode));
|
||||
ustr[len] = 0;
|
||||
return ustr;
|
||||
return eina_unicode_strndup(text, len);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue