| Directory: | ./ |
|---|---|
| File: | s21_sscanf_utils.c |
| Date: | 2025-11-01 23:04:41 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 42 | 42 | 100.0% |
| Branches: | 24 | 24 | 100.0% |
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "s21_sscanf.h" | ||
| 2 | |||
| 3 | 122 | void setAssignable(const char **format, FormatSpecifierScan *fs) { | |
| 4 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 102 times.
|
122 | if (**format == '*') { |
| 5 | 20 | fs->assignable = 0; | |
| 6 | 20 | (*format)++; | |
| 7 | } else { | ||
| 8 | 102 | fs->assignable = 1; | |
| 9 | } | ||
| 10 | 122 | } | |
| 11 | |||
| 12 | 122 | void setWidth(const char **format, FormatSpecifierScan *fs) { | |
| 13 | 122 | fs->width = 0; | |
| 14 |
4/4✓ Branch 0 taken 149 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 30 times.
✓ Branch 3 taken 119 times.
|
152 | while (**format >= '0' && **format <= '9') { |
| 15 | 30 | fs->width = fs->width * 10 + (int)(**format - '0'); | |
| 16 | 30 | (*format)++; | |
| 17 | } | ||
| 18 | 122 | } | |
| 19 | |||
| 20 | 122 | void setLength(const char **format, FormatSpecifierScan *fs) { | |
| 21 |
2/2✓ Branch 1 taken 17 times.
✓ Branch 2 taken 105 times.
|
122 | if (s21_strchr("hlL", **format) != NULL) { |
| 22 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 16 times.
|
17 | if (*(*format + 1) == 'l') { |
| 23 | 1 | fs->length = 'L'; | |
| 24 | 1 | (*format) += 2; | |
| 25 | } else { | ||
| 26 | 16 | fs->length = **format; | |
| 27 | 16 | (*format)++; | |
| 28 | } | ||
| 29 | } else { | ||
| 30 | 105 | fs->length = '\0'; | |
| 31 | } | ||
| 32 | 122 | } | |
| 33 | |||
| 34 | 122 | void setSpecifier(const char **format, FormatSpecifierScan *fs) { | |
| 35 | 122 | fs->specifier = **format; | |
| 36 | 122 | (*format)++; | |
| 37 | 122 | } | |
| 38 | |||
| 39 | 97 | int isInvalid(const char *str, const char *format) { | |
| 40 | 97 | int check = 0; | |
| 41 |
4/4✓ Branch 0 taken 45 times.
✓ Branch 1 taken 52 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 44 times.
|
97 | if (!*str && s21_strchr(format, '%') != S21_NULL) { |
| 42 | 1 | check = S21_EOF; | |
| 43 | } | ||
| 44 | |||
| 45 | 97 | return check; | |
| 46 | } | ||
| 47 | |||
| 48 | 105 | int requireStrNotEmpty(const char **str, int *countOfRead) { | |
| 49 | 105 | int check = 1; | |
| 50 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 102 times.
|
105 | if (!**str) { |
| 51 | 3 | check = 0; | |
| 52 | 3 | (*countOfRead) = S21_EOF; | |
| 53 | } | ||
| 54 | |||
| 55 | 105 | return check; | |
| 56 | } | ||
| 57 | |||
| 58 | 131 | void skipBlankChars(const char **str) { | |
| 59 |
4/4✓ Branch 0 taken 197 times.
✓ Branch 1 taken 5 times.
✓ Branch 3 taken 71 times.
✓ Branch 4 taken 126 times.
|
202 | while (**str && charIsBlank(**str)) { |
| 60 | 71 | (*str)++; | |
| 61 | } | ||
| 62 | 131 | } | |
| 63 | |||
| 64 | 465 | int charIsBlank(char c) { return s21_strchr(" \t\n\v\f\r", c) != S21_NULL; } | |
| 65 | |||
| 66 |
4/4✓ Branch 0 taken 42 times.
✓ Branch 1 taken 301 times.
✓ Branch 2 taken 34 times.
✓ Branch 3 taken 8 times.
|
343 | int isPossibleRead(s21_size_t n, s21_size_t max) { return n == 0 || max > 0; } |
| 67 |