Tizen Native API
|
Functions | |
size_t | eina_strlcpy (char *dst, const char *src, size_t siz) |
Copy a c-string to another. | |
size_t | eina_strlcat (char *dst, const char *src, size_t siz) |
Append a c-string. | |
Eina_Bool | eina_str_has_prefix (const char *str, const char *prefix) |
Check if the given string has the given prefix. | |
Eina_Bool | eina_str_has_suffix (const char *str, const char *suffix) |
Check if the given string has the given suffix. | |
Eina_Bool | eina_str_has_extension (const char *str, const char *ext) |
Check if the given string has the given extension. | |
char ** | eina_str_split (const char *string, const char *delimiter, int max_tokens) |
Split a string using a delimiter. | |
char ** | eina_str_split_full (const char *string, const char *delimiter, int max_tokens, unsigned int *elements) |
Split a string using a delimiter and returns number of elements. | |
size_t | eina_str_join_len (char *dst, size_t size, char sep, const char *a, size_t a_len, const char *b, size_t b_len) |
Join two strings of known length. | |
char * | eina_str_convert (const char *enc_from, const char *enc_to, const char *text) |
Use Iconv to convert a text string from one encoding to another. | |
char * | eina_str_escape (const char *str) |
Escape slashes, spaces and apostrophes in strings. | |
void | eina_str_tolower (char **str) |
Lowercase all the characters in range [A-Z] in the given string. | |
void | eina_str_toupper (char **str) |
Uppercase all the characters in range [a-z] in the given string. | |
static size_t | eina_str_join (char *dst, size_t size, char sep, const char *a, const char *b) |
Join two strings of known length. | |
static size_t | eina_strlen_bounded (const char *str, size_t maxlen) |
Count up to a given amount of bytes of the given string. | |
Defines | |
#define | eina_str_join_static(dst, sep, a, b) eina_str_join_len(dst, sizeof(dst), sep, a, (sizeof(a) > 0) ? sizeof(a) - 1 : 0, b, (sizeof(b) > 0) ? sizeof(b) - 1 : 0) |
Join two static strings and store the result in a static buffer. |
Provide useful functions for C string manipulation.
This group of functions allow you to more easily manipulate strings, they provide functionality not available through string.h.
- Warning:
- Since these functions modify the strings they can't be used with shared strings(eina_stringshare).
See an example Eina String example here.
Define Documentation
#define eina_str_join_static | ( | dst, | |
sep, | |||
a, | |||
b | |||
) | eina_str_join_len(dst, sizeof(dst), sep, a, (sizeof(a) > 0) ? sizeof(a) - 1 : 0, b, (sizeof(b) > 0) ? sizeof(b) - 1 : 0) |
Join two static strings and store the result in a static buffer.
- Since :
- 2.3
- Parameters:
-
dst The buffer to store the result. sep The separator character to use. a First string to use, before sep
.b Second string to use, after sep
.
- Returns:
- The number of characters printed.
This function is similar to eina_str_join_len(), but will assume string sizes are know using sizeof(X).
- See also:
- eina_str_join()
- eina_str_join_static()
Function Documentation
char* eina_str_convert | ( | const char * | enc_from, |
const char * | enc_to, | ||
const char * | text | ||
) |
Use Iconv to convert a text string from one encoding to another.
- Since :
- 2.3
- Parameters:
-
[in] enc_from Encoding to convert from. [in] enc_to Encoding to convert to. [in] text The text to convert.
- Returns:
- The converted text.
- Remarks:
- This function converts
text
, encoded inenc_from
. On success, the converted text is returned and is encoded inenc_to
. On failure,NULL
is returned. Iconv is used to converttext
. If Iconv is not available,NULL
is returned. When not used anymore, the returned value must be freed.
- Warning:
- This function is guaranteed to break when '\0' characters are in
text
.
- Remarks:
- DO NOT USE THIS FUNCTION IF YOUR TEXT CONTAINS NON-TERMINATING '\0' CHARACTERS.
char* eina_str_escape | ( | const char * | str | ) |
Escape slashes, spaces and apostrophes in strings.
- Since :
- 2.3
- Parameters:
-
[in] str The string to escape.
- Returns:
- The escaped string.
- Remarks:
- Escaping is done by adding a slash '\' before any occurrence of slashes '\', spaces ' ' or apostrophes '''. This function returns a newly allocated escaped string on success,
NULL
on failure. When not used anymore, the returned value must be freed.
Eina_Bool eina_str_has_extension | ( | const char * | str, |
const char * | ext | ||
) |
Check if the given string has the given extension.
- Since :
- 2.3
- Parameters:
-
[in] str The string to work with. [in] ext The extension to check for.
- Returns:
- EINA_TRUE if the string has the given extension, EINA_FALSE otherwise.
- Remarks:
- This function does the same as eina_str_has_suffix(), except it's case insensitive.
Eina_Bool eina_str_has_prefix | ( | const char * | str, |
const char * | prefix | ||
) |
Check if the given string has the given prefix.
- Since :
- 2.3
- Parameters:
-
[in] str The string to work with. [in] prefix The prefix to check for.
- Returns:
- EINA_TRUE if the string has the given prefix, EINA_FALSE otherwise.
- Remarks:
- This function returns EINA_TRUE if
str
has the prefixprefix
, EINA_FALSE otherwise. If the length ofprefix
is greater thanstr
, EINA_FALSE is returned.
Eina_Bool eina_str_has_suffix | ( | const char * | str, |
const char * | suffix | ||
) |
Check if the given string has the given suffix.
- Since :
- 2.3
- Parameters:
-
[in] str The string to work with. [in] suffix The suffix to check for.
- Returns:
- EINA_TRUE if the string has the given suffix, EINA_FALSE otherwise.
- Remarks:
- This function returns EINA_TRUE if
str
has the suffixsuffix
, EINA_FALSE otherwise. If the length ofsuffix
is greater thanstr
, EINA_FALSE is returned.
static size_t eina_str_join | ( | char * | dst, |
size_t | size, | ||
char | sep, | ||
const char * | a, | ||
const char * | b | ||
) | [static] |
Join two strings of known length.
- Since :
- 2.3
- Parameters:
-
[in] dst The buffer to store the result. [in] size Size (in byte) of the buffer. [in] sep The separator character to use. [in] a First string to use, before sep
.[in] b Second string to use, after sep
.
- Returns:
- The number of characters printed.
- Remarks:
- This function is similar to eina_str_join_len(), but will compute the length of
a
andb
using strlen().
size_t eina_str_join_len | ( | char * | dst, |
size_t | size, | ||
char | sep, | ||
const char * | a, | ||
size_t | a_len, | ||
const char * | b, | ||
size_t | b_len | ||
) |
Join two strings of known length.
- Since :
- 2.3
- Parameters:
-
[out] dst The buffer to store the result. [in] size Size (in byte) of the buffer. [in] sep The separator character to use. [in] a First string to use, before sep
.[in] a_len length of a
.[in] b Second string to use, after sep
.[in] b_len length of b
.
- Returns:
- The number of characters printed.
- Remarks:
- This function joins the strings
a
andb
(in that order) and separate them withsep
. The result is stored in the bufferdst
and at mostsize
- 1 characters will be written and the string is NULL-terminated.a_len
is the length ofa
(not including '\0') andb_len
is the length ofb
(not including '\0'). This function returns the number of characters printed (not including the trailing '\0' used to end output to strings). Just like snprintf(), it will not write more thansize
bytes, thus a returned value ofsize
or more means that the output was truncated.
- See also:
- eina_str_join()
- eina_str_join_static()
char** eina_str_split | ( | const char * | string, |
const char * | delimiter, | ||
int | max_tokens | ||
) |
Split a string using a delimiter.
- Since :
- 2.3
- Parameters:
-
[in] string The string to split. [in] delimiter The string which specifies the places at which to split the string. [in] max_tokens The maximum number of strings to split string into, or a number less than 1 to split as many times as possible. This parameter IGNORES the added NULL
terminator.
- Returns:
- A newly-allocated NULL-terminated array of strings or
NULL
if it fails to allocate the array.
- Remarks:
- This function splits
string
into a maximum ofmax_tokens
pieces, using the given delimiterdelimiter
.delimiter
is not included in any of the resulting strings, unlessmax_tokens
is reached. Ifmax_tokens
is less than1
, the string is splitted as many times as possible. Ifmax_tokens
is reached, the last string in the returned string array contains the remainder of string. The returned value is a newly allocated NULL-terminated array of strings orNULL
if it fails to allocate the array. To free it, free the first element of the array and the array itself. - If you need the number of elements in the returned array see eina_str_split_full().
char** eina_str_split_full | ( | const char * | string, |
const char * | delimiter, | ||
int | max_tokens, | ||
unsigned int * | elements | ||
) |
Split a string using a delimiter and returns number of elements.
- Since :
- 2.3
- Parameters:
-
[in] string The string to split. [in] delimiter The string which specifies the places at which to split the string. [in] max_tokens The maximum number of strings to split string into, or a number less than 1 to split as many times as possible. This parameter IGNORES the added NULL
terminator.[out] elements Where to return the number of elements in returned array. This array is guaranteed to be no greater than max_tokens
, and it will NOT count theNULL
terminator element.
- Returns:
- A newly-allocated NULL-terminated array of strings or
NULL
if it fails to allocate the array.
- Remarks:
- This function splits
string
into a maximum ofmax_tokens
pieces, using the given delimiterdelimiter
.delimiter
is not included in any of the resulting strings, unlessmax_tokens
is reached. Ifmax_tokens
is less than1
, the string is splitted as many times as possible. Ifmax_tokens
is reached, the last string in the returned string array contains the remainder of string. The returned value is a newly allocated NULL-terminated array of strings orNULL
if it fails to allocate the array. To free it, free the first element of the array and the array itself. -
The actual size of the returned array, when
elements
returns greater than zero, will always beelements
+ 1. This is due to theNULL
terminator element that is added to the array for safety. If it returns6
, the number of split strings returned will be 6, but the size of the array (including theNULL
element) will actually be 7.
- See also:
- eina_str_split()
void eina_str_tolower | ( | char ** | str | ) |
Lowercase all the characters in range [A-Z] in the given string.
- Since :
- 2.3
- Parameters:
-
[out] str The string to lowercase.
- Remarks:
- This function modifies the original string, changing all characters in [A-Z] to lowercase. If
str
isNULL
or is an empty string, this function does nothing.
void eina_str_toupper | ( | char ** | str | ) |
Uppercase all the characters in range [a-z] in the given string.
- Since :
- 2.3
- Parameters:
-
[out] str The string to uppercase.
- Remarks:
- This function modifies the original string, changing all characters in [a-z] to uppercase. If
str
isNULL
or is an empty string, this function does nothing.
size_t eina_strlcat | ( | char * | dst, |
const char * | src, | ||
size_t | siz | ||
) |
Append a c-string.
- Since :
- 2.3
- Parameters:
-
[in] dst The destination string. [in] src The source string. [in] siz The size of the destination string.
- Returns:
- The length of the source string plus MIN(siz, strlen(initial dst))
- Remarks:
- This function appends
src
todst
of sizesiz
(unlike strncat,siz
is the full size ofdst
, not space left). At mostsiz
- 1 characters will be copied. Always NULL-terminates (unlesssiz
<= strlen(dst)). This function returns strlen(src) + MIN(siz, strlen(initial dst)). If the returned value is greater or equal thansiz
, truncation occurred.
size_t eina_strlcpy | ( | char * | dst, |
const char * | src, | ||
size_t | siz | ||
) |
Copy a c-string to another.
- Since :
- 2.3
- Parameters:
-
[out] dst The destination string. [in] src The source string. [in] siz The size of the destination string.
- Returns:
- The length of the source string.
- Remarks:
- This function copies up to
siz
- 1 characters from the NULL-terminated stringsrc
todst
, NULL-terminating the result (unlesssiz
is equal to 0). The returned value is the length ofsrc
. If the returned value is greater thansiz
, truncation occurred. -
The main difference between eina_strlcpy and strncpy is that this ensures
dst
is NULL-terminated even if noNULL
byte is found in the firstsiz
bytes of src.
static size_t eina_strlen_bounded | ( | const char * | str, |
size_t | maxlen | ||
) | [static] |
Count up to a given amount of bytes of the given string.
This function returns the size of str
, up to maxlen
characters. It avoid needless iterations after that size. str
must be a valid pointer and MUST not be NULL
, otherwise this function will crash. This function returns the string size, or (size_t)-1 if the size is greater than maxlen.
- Since :
- 2.3
- Parameters:
-
[in] str The string pointer. [in] maxlen The maximum length to allow.
- Returns:
- the string size or (size_t)-1 if greater than maxlen.