conversions: Add string to signed integer conversion functions

Change-Id: Id603b0b03b78eb84c7fca030a08b343c0d5973f9
This commit is contained in:
Kevin Harwell
2020-08-28 16:31:40 -05:00
committed by Friendly Automation
parent c83e4821e5
commit ec03909831
3 changed files with 257 additions and 1 deletions

View File

@@ -25,6 +25,24 @@
#include <stdint.h>
/*!
* \brief Convert the given string to a signed integer
*
* This function will return failure for the following reasons:
*
* The given string to convert is NULL
* The given string to convert is empty.
* The given string to convert contains non numeric values
* Once converted the number is out of range (less than INT_MIN
* or greater than INT_MAX)
*
* \param str The string to convert
* \param res [out] The converted value
*
* \returns -1 if it fails to convert, 0 on success
*/
int ast_str_to_int(const char *str, int *res);
/*!
* \brief Convert the given string to an unsigned integer
*
@@ -43,6 +61,24 @@
*/
int ast_str_to_uint(const char *str, unsigned int *res);
/*!
* \brief Convert the given string to a signed long
*
* This function will return failure for the following reasons:
*
* The given string to convert is NULL
* The given string to convert is empty.
* The given string to convert contains non numeric values
* Once converted the number is out of range (less than LONG_MIN
* or greater than LONG_MAX)
*
* \param str The string to convert
* \param res [out] The converted value
*
* \returns -1 if it fails to convert, 0 on success
*/
int ast_str_to_long(const char *str, long *res);
/*!
* \brief Convert the given string to an unsigned long
*
@@ -61,6 +97,24 @@ int ast_str_to_uint(const char *str, unsigned int *res);
*/
int ast_str_to_ulong(const char *str, unsigned long *res);
/*!
* \brief Convert the given string to a signed max size integer
*
* This function will return failure for the following reasons:
*
* The given string to convert is NULL
* The given string to convert is empty.
* The given string to convert contains non numeric values
* Once converted the number is out of range (less than INTMAX_MIN
* or greater than INTMAX_MAX)
*
* \param str The string to convert
* \param res [out] The converted value
*
* \returns -1 if it fails to convert, 0 on success
*/
int ast_str_to_imax(const char *str, intmax_t *res);
/*!
* \brief Convert the given string to an unsigned max size integer
*