| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "akimov_i_star/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <cctype> | ||
| 4 | #include <cstddef> | ||
| 5 | #include <string_view> | ||
| 6 | #include <vector> | ||
| 7 | |||
| 8 | #include "akimov_i_star/common/include/common.hpp" | ||
| 9 | |||
| 10 | namespace akimov_i_star { | ||
| 11 | |||
| 12 | namespace { | ||
| 13 | |||
| 14 | constexpr std::size_t kPrefixLen = 5; | ||
| 15 | constexpr std::string_view kPrefix = "send:"; | ||
| 16 | |||
| 17 | 24 | bool CheckPrefix(const char *data, std::size_t n, std::size_t i) { | |
| 18 |
1/2✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
24 | if (i + kPrefixLen > n) { |
| 19 | return false; | ||
| 20 | } | ||
| 21 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
|
24 | return std::string_view(data + i, kPrefixLen) == kPrefix; |
| 22 | } | ||
| 23 | |||
| 24 | std::size_t SkipWhitespace(const char *data, std::size_t n, std::size_t pos) { | ||
| 25 |
2/8✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
24 | while (pos < n && (data[pos] == ' ' || data[pos] == '\t' || data[pos] == '\r')) { |
| 26 | ✗ | ++pos; | |
| 27 | } | ||
| 28 | return pos; | ||
| 29 | } | ||
| 30 | |||
| 31 | 24 | bool ProcessLineForZeroDst(const char *data, std::size_t n, std::size_t &i) { | |
| 32 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
|
24 | if (!CheckPrefix(data, n, i)) { |
| 33 | return false; | ||
| 34 | } | ||
| 35 | |||
| 36 | 24 | std::size_t j = i + kPrefixLen; | |
| 37 | |||
| 38 |
4/6✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 24 times.
✓ Branch 5 taken 24 times.
|
48 | while (j < n && data[j] != '\n' && data[j] != ':') { |
| 39 | 24 | ++j; | |
| 40 | } | ||
| 41 | |||
| 42 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
|
24 | if (j >= n || data[j] != ':') { |
| 43 | return false; | ||
| 44 | } | ||
| 45 | |||
| 46 | 24 | std::size_t dst_start = j + 1; | |
| 47 | dst_start = SkipWhitespace(data, n, dst_start); | ||
| 48 | |||
| 49 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
|
24 | if (dst_start >= n) { |
| 50 | return false; | ||
| 51 | } | ||
| 52 | |||
| 53 |
1/2✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
24 | if (data[dst_start] != '0') { |
| 54 | return false; | ||
| 55 | } | ||
| 56 | |||
| 57 | ✗ | std::size_t after = dst_start + 1; | |
| 58 | after = SkipWhitespace(data, n, after); | ||
| 59 | |||
| 60 | ✗ | return after < n && data[after] == ':'; | |
| 61 | } | ||
| 62 | |||
| 63 | void SkipToNextLine(const char *data, std::size_t n, std::size_t &i) { | ||
| 64 |
4/8✓ Branch 0 taken 560 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 544 times.
✓ Branch 3 taken 16 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
568 | while (i < n && data[i] != '\n') { |
| 65 | 544 | ++i; | |
| 66 | } | ||
| 67 |
3/8✓ Branch 0 taken 16 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
24 | if (i < n && data[i] == '\n') { |
| 68 | 16 | ++i; | |
| 69 | } | ||
| 70 | } | ||
| 71 | |||
| 72 |
1/2✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
|
8 | int CountDstZeroFromBuffer(const InType &buf) { |
| 73 |
1/2✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
|
8 | const char *data = buf.empty() ? nullptr : buf.data(); |
| 74 | std::size_t n = buf.size(); | ||
| 75 |
1/2✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
|
8 | if (n == 0 || data == nullptr) { |
| 76 | return 0; | ||
| 77 | } | ||
| 78 | |||
| 79 | int count = 0; | ||
| 80 | std::size_t i = 0; | ||
| 81 | |||
| 82 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 8 times.
|
32 | while (i < n) { |
| 83 |
1/2✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
24 | if (data[i] == 's') { |
| 84 | 24 | std::size_t current_pos = i; | |
| 85 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
|
24 | if (ProcessLineForZeroDst(data, n, current_pos)) { |
| 86 | ✗ | ++count; | |
| 87 | } | ||
| 88 | SkipToNextLine(data, n, i); | ||
| 89 | continue; | ||
| 90 | 24 | } | |
| 91 | |||
| 92 | ✗ | if (data[i] == '\n') { | |
| 93 | ✗ | ++i; | |
| 94 | ✗ | continue; | |
| 95 | } | ||
| 96 | |||
| 97 | SkipToNextLine(data, n, i); | ||
| 98 | } | ||
| 99 | |||
| 100 | return count; | ||
| 101 | } | ||
| 102 | |||
| 103 | } // namespace | ||
| 104 | |||
| 105 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | AkimovIStarSEQ::AkimovIStarSEQ(const InType &in) { |
| 106 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 107 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | GetInput() = in; |
| 108 | 8 | GetOutput() = 0; | |
| 109 | 8 | } | |
| 110 | |||
| 111 | 8 | bool AkimovIStarSEQ::ValidationImpl() { | |
| 112 | 8 | return !GetInput().empty(); | |
| 113 | } | ||
| 114 | |||
| 115 | 8 | bool AkimovIStarSEQ::PreProcessingImpl() { | |
| 116 | 8 | input_buffer_ = GetInput(); | |
| 117 | 8 | received_count_ = CountDstZeroFromBuffer(input_buffer_); | |
| 118 | 8 | return true; | |
| 119 | } | ||
| 120 | |||
| 121 | 8 | bool AkimovIStarSEQ::RunImpl() { | |
| 122 | 8 | GetOutput() = received_count_; | |
| 123 | 8 | return true; | |
| 124 | } | ||
| 125 | |||
| 126 | 8 | bool AkimovIStarSEQ::PostProcessingImpl() { | |
| 127 | 8 | return true; | |
| 128 | } | ||
| 129 | |||
| 130 | } // namespace akimov_i_star | ||
| 131 |