These functions allow you to convert integer or real numbers to string or conversely. More...
Functions | |
EAPI int | eina_convert_itoa (int n, char *s) EINA_ARG_NONNULL(2) |
Converts an integer number to a string in decimal base. More... | |
EAPI int | eina_convert_xtoa (unsigned int n, char *s) EINA_ARG_NONNULL(2) |
Converts an integer number to a string in hexadecimal base. More... | |
EAPI int | eina_convert_dtoa (double d, char *des) EINA_ARG_NONNULL(2) |
Converts a double to a string. More... | |
EAPI Eina_Bool | eina_convert_atod (const char *src, int length, long long *m, long *e) EINA_ARG_NONNULL(1 |
Converts a string to a double. More... | |
EAPI Eina_Bool EAPI int | eina_convert_fptoa (Eina_F32p32 fp, char *des) EINA_ARG_NONNULL(2) |
Converts a 32.32 fixed point number to a string. More... | |
EAPI Eina_Bool | eina_convert_atofp (const char *src, int length, Eina_F32p32 *fp) EINA_ARG_NONNULL(1 |
Converts a string to a 32.32 fixed point number. More... | |
EAPI Eina_Bool EAPI double | eina_convert_strtod_c (const char *nptr, char **endptr) |
Converts a string to a floating point number. More... | |
Variables | |
EAPI Eina_Error | EINA_ERROR_CONVERT_P_NOT_FOUND |
Not used, perhaps a placeholder? Defined as 0 in eina_convert.c. | |
EAPI Eina_Error | EINA_ERROR_CONVERT_0X_NOT_FOUND |
Not used, perhaps a placeholder? Defined as 0 in eina_convert.c. | |
EAPI Eina_Error | EINA_ERROR_CONVERT_OUTRUN_STRING_LENGTH |
Not used, perhaps a placeholder? Defined as 0 in eina_convert.c. | |
These functions allow you to convert integer or real numbers to string or conversely.
To use these functions, you have to call eina_init() first, and eina_shutdown() when eina is not used anymore.
To convert an integer to a string in the decimal base, eina_convert_itoa() should be used. If the hexadecimal base is wanted, eina_convert_xtoa() should be used. They all need a buffer sufficiently large to store all the cyphers.
Here is an example of use:
Compile this code with the following command:
To convert a double to a string, eina_convert_dtoa() should be used. Like with the integer functions, a buffer must be used. The resulting string has the following format (which is the result obtained with snprintf() and the %a modifier):
To convert a string to a double, eina_convert_atod() should be used. The format of the string must be as above. Then, the double has the following mantissas and exponent:
with n being number of cyphers after the point in the string format. To obtain the double number from the mantissas and exponent, use ldexp().
Here is an example of use:
Compile this code with the following command:
EAPI int eina_convert_itoa | ( | int | n, |
char * | s | ||
) |
Converts an integer number to a string in decimal base.
[in] | n | The integer to convert. |
[out] | s | The buffer to store the converted integer. |
This function converts n
to a null terminated string. The converted string is in decimal base. As no check is done, s
must be a buffer that is sufficiently large to store the integer.
The returned value is the length of the string, including the null terminated character.
References EINA_SAFETY_ON_NULL_RETURN_VAL.
Referenced by eina_convert_dtoa(), eina_convert_fptoa(), and eina_xattr_int_set().
EAPI int eina_convert_xtoa | ( | unsigned int | n, |
char * | s | ||
) |
Converts an integer number to a string in hexadecimal base.
[in] | n | The integer to convert. |
[out] | s | The buffer to store the converted integer. |
This function converts n
to a null terminated string. The converted string is in hexadecimal base and the alphabetical cyphers are in lower case. As no check is done, s
must be a buffer that is sufficiently large to store the integer.
The returned value is the length of the string, including the nul terminated character.
References EINA_SAFETY_ON_NULL_RETURN_VAL.
EAPI int eina_convert_dtoa | ( | double | d, |
char * | des | ||
) |
Converts a double to a string.
[in] | d | The double to convert. |
[out] | des | The destination buffer to store the converted double. |
This function converts the double d
to a string. The string is stored in the buffer pointed by des
and must be sufficiently large to contain the converted double. The returned string is null terminated and has the following format:
where the h are the hexadecimal cyphers of the mantissas and e the exponent (a decimal number).
The returned value is the length of the string, including the null character.
References eina_convert_itoa(), EINA_SAFETY_ON_FALSE_RETURN_VAL, and EINA_SAFETY_ON_NULL_RETURN_VAL.
Referenced by eina_xattr_double_set().
Converts a string to a double.
[in] | src | The string to convert. |
[in] | length | The length of the string. |
[out] | m | The mantissa. |
[out] | e | The exponent. |
This function converts the string s
of length length
that represent a double in hexadecimal base to a double. It is used to replace the use of snprintf() with the %a modifier, which is missing on some platform (like Windows (tm) or OpenBSD).
The string must have the following format:
where the h are the hexadecimal cyphers of the mantissas and e the exponent (a decimal number). If n is the number of cyphers after the point, the returned mantissas and exponents are:
The mantissas and exponent are stored in the buffers pointed respectively by m
and e
.
If the string is invalid EINA_FALSE is returned, otherwise EINA_TRUE is returned.
Referenced by eina_xattr_double_get().
EAPI Eina_Bool EAPI int eina_convert_fptoa | ( | Eina_F32p32 | fp, |
char * | des | ||
) |
Converts a 32.32 fixed point number to a string.
[in] | fp | The fixed point number to convert. |
[out] | des | The destination buffer to store the converted fixed point number. |
This function converts the 32.32 fixed point number fp
to a string. The string is stored in the buffer pointed by des
and must be sufficiently large to contain the converted fixed point number. The returned string is terminated and has the following format:
where the h are the hexadecimal cyphers of the mantissas and e the exponent (a decimal number).
The returned value is the length of the string, including the null character.
References eina_convert_itoa(), EINA_FALSE, and EINA_SAFETY_ON_NULL_RETURN_VAL.
EAPI Eina_Bool eina_convert_atofp | ( | const char * | src, |
int | length, | ||
Eina_F32p32 * | fp | ||
) |
Converts a string to a 32.32 fixed point number.
[in] | src | The string to convert. |
[in] | length | The length of the string. |
[out] | fp | The fixed point number. |
This function converts the string src
of length length
that represent a double in hexadecimal base to a 32.32 fixed point number stored in fp
. The function always tries to convert the string with eina_convert_atod().
The string must have the following format:
where the h's are the hexadecimal cyphers of the mantissas and e the exponent (a decimal number). If n is the number of cyphers after the point, the returned mantissas and exponents are:
The mantissas and exponent are stored in the buffers pointed respectively by m
and e
.
If the string is invalid, EINA_FALSE is returned, otherwise fp
is computed and EINA_TRUE is returned.
Converts a string to a floating point number.
[in] | nptr | a string to convert. It shouldn't be NULL. |
[out] | endptr | If endptr is not NULL, a pointer to the character after the last character used in the conversion is stored in the location referenced by endptr. If nptr is NULL, this will also be set to NULL. |
This function returns converted floating point number with locale-independency. Actually, it use "C" locale for strtod_l function internally. If you need strtod without locale-dependency, this function can replace strtod. For more information, please refer documents of strtod, strtod_l.
References eina_dbl_exact(), and EINA_SAFETY_ON_NULL_RETURN_VAL.