Since we have those fancy helpers, why not use them? Also, add one
extra for skipping float nubers for extra handiness.
Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
ret = atoi(src);
if (dst) {
- while(((*src >= '0') && (*src <= '9')) && *src)
- src++;
- *dst = src;
+ *dst = skip_numbers(src);
}
return ret;
ret = atoll(src);
if (dst) {
- while(((*src >= '0') && (*src <= '9')) && *src)
- src++;
- *dst = src;
+ *dst = skip_numbers(src);
}
return ret;
ret = atof(src);
if (dst) {
- while((((*src >= '0') && (*src <= '9')) || (*src =='.')) && *src)
- src++;
- *dst = src;
+ *dst = skip_float_numbers(src);
}
return ret;
return str;
}
+static inline char *skip_float_numbers(char *str)
+{
+ while(isdigit(*str) || (*str == '.'))
+ str++;
+
+ return str;
+}
+
#endif