// parse_int.h // PUBLIC DOMAIN // http:///www.purposeful.co.uk/software/yabaplib /* I, Tom Vajzovic, am the author of this software and its documentation. I permanently abandon all intellectual property rights in them, including copyright, trademarks, design rights, database right, patents, and the right to be identified as the author. I am fairly certain that the software does what the documentation says it does, but I do not guarantee that it does, or that it does what you think it should. I do not guarantee that it will not have undesirable side effects. You are free to use, modify and distribute this software as you please, but you do so at your own risk. If you do not pass on this warning then you may be responsible for any problems encountered by those who obtain the software through you. */ #ifndef PARSE_INT_H_INCLUDED #define PARSE_INT_H_INCLUDED #include #ifdef __cplusplus extern "C" { #endif // convert a string of decimal digits to a fixed-size integer // all versions allow whitespace at the start of the string // signed versions also allow a positive or negative sign // return zero on success // return negative if no digits // return positive if absolute value overflows type // on success store value in *p_result if non-null // on success or no digits store pointer to first character after space and digits in *p_end if non-null int decimal_to_u8 (const char *str, char **p_end, uint8_t *p_result); int decimal_to_u16 (const char *str, char **p_end, uint16_t *p_result); int decimal_to_u32 (const char *str, char **p_end, uint32_t *p_result); int decimal_to_u64 (const char *str, char **p_end, uint64_t *p_result); int decimal_to_i8 (const char *str, char **p_end, int8_t *p_result); int decimal_to_i16 (const char *str, char **p_end, int16_t *p_result); int decimal_to_i32 (const char *str, char **p_end, int32_t *p_result); int decimal_to_i64 (const char *str, char **p_end, int64_t *p_result); // also return negative if there is anything but space after the digits to the end of the string int decimal_only_to_u8 (const char *str, uint8_t *p_result); int decimal_only_to_u16 (const char *str, uint16_t *p_result); int decimal_only_to_u32 (const char *str, uint32_t *p_result); int decimal_only_to_u64 (const char *str, uint64_t *p_result); int decimal_only_to_i8 (const char *str, int8_t *p_result); int decimal_only_to_i16 (const char *str, int16_t *p_result); int decimal_only_to_i32 (const char *str, int32_t *p_result); int decimal_only_to_i64 (const char *str, int64_t *p_result); // return non-negative converted value on success // return negative on error with errno set to ERANGE or EINVAL int8_t decimal_only_to_u7 (const char *str); int16_t decimal_only_to_u15 (const char *str); int32_t decimal_only_to_u31 (const char *str); int64_t decimal_only_to_u63 (const char *str); int64_t decimal_size_to_u63 (const char *str); #ifdef __cplusplus } #endif #endif /* PARSE_INT_H_INCLUDED */