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

xlnt-community / xlnt / 677b76fc-3901-4722-b4c8-ce9367a0b564

26 Apr 2025 06:05PM UTC coverage: 81.8% (-0.5%) from 82.27%
677b76fc-3901-4722-b4c8-ce9367a0b564

Pull #79

circleci

m7913d
Disabled samples and benchmarks while generating coverage report

Coverage report should be based on the real unit tests.
Pull Request #79: Publishing coverage to github pages

14023 of 18604 branches covered (75.38%)

11488 of 14044 relevant lines covered (81.8%)

10384.36 hits per line

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

94.96
./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,485✔
34
{
35
    if (column_string.length() > 3 || column_string.empty())
1,485✔
36
    {
37
        throw invalid_column_index();
2✔
38
    }
39

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

43
    for (int i = static_cast<int>(column_string.length()) - 1; i >= 0; i--)
2,983✔
44
    {
45
        if (!std::isalpha(column_string[static_cast<std::size_t>(i)]))
1,501✔
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,500✔
51

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

56
    return column_index;
1,482✔
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)
1,406✔
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())
1,406!
68
    {
69
        throw invalid_column_index();
1✔
70
    }
71

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

75
    while (temp > 0)
2,812✔
76
    {
77
        int quotient = temp / 26, remainder = temp % 26;
1,407✔
78

79
        // check for exact division and borrow if needed
80
        if (remainder == 0)
1,407!
81
        {
82
            quotient -= 1;
×
83
            remainder = 26;
×
84
        }
85

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

90
    return column_letter;
1,405✔
91
}
×
92

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

98
column_t::column_t(index_t column_index)
88,637✔
99
    : index(column_index)
88,637✔
100
{
101
}
88,637✔
102

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

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

113
std::string column_t::column_string() const
1,405✔
114
{
115
    return column_string_from_index(index);
1,405✔
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
30,476✔
129
{
130
    return index == other.index;
30,476✔
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
12,405✔
139
{
140
    return *this == column_t(static_cast<index_t>(other));
12,405✔
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
15✔
154
{
155
    return *this == column_t(other);
15✔
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
1,447✔
179
{
180
    return index > other.index;
1,447✔
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
15,905✔
189
{
190
    return index < other.index;
15,905✔
191
}
192

193
bool column_t::operator<=(const column_t &other) const
33,241✔
194
{
195
    return index <= other.index;
33,241✔
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++()
9,070✔
219
{
220
    index++;
9,070✔
221
    return *this;
9,070✔
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)
1,434✔
231
{
232
    column_t copy(index);
1,434✔
233
    ++(*this);
1,434✔
234
    return copy;
1,434✔
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)
2✔
245
{
246
    lhs += rhs;
2✔
247
    return lhs;
2✔
248
}
249

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

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

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

268
bool operator>(const column_t::index_t &left, const column_t &right)
1,407✔
269
{
270
    return column_t(left) > right;
1,407✔
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)
1,406✔
279
{
280
    return column_t(left) < right;
1,406✔
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
46,353✔
295
{
296
    static std::hash<column_t::index_t> hasher;
297
    return hasher(k.index);
46,353✔
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