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

mendersoftware / mender / 2271300743

19 Jan 2026 11:42AM UTC coverage: 81.376% (+1.7%) from 79.701%
2271300743

push

gitlab-ci

web-flow
Merge pull request #1879 from lluiscampos/MEN-8687-ci-debian-updates

MEN-8687: Update Debian base images for CI jobs

8791 of 10803 relevant lines covered (81.38%)

20310.08 hits per line

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

82.5
/src/common/common.cpp
1
// Copyright 2023 Northern.tech AS
2
//
3
//    Licensed under the Apache License, Version 2.0 (the "License");
4
//    you may not use this file except in compliance with the License.
5
//    You may obtain a copy of the License at
6
//
7
//        http://www.apache.org/licenses/LICENSE-2.0
8
//
9
//    Unless required by applicable law or agreed to in writing, software
10
//    distributed under the License is distributed on an "AS IS" BASIS,
11
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//    See the License for the specific language governing permissions and
13
//    limitations under the License.
14

15
#include <common/common.hpp>
16
#include <common/error.hpp>
17

18
#include <cerrno>
19
#include <cstdlib>
20

21
namespace mender {
22
namespace common {
23

24
mender::common::expected::ExpectedLongLong StringToLongLong(const string &str, int base) {
1,261✔
25
        char *end;
26
        errno = 0;
1,261✔
27
        long long num = strtoll(str.c_str(), &end, base);
1,261✔
28
        if (errno != 0) {
1,261✔
29
                int int_error = errno;
30
                return expected::unexpected(mender::common::error::Error(
×
31
                        std::generic_category().default_error_condition(int_error), ""));
×
32
        }
33
        if (end != &*str.end()) {
1,261✔
34
                return expected::unexpected(mender::common::error::Error(
×
35
                        std::make_error_condition(errc::invalid_argument),
×
36
                        str + " had trailing non-numeric data"));
×
37
        }
38

39
        return num;
40
}
41

42
string StringToLower(const string &str) {
77,016✔
43
        string lower_str(str.length(), ' ');
44
        std::transform(
77,016✔
45
                str.begin(), str.end(), lower_str.begin(), [](unsigned char c) { return std::tolower(c); });
965,495✔
46
        return lower_str;
77,016✔
47
}
48

49
vector<string> SplitString(const string &str, const string &delim) {
1,404✔
50
        vector<string> ret;
51
        for (size_t begin = 0, end = str.find(delim);;) {
1,404✔
52
                if (end == string::npos) {
3,084✔
53
                        ret.push_back(string(str.begin() + begin, str.end()));
1,404✔
54
                        break;
55
                } else {
56
                        ret.push_back(string(str.begin() + begin, str.begin() + end));
1,680✔
57
                        begin = end + 1;
1,680✔
58
                        end = str.find(delim, begin);
1,680✔
59
                }
60
        }
61
        return ret;
1,404✔
62
}
×
63

64
string JoinStrings(const vector<string> &str, const string &delim) {
182✔
65
        string ret;
66
        auto s = str.begin();
67
        if (s == str.end()) {
182✔
68
                return ret;
69
        }
70
        ret += *s;
181✔
71
        s++;
72
        for (; s != str.end(); s++) {
1,850✔
73
                ret += delim;
1,669✔
74
                ret += *s;
1,669✔
75
        }
76
        return ret;
77
}
78

79
vector<string> JoinStringsMaxWidth(
268✔
80
        const vector<string> &str, const string &delim, const size_t max_width) {
81
        vector<string> ret;
82
        auto s = str.begin();
83
        if (s == str.end()) {
268✔
84
                return ret;
85
        }
86

87
        string line = *s;
268✔
88
        s++;
89
        for (; s != str.end(); s++) {
1,618✔
90
                if (line.size() + delim.size() + (*s).size() > max_width) {
1,350✔
91
                        ret.push_back(line);
99✔
92
                        line = "";
99✔
93
                } else {
94
                        line += delim;
1,251✔
95
                }
96
                line += *s;
1,350✔
97
        }
98
        ret.push_back(line);
268✔
99
        return ret;
100
}
×
101

102
} // namespace common
103
} // namespace mender
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