21 #ifndef POORMAN_CSTRING_HPP_INCLUDED 22 #define POORMAN_CSTRING_HPP_INCLUDED 24 #include <type_traits> 37 void itoa_hex(
char * buf, Tp value,
int n =
sizeof(Tp)*2,
char padding =
'0') {
38 using value_type =
typename std::make_unsigned<Tp>::type;
39 value_type val = (value_type)value;
45 while(n >= 0 && val) {
47 buf[n--] = v < 10 ?
'0' + v :
'a' + v - 10;
67 typename std::enable_if< std::is_unsigned< Tp >::value >::type
68 itoa(
char * buf, Tp value,
int n,
char padding =
'0') {
73 while(n >= 0 && value > 0) {
74 buf[n--] =
'0' + (value % 10);
86 typename std::enable_if< std::is_signed< Tp >::value >::type
87 itoa(
char * buf, Tp value,
int n,
char padding =
'0') {
89 itoa(buf, (
unsigned)(-value), n-1, padding);
94 #endif // POORMAN_CSTRING_HPP_INCLUDED void itoa_hex(char *buf, Tp value, int n=sizeof(Tp) *2, char padding='0')
Prints "value" as hexadecimal number to buf, '0'-padded, zero terminated.
Definition: poorman_cstring.hpp:37
Definition: poorman_cstring.hpp:26
std::enable_if< std::is_unsigned< Tp >::value >::type itoa(char *buf, Tp value, int n, char padding='0')
Prints n digits of "value" to buf, right aligned, "padding"-padded, zero terminated.
Definition: poorman_cstring.hpp:68