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

xlnt-community / xlnt / aa719a12-330c-47b2-9460-5b2d61336ff6

03 Feb 2025 05:39PM UTC coverage: 81.978% (-1.5%) from 83.482%
aa719a12-330c-47b2-9460-5b2d61336ff6

push

circleci

web-flow
Use C++23 for generating coverage report. (#57)

Using C++23 for coverage reporting, prepares the library for coverage
testing of future post-C++11 features.

This PR makes as few changes as possible to ensure all coverage changes
are due to the changed C++/compiler version used for generating the
coverage report.

Temporarily disable warnings as errors for coverage reporting until
better C++20/23 support is added in PR #55.

11395 of 13900 relevant lines covered (81.98%)

1202684.1 hits per line

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

96.64
./source/cell/index_types.cpp
1
// Copyright (c) 2014-2022 Thomas Fussell
2
// Copyright (c) 2010-2015 openpyxl
3
// Copyright (c) 2024-2025 xlnt-community
4
//
5
// Permission is hereby granted, free of charge, to any person obtaining a copy
6
// of this software and associated documentation files (the "Software"), to deal
7
// in the Software without restriction, including without limitation the rights
8
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
// copies of the Software, and to permit persons to whom the Software is
10
// furnished to do so, subject to the following conditions:
11
//
12
// The above copyright notice and this permission notice shall be included in
13
// all copies or substantial portions of the Software.
14
//
15
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
// THE SOFTWARE
22
//
23
// @license: http://www.opensource.org/licenses/mit-license.php
24
// @author: see AUTHORS file
25
#include <cctype>
26

27
#include <xlnt/cell/index_types.hpp>
28
#include <xlnt/utils/exceptions.hpp>
29
#include <detail/constants.hpp>
30

31
namespace xlnt {
32

33
column_t::index_t column_t::column_index_from_string(const std::string &column_string)
1,640✔
34
{
35
    if (column_string.length() > 3 || column_string.empty())
1,640✔
36
    {
37
        throw invalid_column_index();
2✔
38
    }
39

40
    column_t::index_t column_index = 0;
1,638✔
41
    int place = 1;
1,638✔
42

43
    for (int i = static_cast<int>(column_string.length()) - 1; i >= 0; i--)
3,293✔
44
    {
45
        if (!std::isalpha(column_string[static_cast<std::size_t>(i)]))
1,656✔
46
        {
47
            throw invalid_column_index();
1✔
48
        }
49

50
        auto char_index = std::toupper(column_string[static_cast<std::size_t>(i)]) - 'A';
1,655✔
51

52
        column_index += static_cast<column_t::index_t>((char_index + 1) * place);
1,655✔
53
        place *= 26;
1,655✔
54
    }
55

56
    return column_index;
1,637✔
57
}
58

59
// Convert a column number into a column letter (3 -> 'C')
60
// Right shift the column col_idx by 26 to find column letters in reverse
61
// order.These numbers are 1 - based, and can be converted to ASCII
62
// ordinals by adding 64.
63
std::string column_t::column_string_from_index(column_t::index_t column_index)
14,221,855✔
64
{
65
    // these indicies corrospond to A->ZZZ and include all allowed
66
    // columns
67
    if (column_index < constants::min_column() || column_index > constants::max_column())
14,221,855✔
68
    {
69
        throw invalid_column_index();
1✔
70
    }
71

72
    int temp = static_cast<int>(column_index);
14,221,854✔
73
    std::string column_letter = "";
14,221,854✔
74

75
    while (temp > 0)
48,600,739✔
76
    {
77
        int quotient = temp / 26, remainder = temp % 26;
34,378,885✔
78

79
        // check for exact division and borrow if needed
80
        if (remainder == 0)
34,378,885✔
81
        {
82
            quotient -= 1;
930,052✔
83
            remainder = 26;
930,052✔
84
        }
85

86
        column_letter = std::string(1, char(remainder + 64)) + column_letter;
34,378,885✔
87
        temp = quotient;
34,378,885✔
88
    }
89

90
    return column_letter;
14,221,854✔
91
}
×
92

93
column_t::column_t()
1,569✔
94
    : index(1)
1,569✔
95
{
96
}
1,569✔
97

98
column_t::column_t(index_t column_index)
261,116,157✔
99
    : index(column_index)
261,116,157✔
100
{
101
}
261,116,157✔
102

103
column_t::column_t(const std::string &column_string)
1,637✔
104
    : index(column_index_from_string(column_string))
1,637✔
105
{
106
}
1,637✔
107

108
column_t::column_t(const char *column_string)
61✔
109
    : column_t(std::string(column_string))
61✔
110
{
111
}
61✔
112

113
std::string column_t::column_string() const
14,221,854✔
114
{
115
    return column_string_from_index(index);
14,221,854✔
116
}
117

118
column_t &column_t::operator=(const std::string &rhs)
1✔
119
{
120
    return *this = column_t(rhs);
1✔
121
}
122

123
column_t &column_t::operator=(const char *rhs)
1✔
124
{
125
    return *this = column_t(rhs);
1✔
126
}
127

128
bool column_t::operator==(const column_t &other) const
156,941,555✔
129
{
130
    return index == other.index;
156,941,555✔
131
}
132

133
bool column_t::operator!=(const column_t &other) const
1✔
134
{
135
    return !(*this == other);
1✔
136
}
137

138
bool column_t::operator==(int other) const
86,981,724✔
139
{
140
    return *this == column_t(static_cast<index_t>(other));
86,981,724✔
141
}
142

143
bool column_t::operator==(index_t other) const
2✔
144
{
145
    return *this == column_t(other);
2✔
146
}
147

148
bool column_t::operator==(const std::string &other) const
2✔
149
{
150
    return *this == column_t(other);
2✔
151
}
152

153
bool column_t::operator==(const char *other) const
16✔
154
{
155
    return *this == column_t(other);
16✔
156
}
157

158
bool column_t::operator!=(int other) const
1✔
159
{
160
    return !(*this == other);
1✔
161
}
162

163
bool column_t::operator!=(index_t other) const
1✔
164
{
165
    return !(*this == other);
1✔
166
}
167

168
bool column_t::operator!=(const std::string &other) const
1✔
169
{
170
    return !(*this == other);
1✔
171
}
172

173
bool column_t::operator!=(const char *other) const
1✔
174
{
175
    return !(*this == other);
1✔
176
}
177

178
bool column_t::operator>(const column_t &other) const
14,221,896✔
179
{
180
    return index > other.index;
14,221,896✔
181
}
182

183
bool column_t::operator>=(const column_t &other) const
3✔
184
{
185
    return index >= other.index;
3✔
186
}
187

188
bool column_t::operator<(const column_t &other) const
154,112,128✔
189
{
190
    return index < other.index;
154,112,128✔
191
}
192

193
bool column_t::operator<=(const column_t &other) const
144,184,984✔
194
{
195
    return index <= other.index;
144,184,984✔
196
}
197

198
bool column_t::operator>(const column_t::index_t &other) const
1✔
199
{
200
    return index > other;
1✔
201
}
202

203
bool column_t::operator>=(const column_t::index_t &other) const
1✔
204
{
205
    return index >= other;
1✔
206
}
207

208
bool column_t::operator<(const column_t::index_t &other) const
1✔
209
{
210
    return index < other;
1✔
211
}
212

213
bool column_t::operator<=(const column_t::index_t &other) const
1✔
214
{
215
    return index <= other;
1✔
216
}
217

218
column_t &column_t::operator++()
42,992,242✔
219
{
220
    index++;
42,992,242✔
221
    return *this;
42,992,242✔
222
}
223

224
column_t &column_t::operator--()
2✔
225
{
226
    index--;
2✔
227
    return *this;
2✔
228
}
229

230
column_t column_t::operator++(int)
96,038✔
231
{
232
    column_t copy(index);
96,038✔
233
    ++(*this);
96,038✔
234
    return copy;
96,038✔
235
}
236

237
column_t column_t::operator--(int)
1✔
238
{
239
    column_t copy(index);
1✔
240
    --(*this);
1✔
241
    return copy;
1✔
242
}
243

244
column_t operator+(column_t lhs, const column_t &rhs)
3✔
245
{
246
    lhs += rhs;
3✔
247
    return lhs;
3✔
248
}
249

250
column_t operator-(column_t lhs, const column_t &rhs)
249✔
251
{
252
    lhs -= rhs;
249✔
253
    return lhs;
249✔
254
}
255

256
column_t &column_t::operator+=(const column_t &rhs)
3✔
257
{
258
    index += rhs.index;
3✔
259
    return *this;
3✔
260
}
261

262
column_t &column_t::operator-=(const column_t &rhs)
249✔
263
{
264
    index -= rhs.index;
249✔
265
    return *this;
249✔
266
}
267

268
bool operator>(const column_t::index_t &left, const column_t &right)
14,221,856✔
269
{
270
    return column_t(left) > right;
14,221,856✔
271
}
272

273
bool operator>=(const column_t::index_t &left, const column_t &right)
2✔
274
{
275
    return column_t(left) >= right;
2✔
276
}
277

278
bool operator<(const column_t::index_t &left, const column_t &right)
14,221,855✔
279
{
280
    return column_t(left) < right;
14,221,855✔
281
}
282

283
bool operator<=(const column_t::index_t &left, const column_t &right)
2✔
284
{
285
    return column_t(left) <= right;
2✔
286
}
287

288
void swap(column_t &left, column_t &right)
×
289
{
290
    using std::swap;
291
    swap(left.index, right.index);
×
292
}
×
293

294
std::size_t column_hash::operator()(const column_t &k) const
38,153✔
295
{
296
    static std::hash<column_t::index_t> hasher;
297
    return hasher(k.index);
38,153✔
298
}
299

300
} // namespace xlnt
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