2 * UCW Library -- Conversions of Strings to Numbers
4 * (c) 2010 Daniel Fiala <danfiala@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
11 #include <ucw/string.h>
12 #include <ucw/chartype.h>
13 #include <ucw/strtonum.h>
15 static uint detect_base(const char **pp, const uint flags)
17 if ((flags & STN_BASES0) && **pp == '0')
61 static const char *str_to_num_init(const char **pp, const uint flags, uint *sign, uint *base)
65 const char *err = NULL;
70 if (flags & (STN_SIGNS))
72 if (*p == '-' && (flags & STN_MINUS))
77 else if (*p == '+' && (flags & STN_PLUS))
81 *base = detect_base(&p, flags) ? : flags & STN_DBASES_MASK;
87 static inline uint get_digit(const uint c)
93 const int a = c & 0xDF;
101 #define STN_TYPE uint
102 #define STN_SUFFIX uint
103 #include <ucw/strtonum-gen.h>
106 #define STN_SUFFIX u64
107 #include <ucw/strtonum-gen.h>
109 #define STN_TYPE uintmax_t
110 #define STN_SUFFIX uintmax
111 #include <ucw/strtonum-gen.h>
113 // FIXME: For backwards compatibility, will be removed soon
115 #define STN_SUFFIX uns
116 #include <ucw/strtonum-gen.h>