| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "volkov_a_count_word_line/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <cstddef> | ||
| 4 | #include <cstdint> | ||
| 5 | #include <string> | ||
| 6 | |||
| 7 | #include "volkov_a_count_word_line/common/include/common.hpp" | ||
| 8 | |||
| 9 | namespace volkov_a_count_word_line { | ||
| 10 | namespace { | ||
| 11 | |||
| 12 | bool IsTokenChar(char c) { | ||
| 13 | 3336 | const bool is_alpha = (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); | |
| 14 | 3336 | const bool is_digit = (c >= '0' && c <= '9'); | |
| 15 | 3336 | const bool is_special = (c == '-' || c == '_'); | |
| 16 |
4/4✓ Branch 0 taken 280 times.
✓ Branch 1 taken 568 times.
✓ Branch 2 taken 520 times.
✓ Branch 3 taken 1968 times.
|
3336 | return is_alpha || is_digit || is_special; |
| 17 | } | ||
| 18 | |||
| 19 | 240 | int CountWords(const char *data, size_t n) { | |
| 20 | enum class State : std::uint8_t { kInWord, kInSeparator }; | ||
| 21 | int word_count = 0; | ||
| 22 | |||
| 23 | State current_state = State::kInSeparator; | ||
| 24 | |||
| 25 |
2/2✓ Branch 0 taken 3336 times.
✓ Branch 1 taken 240 times.
|
3576 | for (size_t i = 0; i < n; ++i) { |
| 26 | 3336 | const char c = data[i]; | |
| 27 |
2/2✓ Branch 0 taken 848 times.
✓ Branch 1 taken 2488 times.
|
3336 | if (current_state == State::kInSeparator) { |
| 28 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 256 times.
|
280 | if (IsTokenChar(c)) { |
| 29 | 592 | word_count++; | |
| 30 | current_state = State::kInWord; | ||
| 31 | } | ||
| 32 | } else { | ||
| 33 |
2/2✓ Branch 0 taken 416 times.
✓ Branch 1 taken 104 times.
|
520 | if (!IsTokenChar(c)) { |
| 34 | current_state = State::kInSeparator; | ||
| 35 | } | ||
| 36 | } | ||
| 37 | } | ||
| 38 | 240 | return word_count; | |
| 39 | } | ||
| 40 | |||
| 41 | } // namespace | ||
| 42 | |||
| 43 |
1/2✓ Branch 1 taken 240 times.
✗ Branch 2 not taken.
|
240 | VolkovACountWordLineSEQ::VolkovACountWordLineSEQ(const InType &in) { |
| 44 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 45 | GetInput() = in; | ||
| 46 | 240 | GetOutput() = 0; | |
| 47 | 240 | } | |
| 48 | |||
| 49 | 240 | bool VolkovACountWordLineSEQ::ValidationImpl() { | |
| 50 | 240 | return true; | |
| 51 | } | ||
| 52 | |||
| 53 | 240 | bool VolkovACountWordLineSEQ::PreProcessingImpl() { | |
| 54 | 240 | return true; | |
| 55 | } | ||
| 56 | |||
| 57 | 240 | bool VolkovACountWordLineSEQ::RunImpl() { | |
| 58 | const char *data = reinterpret_cast<const char *>(GetInput().data()); | ||
| 59 | const size_t size = GetInput().size(); | ||
| 60 | 240 | GetOutput() = CountWords(data, size); | |
| 61 | 240 | return true; | |
| 62 | } | ||
| 63 | |||
| 64 | 240 | bool VolkovACountWordLineSEQ::PostProcessingImpl() { | |
| 65 | 240 | return true; | |
| 66 | } | ||
| 67 | |||
| 68 | } // namespace volkov_a_count_word_line | ||
| 69 |