| Line | Branch | Exec | Source | 
|---|---|---|---|
| 1 | /* | ||
| 2 | ** EPITECH PROJECT, 2023 | ||
| 3 | ** my_printf | ||
| 4 | ** File description: | ||
| 5 | ** The functions for format an int | ||
| 6 | */ | ||
| 7 | /** | ||
| 8 | * @file sub_format_int.c | ||
| 9 | * @brief The functions for format an int | ||
| 10 | * @author Nicolas TORO | ||
| 11 | */ | ||
| 12 | |||
| 13 | #include "myprintf.h" | ||
| 14 | |||
| 15 | 4 | static void do_next(char *str_finale, formating_t *formating, double nb) | |
| 16 | { | ||
| 17 | 4 | void (*format[])(char *, formating_t *, size_t) = | |
| 18 | {&format_moins_int, &format_plus_int, &format_esp_int, | ||
| 19 | &format_hash_int, &format_zero_int}; | ||
| 20 | |||
| 21 | 1/2✓ Branch 0 taken 7 times. ✗ Branch 1 not taken. | 7 | for (int j = 0; j < 5; j++) { | 
| 22 | 2/2✓ Branch 0 taken 4 times. ✓ Branch 1 taken 3 times. | 7 | if (formating->next_chara == FORMATAGE[j]) { | 
| 23 | 4 | formating->next_chara = 1; | |
| 24 | 4 | format[j](str_finale, formating, nb); | |
| 25 | 4 | return; | |
| 26 | } | ||
| 27 | } | ||
| 28 | } | ||
| 29 | |||
| 30 | 4 | static void en_plus(char *str_finale, formating_t *formating) | |
| 31 | { | ||
| 32 | 2/2✓ Branch 1 taken 2 times. ✓ Branch 2 taken 4 times. | 6 | for (int i = my_strlen(str_finale); i < formating->id_wd; i++) | 
| 33 | 2 | my_strcat(str_finale, " "); | |
| 34 | 4 | } | |
| 35 | |||
| 36 | 5 | void format_plus_int(char *str_finale, | |
| 37 | formating_t *formating, size_t nb) | ||
| 38 | { | ||
| 39 | 1/2✓ Branch 0 taken 5 times. ✗ Branch 1 not taken. | 5 | if ((formating->flag != 'b') | 
| 40 | 2/4✓ Branch 0 taken 5 times. ✗ Branch 1 not taken. ✓ Branch 2 taken 5 times. ✗ Branch 3 not taken. | 5 | && (formating->flag != 'x') && (formating->flag != 'X') | 
| 41 | 2/4✓ Branch 0 taken 5 times. ✗ Branch 1 not taken. ✓ Branch 2 taken 5 times. ✗ Branch 3 not taken. | 5 | && (formating->flag != 'o') && (formating->flag != 'u')){ | 
| 42 | 5 | my_revstr(str_finale); | |
| 43 | 5 | my_strcat(str_finale, "+"); | |
| 44 | 3/4✓ Branch 0 taken 5 times. ✗ Branch 1 not taken. ✓ Branch 2 taken 4 times. ✓ Branch 3 taken 1 times. | 5 | if (formating->id_wd != -1 && formating->next_chara != '-') | 
| 45 | 4 | en_plus(str_finale, formating); | |
| 46 | 5 | my_revstr(str_finale); | |
| 47 | } | ||
| 48 | 3/4✓ Branch 0 taken 5 times. ✗ Branch 1 not taken. ✓ Branch 2 taken 1 times. ✓ Branch 3 taken 4 times. | 5 | if (formating->next_chara == '+' || formating->next_chara == '-') | 
| 49 | 1 | do_next(str_finale, formating, nb); | |
| 50 | 5 | } | |
| 51 | |||
| 52 | 3 | void format_moins_int(char *str_finale, | |
| 53 | formating_t *formating, size_t nb) | ||
| 54 | { | ||
| 55 | 2/2✓ Branch 0 taken 1 times. ✓ Branch 1 taken 2 times. | 3 | if (formating->next_chara == '+') | 
| 56 | 1 | formating->id_wd -= 1; | |
| 57 | 1/2✓ Branch 1 taken 3 times. ✗ Branch 2 not taken. | 3 | if ((my_strlen(str_finale) < formating->id_wd | 
| 58 | 2/2✓ Branch 0 taken 2 times. ✓ Branch 1 taken 1 times. | 3 | && formating->next_chara == '+') | 
| 59 | 1/2✓ Branch 1 taken 2 times. ✗ Branch 2 not taken. | 2 | || my_strlen(str_finale) < formating->id_wd) { | 
| 60 | 2/2✓ Branch 1 taken 13 times. ✓ Branch 2 taken 3 times. | 16 | for (int i = my_strlen(str_finale); i < formating->id_wd; i++) { | 
| 61 | 13 | my_strcat(str_finale, " "); | |
| 62 | } | ||
| 63 | } | ||
| 64 | 3/4✓ Branch 0 taken 2 times. ✓ Branch 1 taken 1 times. ✗ Branch 2 not taken. ✓ Branch 3 taken 2 times. | 3 | if (formating->next_chara == '+' || formating->next_chara == '-') | 
| 65 | 1 | do_next(str_finale, formating, nb); | |
| 66 | 3 | } | |
| 67 | |||
| 68 | 9 | void format_esp_int(char *str_finale, formating_t *formating, size_t nb) | |
| 69 | { | ||
| 70 | 3/4✓ Branch 0 taken 8 times. ✓ Branch 1 taken 1 times. ✗ Branch 2 not taken. ✓ Branch 3 taken 8 times. | 9 | if (formating->next_chara == '+' || formating->next_chara == '-') | 
| 71 | 1 | do_next(str_finale, formating, nb); | |
| 72 | 9 | my_revstr(str_finale); | |
| 73 | 2/2✓ Branch 1 taken 7 times. ✓ Branch 2 taken 9 times. | 16 | for (int i = my_strlen(str_finale); i < formating->id_wd; i++) | 
| 74 | 7 | my_strcat(str_finale, " "); | |
| 75 | 9 | my_revstr(str_finale); | |
| 76 | 9 | } | |
| 77 | |||
| 78 | 2 | void format_zero_int(char *str_finale, | |
| 79 | formating_t *formating, size_t nb) | ||
| 80 | { | ||
| 81 | 2 | long long int i = my_strlen(str_finale); | |
| 82 | |||
| 83 | 1/2✓ Branch 0 taken 2 times. ✗ Branch 1 not taken. | 2 | if (formating->next_chara != '-') { | 
| 84 | 2 | my_revstr(str_finale); | |
| 85 | 2/2✓ Branch 0 taken 3 times. ✓ Branch 1 taken 6 times. | 11 | for (i; (i < formating->id_wd && formating->next_chara != '+') | 
| 86 | 5/6✓ Branch 0 taken 9 times. ✓ Branch 1 taken 1 times. ✓ Branch 2 taken 5 times. ✓ Branch 3 taken 2 times. ✓ Branch 4 taken 5 times. ✗ Branch 5 not taken. | 16 | || (i < formating->id_wd - 1 && formating->next_chara == '+'); i++) | 
| 87 | 8 | my_strcat(str_finale, "0"); | |
| 88 | 2 | my_revstr(str_finale); | |
| 89 | } | ||
| 90 | 3/4✓ Branch 0 taken 1 times. ✓ Branch 1 taken 1 times. ✗ Branch 2 not taken. ✓ Branch 3 taken 1 times. | 2 | if (formating->next_chara == '+' || formating->next_chara == '-') | 
| 91 | 1 | do_next(str_finale, formating, nb); | |
| 92 | 2 | } | |
| 93 | |||
| 94 | 7 | void format_hash_int(char *str_finale, | |
| 95 | formating_t *formating, size_t nb) | ||
| 96 | { | ||
| 97 | 7 | format_esp_int(str_finale, formating, nb); | |
| 98 | 7 | return; | |
| 99 | } | ||
| 100 |