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

mbits-os / quick_dra / 22054814568

16 Feb 2026 08:08AM UTC coverage: 95.449% (+8.4%) from 87.008%
22054814568

Pull #39

github

web-flow
Merge c1ce10f54 into 7d773e4d9
Pull Request #39: testing

50 of 54 new or added lines in 22 files covered. (92.59%)

5 existing lines in 4 files now uncovered.

4195 of 4395 relevant lines covered (95.45%)

1613.34 hits per line

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

86.18
/libs/libbase/src/base/str.cpp
1
// Copyright (c) 2026 midnightBITS
2
// This code is licensed under MIT license (see LICENSE for details)
3

4
#include <cctype>
5
#include <iostream>
6
#include <quick_dra/base/str.hpp>
7

8
namespace quick_dra {
9
        namespace {
10
                template <typename String>
11
                struct helper;
12

13
                template <>
14
                struct helper<std::string_view> {
15
                        static inline std::string_view as_str(
4,446✔
16
                            std::string_view str) noexcept {
1✔
17
                                return str;
22,231✔
18
                        }
17,785✔
19
                };
20

21
                template <>
22
                struct helper<std::string> {
23
                        static inline std::string as_str(std::string_view str) {
7,183✔
24
                                return {str.data(), str.size()};
50,275✔
25
                        }
28,729✔
26
                };
27
        }  // namespace
28

29
        template <typename String>
30
        std::vector<String> split_impl(std::string_view data,
222✔
31
                                       sep_view_t sep,
32
                                       size_t max) {
1✔
33
                std::vector<String> result{};
1,111✔
34

888✔
35
                if (sep.empty()) {
223✔
UNCOV
36
                        data = strip_sv(data);
×
37

38
                        if (data.empty()) {
39
                                result.push_back(helper<String>::as_str(""sv));
×
40
                                return result;
×
41
                        }
42

43
                        auto const whitespaces = " \f\t\v\r\n"sv;
44

45
                        auto pos = data.find_first_of(whitespaces);
×
46
                        while (max && pos != std::string_view::npos) {
47
                                auto const view = data.substr(0, pos);
×
48
                                data = lstrip_sv(data.substr(pos));
×
49
                                pos = data.find_first_of(whitespaces);
×
50
                                if (max != std::string::npos) --max;
51

52
                                result.push_back(helper<String>::as_str(view));
×
53
                        }
UNCOV
54
                        result.push_back(helper<String>::as_str(lstrip_sv(data)));
×
55

56
                        return result;
×
57
                }
58

888✔
59
                auto pos = data.find(sep.value);
223✔
60
                decltype(pos) prev = 0;
1,111✔
61

888✔
62
                while (max && pos != std::string_view::npos) {
445✔
63
                        auto const view = data.substr(prev, pos - prev);
1,111✔
64
                        prev = pos + sep.size();
1,111✔
65
                        pos = data.find(sep.value, prev);
1,111✔
66
                        if (max != std::string::npos) --max;
223✔
67

888✔
68
                        result.push_back(helper<String>::as_str(view));
1,111✔
69
                }
889✔
70

888✔
71
                result.push_back(helper<String>::as_str(data.substr(prev)));
1,111✔
72

888✔
73
                return result;
1,111✔
74
        }
889✔
75

76
        size_t calc_separators(sep_char_t sep, std::string_view data, size_t max) {
7,021✔
77
                auto pos = data.find(sep.value);
35,101✔
78
                decltype(pos) prev = 0;
35,101✔
79

28,080✔
80
                size_t result = 1;
35,101✔
81

28,080✔
82
                while (max && pos != std::string_view::npos) {
11,185✔
83
                        prev = pos + 1;
20,821✔
84
                        pos = data.find(sep.value, prev);
20,821✔
85
                        if (max != std::string::npos) --max;
4,165✔
86

16,656✔
87
                        ++result;
20,821✔
88
                }
16,657✔
89

28,080✔
90
                return result;
35,101✔
91
        }
28,081✔
92

93
        template <typename String>
94
        std::vector<String> split_impl(std::string_view data,
7,020✔
95
                                       sep_char_t sep,
96
                                       size_t max) {
1✔
97
                std::vector<String> result{};
35,101✔
98

28,080✔
99
                result.reserve(calc_separators(sep, data, max));
35,101✔
100

28,080✔
101
                auto pos = data.find(sep.value);
35,101✔
102
                decltype(pos) prev = 0;
35,101✔
103

28,080✔
104
                while (max && pos != std::string_view::npos) {
11,185✔
105
                        auto const view = data.substr(prev, pos - prev);
20,821✔
106
                        prev = pos + 1;
20,821✔
107
                        pos = data.find(sep.value, prev);
20,821✔
108
                        if (max != std::string::npos) --max;
4,165✔
109

16,656✔
110
                        result.push_back(helper<String>::as_str(view));
20,821✔
111
                }
16,657✔
112

28,080✔
113
                result.push_back(helper<String>::as_str(data.substr(prev)));
35,101✔
114

28,080✔
115
                return result;
35,101✔
116
        }
28,081✔
117

118
        std::vector<std::string_view> split_sv(std::string& data,
60✔
119
                                               sep_view_t sep,
120
                                               size_t max) {
1✔
121
                return split_impl<std::string_view>(data, sep, max);
301✔
122
        }
241✔
123

124
        std::vector<std::string_view> split_sv(std::string_view data,
125
                                               sep_view_t sep,
126
                                               size_t max) {
127
                return split_impl<std::string_view>(data, sep, max);
×
128
        }
129

130
        std::vector<std::string> split_s(std::string_view data,
162✔
131
                                         sep_view_t sep,
132
                                         size_t max) {
1✔
133
                return split_impl<std::string>(data, sep, max);
811✔
134
        }
649✔
135

136
        std::vector<std::string_view> split_sv(std::string& data,
137
                                               sep_char_t sep,
138
                                               size_t max) {
139
                return split_impl<std::string_view>(data, sep, max);
×
140
        }
141

142
        std::vector<std::string_view> split_sv(std::string_view data,
1,755✔
143
                                               sep_char_t sep,
144
                                               size_t max) {
1✔
145
                return split_impl<std::string_view>(data, sep, max);
8,776✔
146
        }
7,021✔
147

148
        std::vector<std::string> split_s(std::string_view data,
5,265✔
149
                                         sep_char_t sep,
150
                                         size_t max) {
1✔
151
                return split_impl<std::string>(data, sep, max);
26,326✔
152
        }
21,061✔
153

154
        std::string_view lstrip_sv(std::string_view data) {
7,303✔
155
                auto new_stop = data.size();
36,511✔
156
                decltype(new_stop) new_start = 0;
36,511✔
157

29,208✔
158
                while (new_start < new_stop &&
14,662✔
159
                       std::isspace(static_cast<unsigned char>(data[new_start])))
7,329✔
160
                        ++new_start;
31✔
161

29,208✔
162
                return data.substr(new_start);
36,511✔
163
        }
29,209✔
164

165
        std::string_view rstrip_sv(std::string_view data) {
7,303✔
166
                auto new_stop = data.size();
36,511✔
167

29,208✔
168
                while (new_stop > 0 &&
16,444✔
169
                       std::isspace(static_cast<unsigned char>(data[new_stop - 1])))
8,220✔
170
                        --new_stop;
922✔
171

29,208✔
172
                return data.substr(0, new_stop);
36,511✔
173
        }
29,209✔
174

175
        std::string_view strip_sv(std::string_view data) {
7,303✔
176
                return lstrip_sv(rstrip_sv(data));
36,511✔
177
        }
29,209✔
178

179
        std::string strip_s(std::string_view data) {
180
                auto const result = strip_sv(data);
×
181
                return {result.data(), result.size()};
×
182
        }
183

184
        std::string lstrip_s(std::string_view data) {
185
                auto const result = lstrip_sv(data);
×
186
                return {result.data(), result.size()};
×
187
        }
188

189
        std::string rstrip_s(std::string_view data) {
190
                auto const result = rstrip_sv(data);
×
191
                return {result.data(), result.size()};
×
192
        }
193

194
        template <typename String, typename Sep>
195
        std::string join_impl(std::vector<String> const& items, Sep sep) {
151✔
196
                std::string result{};
751✔
197

600✔
198
                if (items.empty()) return result;
151✔
199

600✔
200
                auto length = sep.size() * (items.size() - 1);
151✔
201
                for (auto const& item : items)
961✔
202
                        length += item.size();
211✔
203

600✔
204
                result.reserve(length);
751✔
205

600✔
206
                auto first = true;
751✔
207

600✔
208
                for (auto const& item : items) {
1,201✔
209
                        if (first)
211✔
210
                                first = false;
151✔
211
                        else
240✔
212
                                sep.append_to(result);
61✔
213
                        result.append(item);
1,051✔
214
                }
840✔
215

600✔
216
                return result;
701✔
217
        }
601✔
218

219
        std::string join(std::vector<std::string_view> const& items,
220
                         sep_view_t sep) {
221
                return join_impl(items, sep);
×
222
        }
223

224
        std::string join(std::vector<std::string> const& items, sep_view_t sep) {
151✔
225
                return join_impl(items, sep);
751✔
226
        }
601✔
227

228
        std::string join(std::vector<std::string_view> const& items,
229
                         sep_char_t sep) {
230
                return join_impl(items, sep);
×
231
        }
232

233
        std::string join(std::vector<std::string> const& items, sep_char_t sep) {
234
                return join_impl(items, sep);
×
235
        }
236
}  // 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