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 uns 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;
50 flags |= STN_UNDERSCORE;
73 static void convert(const char *str_flags, const char *str_num)
75 const uns flags = str_to_flags(str_flags);
77 const char *next1, *next2;
79 uintmax_t um = 1234567890;
80 const char *err1 = str_to_uns(&ux, str_num, &next1, flags);
81 const char *err2 = str_to_uintmax(&um, str_num, &next2, flags);
83 if (flags & STN_SIGNED)
84 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);
86 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);
89 int main(int argc, char *argv[])
92 convert(argv[1], argv[2]);