strtol10.c
Go to the documentation of this file.00001
00039 #include "strtol10.h"
00040
00057 bool strtoul10(const char *first, const char *last, unsigned long *val)
00058 {
00059
00060 if (*first == '\0')
00061 return false;
00062
00063 *val = 0;
00064 for(; first != last && *first != '\0'; ++first)
00065 {
00066 if ((*first < '0') || (*first > '9'))
00067 return false;
00068
00069 *val = (*val * 10L) + (*first - '0');
00070 }
00071
00072 return true;
00073 }
00074
00075
00081 bool strtol10(const char *first, const char *last, long *val)
00082 {
00083 bool negative = false;
00084
00085 if (*first == '+')
00086 ++first;
00087 else if (*first == '-')
00088 {
00089 negative = true;
00090 ++first;
00091 }
00092
00093 bool result = strtoul10(first, last, (unsigned long *)val);
00094
00095 if (negative)
00096 *val = - *val;
00097
00098 return result;
00099 }
00100