| Line | Branch | Decision | Exec | Source |
|---|---|---|---|---|
| 1 | #include <cstring> | |||
| 2 | #include <cstdint> | |||
| 3 | #include <cmath> | |||
| 4 | #include <cctype> | |||
| 5 | #include <rusefi/efistringutil.h> | |||
| 6 | #include <rusefi/rusefi_math.h> | |||
| 7 | ||||
| 8 | namespace rusefi::stringutil { | |||
| 9 | ||||
| 10 | 26 | bool strEqualCaseInsensitive(const char *str1, const char *str2) { | ||
| 11 | 26 | int len1 = efiStrlen(str1); | ||
| 12 | 26 | int len2 = efiStrlen(str2); | ||
| 13 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 12 times.
|
2/2✓ Decision 'true' taken 14 times.
✓ Decision 'false' taken 12 times.
|
26 | if (len1 != len2) { |
| 14 | 14 | return false; | ||
| 15 | } | |||
| 16 |
2/2✓ Branch 0 taken 36 times.
✓ Branch 1 taken 11 times.
|
2/2✓ Decision 'true' taken 36 times.
✓ Decision 'false' taken 11 times.
|
47 | for (int i = 0; i < len1; i++) { |
| 17 |
2/2✓ Branch 0 taken 1 time.
✓ Branch 1 taken 35 times.
|
2/2✓ Decision 'true' taken 1 time.
✓ Decision 'false' taken 35 times.
|
36 | if (std::tolower(str1[i]) != std::tolower(str2[i])) { |
| 18 | 1 | return false; | ||
| 19 | } | |||
| 20 | } | |||
| 21 | 11 | return true; | ||
| 22 | } | |||
| 23 | ||||
| 24 | 21 | bool strEqual(const char *str1, const char *str2) { | ||
| 25 | // todo: there must be a standard function?! | |||
| 26 | 21 | int len1 = efiStrlen(str1); | ||
| 27 | 21 | int len2 = efiStrlen(str2); | ||
| 28 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 13 times.
|
2/2✓ Decision 'true' taken 8 times.
✓ Decision 'false' taken 13 times.
|
21 | if (len1 != len2) { |
| 29 | 8 | return false; | ||
| 30 | } | |||
| 31 |
2/2✓ Branch 0 taken 65 times.
✓ Branch 1 taken 12 times.
|
2/2✓ Decision 'true' taken 65 times.
✓ Decision 'false' taken 12 times.
|
77 | for (int i = 0; i < len1; i++) { |
| 32 |
2/2✓ Branch 0 taken 1 time.
✓ Branch 1 taken 64 times.
|
2/2✓ Decision 'true' taken 1 time.
✓ Decision 'false' taken 64 times.
|
65 | if (str1[i] != str2[i]) { |
| 33 | 1 | return false; | ||
| 34 | } | |||
| 35 | } | |||
| 36 | 12 | return true; | ||
| 37 | } | |||
| 38 | ||||
| 39 | /** | |||
| 40 | * string to float. NaN input is supported | |||
| 41 | * | |||
| 42 | * @return NAN in case of invalid string | |||
| 43 | * todo: explicit value for error code? probably not, NaN is only returned in case of an error | |||
| 44 | */ | |||
| 45 |
1/1✓ Decision 'true' taken 21 times.
|
21 | float atoff(const char *param) { | |
| 46 | static char todofixthismesswithcopy[DEFAULT_MAX_EXPECTED_STRING_LENGTH]; | |||
| 47 | ||||
| 48 | 21 | uint32_t totallen = efiStrlen(param); | ||
| 49 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 21 times.
|
21 | if (totallen > sizeof(todofixthismesswithcopy) - 1) { |
| 50 | ✗ | return (float) NAN; | ||
| 51 | } | |||
| 52 | 21 | strcpy(todofixthismesswithcopy, param); | ||
| 53 | 21 | char *string = todofixthismesswithcopy; | ||
| 54 |
6/6✓ Branch 1 taken 20 times.
✓ Branch 2 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 5 taken 19 times.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 19 times.
|
2/2✓ Decision 'true' taken 2 times.
✓ Decision 'false' taken 19 times.
|
21 | if (indexOf(string, 'n') != -1 || indexOf(string, 'N') != -1) { |
| 55 | 2 | return (float) NAN; | ||
| 56 | } | |||
| 57 | ||||
| 58 | // todo: is there a standard function? | |||
| 59 | // unit-tested by 'testMisc()' | |||
| 60 | 19 | int dotIndex = indexOf(string, '.'); | ||
| 61 |
2/2✓ Branch 0 taken 1 time.
✓ Branch 1 taken 18 times.
|
2/2✓ Decision 'true' taken 1 time.
✓ Decision 'false' taken 18 times.
|
19 | if (dotIndex == -1) { |
| 62 | // just an integer | |||
| 63 | 1 | int result = safe_atoi(string); | ||
| 64 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 1 time.
|
1 | if (absI(result) == ATOI_ERROR_CODE) { |
| 65 | ✗ | return (float) NAN; | ||
| 66 | } | |||
| 67 | 1 | return (float) result; | ||
| 68 | } | |||
| 69 | // todo: this needs to be fixed | |||
| 70 | 18 | string[dotIndex] = 0; | ||
| 71 | 18 | int integerPart = safe_atoi(string); | ||
| 72 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 18 times.
|
18 | if (absI(integerPart) == ATOI_ERROR_CODE) { |
| 73 | ✗ | return (float) NAN; | ||
| 74 | } | |||
| 75 | 18 | string += (dotIndex + 1); | ||
| 76 | 18 | int decimalLen = efiStrlen(string); | ||
| 77 | 18 | int decimal = safe_atoi(string); | ||
| 78 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 18 times.
|
18 | if (absI(decimal) == ATOI_ERROR_CODE) { |
| 79 | ✗ | return (float) NAN; | ||
| 80 | } | |||
| 81 | 18 | float divider = 1.0; | ||
| 82 | // todo: reuse 'pow10' function which we have anyway | |||
| 83 |
2/2✓ Branch 0 taken 30 times.
✓ Branch 1 taken 18 times.
|
2/2✓ Decision 'true' taken 30 times.
✓ Decision 'false' taken 18 times.
|
48 | for (int i = 0; i < decimalLen; i++) { |
| 84 | 30 | divider = divider * 10.0; | ||
| 85 | } | |||
| 86 | 18 | return integerPart + decimal / divider; | ||
| 87 | } | |||
| 88 | } | |||
| 89 |