-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstyles_method_3.c
More file actions
95 lines (83 loc) · 2.56 KB
/
styles_method_3.c
File metadata and controls
95 lines (83 loc) · 2.56 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* styles_method_3.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: seungbki <seungbki@student.42seoul.kr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/28 06:07:15 by seungbki #+# #+# */
/* Updated: 2022/03/29 10:34:39 by seungbki ### ########.fr */
/* */
/* ************************************************************************** */
#include "styles_method.h"
#include <sys/types.h>
#include "styles.h"
#include "token.h"
t_style _lower_i_of(t_styles *this, t_token token, ssize_t n)
{
return (_lower_d_of(this, token, n));
}
t_style _lower_p_of(t_styles *this, t_token token, size_t ptr)
{
t_style style;
style = this->default_style;
style.prefix = this->hash_prefix_lower[2];
style.prefix_len = this->hash_prefix_lower_len[2];
style.content_len = 1;
while (16 <= ptr)
{
style.content_len++;
ptr /= 16;
}
_set_outer_padding(this, &style, token);
return (style);
}
t_style _lower_s_of(t_styles *this, t_token token, const char *str)
{
t_style style;
style = this->default_style;
while (str[style.content_len])
{
style.content_len++;
}
if (token.is_precision && (style.content_len > token.precision))
{
style.content_len = token.precision;
}
_set_outer_padding(this, &style, token);
return (style);
}
t_style _lower_u_of(t_styles *this, t_token token, unsigned int n)
{
t_style style;
style = this->default_style;
style.content_len = ((0 == token.is_precision) || token.precision || n);
while (10 <= n)
{
style.content_len++;
n /= 10;
}
_set_inner_padding(this, &style, token);
_set_outer_padding(this, &style, token);
return (style);
}
t_style _lower_x_of(t_styles *this, t_token token, unsigned int n)
{
t_style style;
const int sign = (0 < n) - (0 > n);
style = this->default_style;
if (token.is_hash)
{
style.prefix = this->hash_prefix_lower[1 + sign];
style.prefix_len = this->hash_prefix_lower_len[1 + sign];
}
style.content_len = 1;
while (16 <= n)
{
style.content_len++;
n /= 16;
}
_set_inner_padding(this, &style, token);
_set_outer_padding(this, &style, token);
return (style);
}