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