• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mbits-os / quick_dra / 22263246436

21 Feb 2026 07:51PM UTC coverage: 98.659%. Remained the same
22263246436

push

github

mzdun
ci: adding coverage comment to GitHub PR

4562 of 4624 relevant lines covered (98.66%)

2266.46 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.73
/libs/libconv/src/search.cpp
1
// Copyright (c) 2026 midnightBITS
2
// This code is licensed under MIT license (see LICENSE for details)
3

4
#include <quick_dra/base/str.hpp>
5
#include <quick_dra/conv/search.hpp>
6
#include <string>
7
#include <utility>
8
#include <vector>
9

10
namespace quick_dra {
11
        namespace {
12
                auto make_records(std::span<partial::insured_t> const& insured) {
40✔
13
                        std::vector<std::vector<std::string>> records{};
118✔
14
                        records.reserve(insured.size());
118✔
15
                        for (auto const& person : insured) {
337✔
16
                                records.emplace_back();
298✔
17
                                auto& dst = records.back();
298✔
18
                                dst.reserve(3);
298✔
19
                                for (auto const& field :
694✔
20
                                     {person.document, person.first_name, person.last_name}) {
1,387✔
21
                                        auto const key = field.transform(
694✔
22
                                            [](auto const& fld) { return to_upper(fld); });
595✔
23
                                        if (key) {
298✔
24
                                                dst.push_back(std::move(*key));
892✔
25
                                        }
594✔
26
                                }
1,288✔
27
                        }
199✔
28

78✔
29
                        return records;
118✔
30
                }
79✔
31

32
                void search_insured_from_records(
51✔
33
                    std::vector<unsigned>& found,
34
                    std::vector<std::vector<std::string>> const& records,
35
                    auto const& predicate) {
1✔
36
                        unsigned index = 0;
154✔
37

102✔
38
                        for (auto const& record : records) {
421✔
39
                                auto matching = false;
370✔
40
                                for (auto const& field : record) {
1,090✔
41
                                        if (predicate(field)) {
337✔
42
                                                matching = true;
127✔
43
                                                break;
127✔
44
                                        }
84✔
45
                                }
672✔
46

246✔
47
                                if (matching) {
124✔
48
                                        found.push_back(index);
127✔
49
                                }
84✔
50

246✔
51
                                ++index;
370✔
52
                        }
246✔
53
                }
154✔
54
        }  // namespace
55

56
        std::vector<unsigned> search_insured_from_position(
21✔
57
            unsigned position,
58
            std::span<partial::insured_t> const& insured,
59
            std::function<void(std::string const&)> const& on_error) {
1✔
60
                if (position < 1 || position > insured.size()) {
22✔
61
                        if (insured.size() == 1) {
4✔
62
                                on_error("argument --pos must be equal to 1"s);
×
63
                        } else {
6✔
64
                                on_error(
11✔
65
                                    fmt::format("argument --pos must be between 1 and "
11✔
66
                                                "{}, inclusive",
6✔
67
                                                insured.size()));
9✔
68
                        }
6✔
69
                }
6✔
70

42✔
71
                return {position - 1};
97✔
72
        }
43✔
73

74
        std::vector<unsigned> search_insured_from_keyword(
39✔
75
            std::string_view search_keyword,
76
            std::span<partial::insured_t> const& insured,
77
            std::function<void(std::string const&)> const& on_error) {
1✔
78
                std::vector<unsigned> result{};
118✔
79
                auto const records = make_records(insured);
118✔
80

78✔
81
                auto const upper = to_upper(search_keyword);
118✔
82
                auto const view = std::string_view{upper};
118✔
83
                search_insured_from_records(
118✔
84
                    result, records,
78✔
85
                    [view](std::string const& field) { return field == view; });
317✔
86

78✔
87
                if (result.empty()) {
40✔
88
                        search_insured_from_records(
37✔
89
                            result, records, [view](std::string const& field) {
17✔
90
                                    return field.starts_with(view) || field.ends_with(view);
73✔
91
                            });
145✔
92
                }
24✔
93

78✔
94
                if (result.empty()) {
40✔
95
                        on_error(fmt::format("--find: could not find any record using `{}'",
25✔
96
                                             search_keyword));
12✔
97
                }
12✔
98

78✔
99
                return result;
134✔
100
        }
112✔
101
}  // namespace quick_dra
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc