GCC Code Coverage Report


Directory: ./
File: s21_strtok.c
Date: 2025-07-13 17:59:14
Exec Total Coverage
Lines: 25 25 100.0%
Branches: 22 22 100.0%

Line Branch Exec Source
1 #include "s21_string.h"
2
3 int isDelim(char toCheck, const char *delim);
4
5 14 char *s21_strtok(char *str, const char *delim) {
6 static char *current = S21_NULL;
7 14 char *result = S21_NULL;
8
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 10 times.
14 if (str != S21_NULL) {
9 4 current = str;
10 }
11
12
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 3 times.
14 if (current != S21_NULL) {
13
4/4
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 2 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 9 times.
14 while (*current != '\0' && isDelim(*current, delim)) {
14 3 current++;
15 }
16
17 11 result = current;
18 11 char *end = result;
19
4/4
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 3 times.
✓ Branch 3 taken 16 times.
✓ Branch 4 taken 8 times.
27 while (*end != '\0' && !isDelim(*end, delim)) {
20 16 end++;
21 }
22
23
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 9 times.
11 if (result == end) {
24 2 current = S21_NULL;
25 2 result = S21_NULL;
26
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
9 } else if (*end != '\0') {
27 8 current = end + 1;
28 8 *end = '\0';
29 } else {
30 1 current = S21_NULL;
31 }
32 }
33
34 14 return result;
35 }
36
37 36 int isDelim(char toCheck, const char *delim) {
38 36 int check = 0;
39
4/4
✓ Branch 0 taken 53 times.
✓ Branch 1 taken 34 times.
✓ Branch 2 taken 51 times.
✓ Branch 3 taken 2 times.
87 for (const char *p = delim; *p != '\0' && check == 0; p++) {
40
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 40 times.
51 if (toCheck == *p) {
41 11 check = 1;
42 }
43 }
44
45 36 return check;
46 }
47