Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | ** EPITECH PROJECT, 2023 | ||
3 | ** my_printf | ||
4 | ** File description: | ||
5 | ** The functions for format a char | ||
6 | */ | ||
7 | /** | ||
8 | * @file sub_format_char.c | ||
9 | * @brief The file containing the sub_format_char functions | ||
10 | * @author Nicolas TORO | ||
11 | */ | ||
12 | |||
13 | #include "myprintf.h" | ||
14 | |||
15 | 3 | static void do_next_char(char *str_finale, | |
16 | formating_t *formating, char c) | ||
17 | { | ||
18 | 3 | void (*format[])(char *, formating_t *, char) = | |
19 | {&format_moins_char, &format_plus_char, &format_esp_char, | ||
20 | &format_hash_char, &format_zero_char}; | ||
21 | |||
22 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 2 times.
|
14 | for (int j = 0; j < 5; j++) { |
23 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 11 times.
|
12 | if (formating->next_chara == FORMATAGE[j]) { |
24 | 1 | format[j](str_finale, formating, c); | |
25 | 1 | return; | |
26 | } | ||
27 | } | ||
28 | } | ||
29 | |||
30 | 2 | void format_plus_char(char *str_finale, | |
31 | formating_t *formating, char c) | ||
32 | { | ||
33 | 2 | format_esp_char(str_finale, formating, c); | |
34 | 2 | return; | |
35 | } | ||
36 | |||
37 | 2 | void format_moins_char(char *str_finale, | |
38 | formating_t *formating, char c) | ||
39 | { | ||
40 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | if ((my_strlen(str_finale) < formating->id_wd |
41 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | && formating->next_chara == '+') |
42 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | || my_strlen(str_finale) < formating->id_wd) { |
43 |
2/2✓ Branch 1 taken 18 times.
✓ Branch 2 taken 2 times.
|
20 | for (int i = my_strlen(str_finale); i < formating->id_wd; i++) { |
44 | 18 | my_strcat(str_finale, " "); | |
45 | } | ||
46 | } | ||
47 | 2 | do_next_char(str_finale, formating, c); | |
48 | 2 | } | |
49 | |||
50 | 6 | void format_esp_char(char *str_finale, | |
51 | formating_t *formating, char c) | ||
52 | { | ||
53 | 6 | my_revstr(str_finale); | |
54 |
2/2✓ Branch 1 taken 13 times.
✓ Branch 2 taken 6 times.
|
19 | for (int i = my_strlen(str_finale); i < formating->id_wd; i++) |
55 | 13 | my_strcat(str_finale, " "); | |
56 | 6 | my_revstr(str_finale); | |
57 | 6 | } | |
58 | |||
59 | 1 | void format_zero_char(char *str_finale, | |
60 | formating_t *formating, char c) | ||
61 | { | ||
62 | 1 | long long int i = my_strlen(str_finale); | |
63 | |||
64 | 1 | my_revstr(str_finale); | |
65 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
2 | for (i;(i < formating->id_wd && formating->next_chara != '+') |
66 |
3/6✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
2 | || (i < formating->id_wd - 1 && formating->next_chara == '+') |
67 | 1 | ; i++) | |
68 | 1 | my_strcat(str_finale, "0"); | |
69 | 1 | my_revstr(str_finale); | |
70 | 1 | do_next_char(str_finale, formating, c); | |
71 | 1 | } | |
72 | |||
73 | 3 | void format_hash_char(char *str_finale, | |
74 | formating_t *formating, char c) | ||
75 | { | ||
76 | 3 | format_esp_char(str_finale, formating, c); | |
77 | 3 | return; | |
78 | } | ||
79 |