| 1 |
/* this file defines obsolete functions: mrb_int_read() and mrb_float_read() */ |
| 2 |
/* use mrb_read_int() and mrb_read_float() instead */ |
| 3 |
|
| 4 |
#include <mruby.h> |
| 5 |
#include <mruby/numeric.h> |
| 6 |
#include <errno.h> |
| 7 |
|
| 8 |
/* mrb_int_read(): read mrb_int from a string (base 10 only) */ |
| 9 |
/* const char *p - string to read */ |
| 10 |
/* const char *e - end of string */ |
| 11 |
/* char **endp - end of parsed integer */ |
| 12 |
|
| 13 |
/* if integer overflows, errno will be set to ERANGE */ |
| 14 |
/* also endp will be set to NULL on overflow */ |
| 15 |
MRB_API mrb_int |
| 16 |
mrb_int_read(const char *p, const char *e, char **endp) |
| 17 |
{ |
| 18 |
mrb_int n; |
| 19 |
|
| 20 |
if (!mrb_read_int(p, e, endp, &n)) { |
| 21 |
if (endp) *endp = NULL; |
| 22 |
errno = ERANGE; |
| 23 |
return MRB_INT_MAX; |
| 24 |
} |
| 25 |
if (endp) *endp = (char*)p; |
| 26 |
return n; |
| 27 |
} |
| 28 |
|
| 29 |
#ifndef MRB_NO_FLOAT |
| 30 |
//#include <string.h> |
| 31 |
//#include <math.h> |
| 32 |
|
| 33 |
MRB_API double |
| 34 |
mrb_float_read(const char *str, char **endp) |
| 35 |
{ |
| 36 |
double d; |
| 37 |
|
| 38 |
if (!mrb_read_float(str, endp, &d)) { |
| 39 |
errno = ERANGE; |
| 40 |
} |
| 41 |
return d; |
| 42 |
} |
| 43 |
#endif |