forked from AlfredPianist/printf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformats_advanced_str.c
executable file
·129 lines (105 loc) · 2.32 KB
/
formats_advanced_str.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include "holberton.h"
/**
* f_add - The "%p" format specifier.
* @arg_l: The argument list to be operated.
* @precision: The precision amount.
*
* Return: The formatted "%p" string.
*/
char *f_add(va_list arg_l, unsigned int precision)
{
void *add;
char *add_s, *buf;
unsigned long int add_u;
precision = precision;
buf = NULL;
add = va_arg(arg_l, void *);
if (add == NULL)
{
buf = _alloc(buf, str_len("(nil)") * sizeof(*buf));
buf = str_cpy("(nil)", buf);
}
else
{
add_u = (unsigned long int) add;
add_s = _uitoa_b_o_h(add_u, 16, 0);
buf = _alloc(buf, (str_len(add_s) + 2) * sizeof(*buf));
buf[0] = '0', buf[1] = 'x';
buf = buf + 2, buf = str_cpy(add_s, buf), buf = buf - 2;
free(add_s);
}
return (buf);
}
/**
* f_strh - The "%S" custom format specifier.
* @arg_l: The argument list to be operated.
* @precision: The precision amount.
*
* Return: The formatted "%S" string.
*/
char *f_strh(va_list arg_l, unsigned int precision)
{
char *str, *strh;
unsigned int index, len;
precision = precision;
str = strh = NULL;
index = len = 0;
str = va_arg(arg_l, char *);
if (str == NULL)
str = "(null)";
while (str[index] != '\0')
{
if (str[index] < 32 || str[index] >= 127)
len += 4;
else
len++;
index++;
}
strh = _alloc(strh, sizeof(*strh) * len);
strh = str_cpy_h(str, strh);
return (strh);
}
/**
* f_rev - The "%r" custom format specifier.
* @arg_l: The argument list to be operated.
* @precision: The precision amount.
*
* Return: The formatted "%r" string.
*/
char *f_rev(va_list arg_l, unsigned int precision)
{
unsigned int index;
char *str, *rev;
precision = precision;
rev = str = NULL;
index = 0;
str = va_arg(arg_l, char *);
while (str[index] != '\0')
index++;
rev = _alloc(rev, sizeof(*rev) * index + 1);
rev = str_cpy(str, rev);
rev_string(rev);
return (rev);
}
/**
* f_rot - The "%R" custom format specifier.
* @arg_l: The argument list to be operated.
* @precision: The precision amount.
*
* Return: The formatted "%R" string.
*/
char *f_rot(va_list arg_l, unsigned int precision)
{
unsigned int index;
char *str, *rot;
precision = precision;
rot = str = NULL;
index = 0;
str = va_arg(arg_l, char *);
while (str[index] != '\0')
index++;
rot = _alloc(rot, sizeof(*rot) * index + 1);
rot = str_cpy(str, rot);
rot13(rot);
return (rot);
}