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 u32
107 #include <ucw/strtonum-gen.h>
110 #define STN_SUFFIX u64
111 #include <ucw/strtonum-gen.h>
113 #define STN_TYPE uintmax_t
114 #define STN_SUFFIX uintmax
115 #include <ucw/strtonum-gen.h>
117 // FIXME: For backward compatibility, will be removed soon
119 #define STN_SUFFIX uns
120 #include <ucw/strtonum-gen.h>