rcx

miscellaneous C library
git clone git://git.rr3.xyz/rcx
Log | Files | Refs | README | LICENSE

conv.h (1079B)


      1 #pragma once
      2 
      3 #include "def.h"
      4 
      5 /* TODO: Support for more types (in particular, signed integers). */
      6 /* TODO: Support for conversions in the other direction. */
      7 /* TODO: Support for rstr's (in addition to zstr's). */
      8 
      9 #define R_CONV_BASE_MASK (((RConvOpts)1 << 6) - 1)
     10 
     11 #define R_CONV_0B ((RConvOpts)1 << 6) /* "0b"/"0B" prefix forces base 2. */
     12 #define R_CONV_0Q ((RConvOpts)1 << 7) /* "0q"/"0Q" prefix forces base 4. */
     13 #define R_CONV_0O ((RConvOpts)1 << 8) /* "0o"/"0O" prefix forces base 8. */
     14 #define R_CONV_0X ((RConvOpts)1 << 9) /* "0x"/"0X" prefix forces base 16. */
     15 
     16 /* RConvOpts partially controls how conversion functions operate. It consists
     17  * of a base (a number in the range [1..36]) ORed with some of the R_CONV
     18  * flags. As a special case, 0 means
     19  *     10 | R_CONV_0B | R_CONV_0Q | R_CONV_0O | R_CONV_0X */
     20 typedef uint RConvOpts;
     21 
     22 int r_conv_zstr_to_u8 (u8  *i, char *s, RConvOpts opts);
     23 int r_conv_zstr_to_u16(u16 *i, char *s, RConvOpts opts);
     24 int r_conv_zstr_to_u32(u32 *i, char *s, RConvOpts opts);
     25 int r_conv_zstr_to_u64(u64 *i, char *s, RConvOpts opts);