Unicode String

These functions provide basic unicode string handling. More...

Typedefs

typedef wchar_t Eina_Unicode
 A type that holds Unicode codepoints.
 

Functions

EAPI size_t eina_unicode_strlen (const Eina_Unicode *ustr) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT EINA_PURE
 
EAPI size_t eina_unicode_strnlen (const Eina_Unicode *ustr, int n) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT EINA_PURE
 Returns the length of a Eina_Unicode string, up to a limit. More...
 
EAPI Eina_Unicodeeina_unicode_strdup (const Eina_Unicode *text) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_MALLOC
 Same as the standard strdup just with Eina_Unicode instead of char.
 
EAPI Eina_Unicodeeina_unicode_strndup (const Eina_Unicode *text, size_t n) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_MALLOC
 Same as strdup but cuts on the given size. More...
 
EAPI int eina_unicode_strcmp (const Eina_Unicode *a, const Eina_Unicode *b) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1
 Same as the standard strcmp just with Eina_Unicode instead of char.
 
EAPI Eina_Unicodeeina_unicode_strcpy (Eina_Unicode *dest, const Eina_Unicode *source) EINA_ARG_NONNULL(1
 Same as the standard strcpy just with Eina_Unicode instead of char.
 
EAPI Eina_Unicode EAPI Eina_Unicodeeina_unicode_strstr (const Eina_Unicode *haystack, const Eina_Unicode *needle) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1
 Same as the standard strstr just with Eina_Unicode instead of char.
 
EAPI Eina_Unicodeeina_unicode_strncpy (Eina_Unicode *dest, const Eina_Unicode *source, size_t n) EINA_ARG_NONNULL(1
 Same as the standard strncpy just with Eina_Unicode instead of char.
 
EAPI Eina_Unicode EAPI Eina_Unicodeeina_unicode_escape (const Eina_Unicode *str) EINA_ARG_NONNULL(1) EINA_MALLOC EINA_WARN_UNUSED_RESULT
 
static Eina_Unicode eina_unicode_utf8_next_get (const char *buf, int *iindex) EINA_ARG_NONNULL(1
 Reads UTF8 bytes from buf, starting at iindex and returns the decoded code point at iindex offset, and advances iindex to the next code point after this. More...
 
static Eina_Unicode EAPI Eina_Unicode eina_unicode_utf8_get_next (const char *buf, int *iindex) EINA_ARG_NONNULL(1
 Reads UTF8 bytes from buf, starting at iindex and returns the decoded code point at iindex offset, and advances iindex to the next code point after this. More...
 
EAPI Eina_Unicode eina_unicode_utf8_get_prev (const char *buf, int *iindex) EINA_ARG_NONNULL(1
 Reads UTF8 bytes from buf, starting at iindex and returns the decoded code point at iindex offset, and moves àp iindex to the previous code point. More...
 
EAPI Eina_Unicode EAPI int eina_unicode_utf8_get_len (const char *buf) EINA_ARG_NONNULL(1)
 Returns the number of unicode characters in the string. More...
 
EAPI Eina_Unicodeeina_unicode_utf8_to_unicode (const char *utf, int *_len) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_MALLOC
 Converts a utf-8 string to a newly allocated Eina_Unicode string. More...
 
EAPI char * eina_unicode_unicode_to_utf8 (const Eina_Unicode *uni, int *_len) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_MALLOC
 Converts an Eina_Unicode string to a newly allocated utf-8 string. More...
 

Variables

EAPI const Eina_UnicodeEINA_UNICODE_EMPTY_STRING
 Same as the standard strlen just with Eina_Unicode instead of char.
 
EAPI int EINA_PURE
 
static Eina_Unicode EAPI Eina_Unicode EINA_DEPRECATED
 

Detailed Description

These functions provide basic unicode string handling.

Eina_Unicode is a type that holds unicode codepoints.

Function Documentation

◆ eina_unicode_strnlen()

EAPI size_t eina_unicode_strnlen ( const Eina_Unicode ustr,
int  n 
)

Returns the length of a Eina_Unicode string, up to a limit.

This function returns the number of characters in string, up to a maximum of n. If the terminating character is not found in the string, it returns n.

Parameters
ustrString to search
nMax length to search
Returns
Number of characters or n.

◆ eina_unicode_strndup()

EAPI Eina_Unicode* eina_unicode_strndup ( const Eina_Unicode text,
size_t  n 
)

Same as strdup but cuts on the given size.

Assumes n < len

Parameters
textThe text to duplicate.
nThe maximum size of the text to duplicate.
Returns
The duplicated string.

This function duplicates text. The resuting string is cut on n. n is assumed to be lesser (<) than the length of text. When not needed anymore, the returned string must be freed.

Since
1.1.0

Referenced by evas_object_textblock_text_markup_get().

◆ eina_unicode_escape()

EAPI Eina_Unicode EAPI Eina_Unicode* eina_unicode_escape ( const Eina_Unicode str)
See also
eina_str_escape()
Parameters
strThe string to escape.
Returns
The escaped string.

◆ eina_unicode_utf8_next_get()

static Eina_Unicode eina_unicode_utf8_next_get ( const char *  buf,
int *  iindex 
)
inlinestatic

Reads UTF8 bytes from buf, starting at iindex and returns the decoded code point at iindex offset, and advances iindex to the next code point after this.

iindex is always advanced, unless if the advancement is after the NULL. On error: return a codepoint between DC80 to DCFF where the low 8 bits are the byte's value.

Parameters
bufthe string
iindexthe index to look at and return by.
Returns
the codepoint found, 0 if buf or iindex are NULL
Since
1.8.0

Referenced by evas_string_char_next_get().

◆ eina_unicode_utf8_get_next()

static Eina_Unicode EAPI Eina_Unicode eina_unicode_utf8_get_next ( const char *  buf,
int *  iindex 
)

Reads UTF8 bytes from buf, starting at iindex and returns the decoded code point at iindex offset, and advances iindex to the next code point after this.

iindex is always advanced, unless if the advancement is after the NULL. On error: return a codepoint between DC80 to DCFF where the low 8 bits are the byte's value.

Parameters
bufthe string
iindexthe index to look at and return by.
Returns
the codepoint found, 0 if buf or iindex are NULL
Since
1.1.0
Deprecated:
use eina_unicode_utf8_next_get

◆ eina_unicode_utf8_get_prev()

EAPI Eina_Unicode eina_unicode_utf8_get_prev ( const char *  buf,
int *  iindex 
)

Reads UTF8 bytes from buf, starting at iindex and returns the decoded code point at iindex offset, and moves àp iindex to the previous code point.

iindex is always moved, as long as it's not past the start of the string. On error: return a codepoint between DC80 to DCFF where the low 8 bits are the byte's value.

Parameters
bufthe string
iindexthe index to look at and return by.
Returns
the codepoint found.
Since
1.1.0

Referenced by evas_string_char_prev_get().

◆ eina_unicode_utf8_get_len()

EAPI Eina_Unicode EAPI int eina_unicode_utf8_get_len ( const char *  buf)

Returns the number of unicode characters in the string.

That is, the number of Eina_Unicodes it'll take to store this string in an Eina_Unicode string.

Parameters
bufthe string
Returns
the number of unicode characters (not bytes) in the string
Since
1.1.0

Referenced by evas_string_char_len_get().

◆ eina_unicode_utf8_to_unicode()

EAPI Eina_Unicode* eina_unicode_utf8_to_unicode ( const char *  utf,
int *  _len 
)

Converts a utf-8 string to a newly allocated Eina_Unicode string.

Parameters
utfthe string in utf-8
_lenthe length of the returned Eina_Unicode string.
Returns
the newly allocated Eina_Unicode string.
Since
1.1.0

Referenced by evas_object_text_text_set(), and evas_textblock_cursor_text_append().

◆ eina_unicode_unicode_to_utf8()

EAPI char* eina_unicode_unicode_to_utf8 ( const Eina_Unicode uni,
int *  _len 
)

Converts an Eina_Unicode string to a newly allocated utf-8 string.

Parameters
unithe Eina_Unicode string
_lenthe length byte length of the return utf8 string.
Returns
the newly allocated utf-8 string.
Since
1.1.0

Referenced by evas_object_textblock_replace_char_get(), evas_object_textblock_text_markup_prepend(), and evas_textblock_cursor_content_get().