2 * UCW Library -- Conversions of Strings to Numbers: Testing
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/chartype.h>
12 #include <ucw/strtonum.h>
16 static uint str_to_flags(const char *str)
19 for(const char *p = str; *p; ++p)
24 flags = (flags & ~STN_DBASES_MASK) | 16;
27 flags = (flags & ~STN_DBASES_MASK) | 8;
30 flags = (flags & ~STN_DBASES_MASK) | 2;
33 flags = (flags & ~STN_DBASES_MASK) | 10;
53 flags |= STN_UNDERSCORE;
76 static void convert(const char *str_flags, const char *str_num)
78 const uint flags = str_to_flags(str_flags);
80 const char *next1, *next2;
82 uintmax_t um = 1234567890;
83 const char *err1 = str_to_uint(&ux, str_num, &next1, flags);
84 const char *err2 = str_to_uintmax(&um, str_num, &next2, flags);
86 if (flags & STN_SIGNED)
87 printf("i%d\nh%x\ne[%s]\nc[%s]\nb%td:0x%x\nI%jd\nH%jx\nE[%s]\nC[%s]\nB%td:0x%x\n", ux, ux, err1, str_num, next1 - str_num, *next1, um, um, err2, str_num, next2 - str_num, *next2);
89 printf("i%u\nh%x\ne[%s]\nc[%s]\nb%td:0x%x\nI%ju\nH%jx\nE[%s]\nC[%s]\nB%td:0x%x\n", ux, ux, err1, str_num, next1 - str_num, *next1, um, um, err2, str_num, next2 - str_num, *next2);
92 int main(int argc, char *argv[])
95 convert(argv[1], argv[2]);