| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | ** EPITECH PROJECT, 2023 | ||
| 3 | ** my_showstr | ||
| 4 | ** File description: | ||
| 5 | ** Prints a string (str) but replaces | ||
| 6 | ** non-printable characters with their hexadecimal number | ||
| 7 | */ | ||
| 8 | |||
| 9 | #include "my.h" | ||
| 10 | |||
| 11 | 7 | static int is_printable(char c) | |
| 12 | { | ||
| 13 |
3/4✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
7 | if (c >= 32 && c <= 126) { |
| 14 | 5 | return 1; | |
| 15 | } else { | ||
| 16 | 2 | return 0; | |
| 17 | } | ||
| 18 | } | ||
| 19 | |||
| 20 | 2 | static void check_zero_in_hexadecimal(char c) | |
| 21 | { | ||
| 22 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (c < 16) |
| 23 | 2 | my_putchar('0'); | |
| 24 | 2 | } | |
| 25 | |||
| 26 | 1 | int my_showstr(char const *str) | |
| 27 | { | ||
| 28 | 1 | int len = my_strlen(str); | |
| 29 | |||
| 30 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
|
8 | for (int i = 0; i < len; i++) { |
| 31 |
2/2✓ Branch 1 taken 5 times.
✓ Branch 2 taken 2 times.
|
7 | if (is_printable(str[i]) == 1) { |
| 32 | 5 | my_putchar(str[i]); | |
| 33 | } else { | ||
| 34 | 2 | my_putchar('\\'); | |
| 35 | 2 | check_zero_in_hexadecimal(str[i]); | |
| 36 | 2 | my_putnbr_base(str[i], "0123456789abcedf"); | |
| 37 | } | ||
| 38 | } | ||
| 39 | 1 | return 0; | |
| 40 | } | ||
| 41 |