#ifndef STRING_CONVERSIONS_H
#define STRING_CONVERSIONS_H
/**
* Convert a string to basic numeric types. This source code is in
* the public domain.
*
* @author Paul Serice
* @file
*/
#ifdef __cplusplus
extern "C" {
#endif
/**
* Convert a string to an int. If you pass in a base
of
* zero, the conversion will treat a leading "0x" prefix as
* hexadecimal and a leading "0" prefix as octal.
*
* @param[in] s string to convert
* @param[out] n conversion of s
to an unsigned long
* @param[in] base base to use for the conversion
* @return 1 on success and 0 on error
*/
extern int
string_to_int(const char* s,
int* n,
int base);
/**
* Convert a string to an unsigned. If you pass in a
* base
of zero, the conversion will treat a leading "0x"
* prefix as hexadecimal and a leading "0" prefix as octal.
*
* @param[in] s string to convert
* @param[out] n conversion of s
to an unsigned int
* @param[in] base base to use for the conversion
* @return 1 on success and 0 on error
*/
extern int
string_to_unsigned(const char* s,
unsigned int* n,
int base);
/**
* Convert a string to a long. If you pass in a base
of
* zero, the conversion will treat a leading "0x" prefix as
* hexadecimal and a leading "0" prefix as octal.
*
* @param[in] s string to convert
* @param[out] n conversion of s
to a long int
* @param[in] base base to use for the conversion
* @return 1 on success and 0 on error
*/
extern int
string_to_long(const char* s,
long int* n,
int base);
/**
* Convert a string to an unsigned long. If you pass in a
* base
of zero, the conversion will treat a leading "0x"
* prefix as hexadecimal and a leading "0" prefix as octal.
*
* @param[in] s string to convert
* @param[out] n conversion of s
to an unsigned long int
* @param[in] base base to use for the conversion
* @return 1 on success and 0 on error
*/
extern int
string_to_unsigned_long(const char* s,
unsigned long int* n,
int base);
/**
* Convert a string to a float. The conversion will treat a leading
* "0x" prefix as hexadecimal floating point and a leading "0" prefix
* as octal floating point.
*
* @param[in] s string to convert
* @param[out] n conversion of s
to a float
* @return 1 on success and 0 on error
*/
extern int
string_to_float(const char* s,
float* n);
/**
* Convert a string to a double. The conversion will treat a leading
* "0x" prefix as hexadecimal floating point and a leading "0" prefix
* as octal floating point.
*
* @param[in] s string to convert
* @param[out] n conversion of s
to a double
* @return 1 on success and 0 on error
*/
extern int
string_to_double(const char* s,
double* n);
#ifdef __cplusplus
}
#endif
#endif /* STRING_CONVERSIONS_H */