]> mj.ucw.cz Git - libucw.git/blob - ucw/xtypes-basic.c
Extended types: First attempt at interface
[libucw.git] / ucw / xtypes-basic.c
1 /*
2  *      UCW Library -- Basic Extended Types
3  *
4  *      (c) 2014 Martin Mares <mj@ucw.cz>
5  *
6  *      This software may be freely distributed and used according to the terms
7  *      of the GNU Lesser General Public License.
8  */
9
10 #include <ucw/lib.h>
11 #include <ucw/mempool.h>
12 #include <ucw/strtonum.h>
13 #include <ucw/xtypes.h>
14
15 static const char *xt_int_parse(const char *str, void *dest, struct mempool *pool UNUSED)
16 {
17   return str_to_int(dest, str, NULL, 10 | STN_WHOLE | STN_MINUS | STN_PLUS | STN_HEX | STN_BIN | STN_OCT);
18 }
19
20 static const char *xt_int_format(void *src, u32 fmt UNUSED, struct mempool *pool)
21 {
22   return mp_printf(pool, "%d", *(int *)src);
23 }
24
25 const struct xtype xt_int = {
26   .size = sizeof(int),
27   .name = "int",
28   .parse = xt_int_parse,
29   .format = xt_int_format,
30 };