2
3
4
5
6
7
8
9
10
12#ifndef IPADDRESS_FIXED_STRING_HPP
13#define IPADDRESS_FIXED_STRING_HPP
21
22
23
24
25
26
27
30 using value_type =
char;
31 using const_pointer =
const char*;
32 using const_reference =
const char&;
33 using const_iterator = const_pointer;
34 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
36 static constexpr size_t max_length =
N;
43
44
45
46
50
51
52
53
54
55
56
57
60 const auto begin = &data[0];
61 const auto end = &data[N];
63 for (size_t i = 0; i < N; ++i) {
64 _data[i] = internal::next_char(it, begin, end);
65 if (_data[i] ==
'\0') {
73
74
75
76
77
78
79
80
83 const auto begin = &data[0];
84 const auto end = &data[N];
86 uint32_t error_symbol = 0;
87 for (size_t i = 0; i < N; ++i) {
88 _data[i] = internal::next_char_or_error(it, end, code, error_symbol);
89 if (_data[i] ==
'\0' || code != error_code::no_error) {
97
98
99
100
101
102
103
104
106 return const_iterator(_data);
110
111
112
113
114
115
116
117
119 return const_iterator(_data) + length;
123
124
125
126
127
128
129
130
132 return const_reverse_iterator(end());
136
137
138
139
140
141
142
143
145 return const_reverse_iterator(begin());
149
150
151
152
153
154
155
156
162
163
164
165
166
167
168
169
175
176
177
178
179
180
181
182
184 return const_reverse_iterator(cend());
188
189
190
191
192
193
194
195
197 return const_reverse_iterator(cbegin());
201
202
203
204
205
206
212
213
214
215
216
217
218
224
225
226
227
228
229
230
236
237
238
239
240
241
242
243
244
245
251
252
253
254
255
256
257
258
259
260
266
267
268
269
270
271
272
273
279
280
281
282
283
284
285
286
292
293
294
295
296
297
298
299
305
306
307
308
309
310
311
312
316 for (; i < size() && i < rhs.size(); ++i) {
317 const auto c1 = at(i);
318 const auto c2 = rhs.at(i);
320 return int(c1) -
int(c2);
324 if (i == size() && i == rhs.size()) {
326 }
else if (i == size() && i < rhs.size()) {
334
335
336
337
338
339
344 if (
sizeof(size_t) == 8) {
345 value = size_t(14695981039346656037ULL);
346 prime = size_t(1099511628211ULL);
348 value = size_t(2166136261U);
349 prime = size_t(16777619U);
352 for (size_t i = 0; i < size(); ++i) {
353 value ^=
static_cast<size_t>(_data[i]);
360
361
362
363
364
365
367 auto count = size() < other.size() ? other.size() : size();
368 for (size_t i = 0; i < count; ++i) {
370 _data[i] = other._data[i];
371 other._data[i] = tmp;
374 length = other.length;
381 using value_type =
char;
382 using const_pointer =
const char*;
383 using const_reference =
const char&;
384 using const_iterator = const_pointer;
385 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
387 static constexpr size_t max_length = 0;
389 static constexpr size_t length = 0;
421#if __cpp_char8_t >= 201811L
431 return const_iterator(
nullptr);
435 return const_iterator(
nullptr) + length;
439 return const_reverse_iterator(end());
443 return const_reverse_iterator(begin());
455 return const_reverse_iterator(cend());
459 return const_reverse_iterator(cbegin());
496 return rhs.empty() ? 0 : -1;
508
509
510
511
512
513
514
515
516
517
518
521 return lhs.compare(rhs) == 0;
525
526
527
528
529
530
531
532
533
534
535
538 return !(lhs == rhs);
541#ifdef IPADDRESS_HAS_SPACESHIP_OPERATOR
544
545
546
547
548
549
550
551
552
553
554 IPADDRESS_EXPORT
template <size_t N1, size_t N2>
555 IPADDRESS_NODISCARD IPADDRESS_CONSTEXPR IPADDRESS_FORCE_INLINE std::strong_ordering operator<=>(
const fixed_string<N1>& lhs,
const fixed_string<N2>& rhs) IPADDRESS_NOEXCEPT {
556 if (
const auto result = lhs.compare(rhs); result == 0) {
557 return std::strong_ordering::equivalent;
558 }
else if (result < 0) {
559 return std::strong_ordering::less;
561 return std::strong_ordering::greater;
568
569
570
571
572
573
574
575
576
577
580 return lhs.compare(rhs) < 0;
584
585
586
587
588
589
590
591
592
593
600
601
602
603
604
605
606
607
608
609
616
617
618
619
620
621
622
623
624
625
634
635
636
637
638
639
640
641
642
649
650
651
652
653
654
655
656
657
658
664#if IPADDRESS_CPP_VERSION
>= 17
666#if __cpp_char8_t >= 201811L
667 IPADDRESS_EXPORT
template <size_t N> fixed_string(
const char8_t(&)[N]) -> fixed_string<N - 1>;
669 IPADDRESS_EXPORT
template <size_t N> fixed_string(fixed_string<N>) -> fixed_string<N>;
670 IPADDRESS_EXPORT
template <size_t N> fixed_string(
const char(&)[N]) -> fixed_string<N - 1>;
671 IPADDRESS_EXPORT
template <size_t N> fixed_string(
const wchar_t(&)[N]) -> fixed_string<N - 1>;
672 IPADDRESS_EXPORT
template <size_t N> fixed_string(
const char16_t(&)[N]) -> fixed_string<N - 1>;
673 IPADDRESS_EXPORT
template <size_t N> fixed_string(
const char32_t(&)[N]) -> fixed_string<N - 1>;
674 IPADDRESS_EXPORT fixed_string() -> fixed_string<0>;
#define IPADDRESS_NOEXCEPT_WHEN_NO_EXCEPTIONS
Definition config.hpp:93
#define IPADDRESS_EXPORT
Definition config.hpp:42
#define IPADDRESS_NODISCARD
Definition config.hpp:98
#define IPADDRESS_FORCE_INLINE
Definition config.hpp:112
#define IPADDRESS_NAMESPACE
Definition config.hpp:38
#define IPADDRESS_NOEXCEPT
Definition config.hpp:89
#define IPADDRESS_NODISCARD_WHEN_NO_EXCEPTIONS
Definition config.hpp:102
constexpr inline bool operator>=(const fixed_string< N1 > &lhs, const fixed_string< N2 > &rhs) noexcept
Compares the contents of two fixed strings for greater than or equal relation.
Definition fixed-string.hpp:627
constexpr inline bool operator>(const fixed_string< N1 > &lhs, const fixed_string< N2 > &rhs) noexcept
Compares the contents of two fixed strings for greater than relation.
Definition fixed-string.hpp:595
error_code
Enumeration of error codes for IP address parsing and validation.
Definition errors.hpp:52
@ no_error
Indicates the absence of any errors.
constexpr inline bool operator<(const fixed_string< N1 > &lhs, const fixed_string< N2 > &rhs) noexcept
Compares the contents of two fixed strings lexicographically.
Definition fixed-string.hpp:579
constexpr inline fixed_string< N - 1 > make_fixed_string(const T(&data)[N], error_code &code) noexcept
Creates a fixed-length string from a character array.
Definition fixed-string.hpp:660
constexpr inline bool operator<=(const fixed_string< N1 > &lhs, const fixed_string< N2 > &rhs) noexcept
Compares the contents of two fixed strings for less than or equal relation.
Definition fixed-string.hpp:611
constexpr inline fixed_string< N - 1 > make_fixed_string(const T(&data)[N]) noexcept(noexcept(fixed_string< N - 1 >(data)))
Creates a fixed-length string from a character array.
Definition fixed-string.hpp:644
constexpr inline bool operator==(const fixed_string< N1 > &lhs, const fixed_string< N2 > &rhs) noexcept
Compares the contents of two fixed strings for equality.
Definition fixed-string.hpp:520
constexpr inline bool operator!=(const fixed_string< N1 > &lhs, const fixed_string< N2 > &rhs) noexcept
Compares the contents of two fixed strings for inequality.
Definition fixed-string.hpp:537
Fixed size string class.
Definition fixed-string.hpp:29
constexpr inline fixed_string() noexcept=default
Default constructor.
constexpr inline const_reverse_iterator crbegin() const noexcept
Retrieves the constant reverse begin iterator of the fixed_string.
Definition fixed-string.hpp:183
constexpr inline size_t capacity() const noexcept
Retrieves the capacity of the fixed_string.
Definition fixed-string.hpp:231
constexpr inline const_iterator begin() const noexcept
Retrieves the begin iterator of the fixed_string.
Definition fixed-string.hpp:105
constexpr inline bool empty() const noexcept
Checks if the fixed_string is empty.
Definition fixed-string.hpp:207
constexpr inline const_reverse_iterator crend() const noexcept
Retrieves the constant reverse end iterator of the fixed_string.
Definition fixed-string.hpp:196
constexpr inline const_reference front() const noexcept
Accesses the first element.
Definition fixed-string.hpp:274
constexpr inline const_pointer data() const noexcept
Provides a pointer to the underlying data.
Definition fixed-string.hpp:300
constexpr inline const_reference at(size_t n) const noexcept
Accesses the character at the specified location with bounds checking.
Definition fixed-string.hpp:261
constexpr inline const_reverse_iterator rend() const noexcept
Retrieves the reverse end iterator of the fixed_string.
Definition fixed-string.hpp:144
constexpr inline const_iterator cend() const noexcept
Retrieves the constant end iterator of the fixed_string.
Definition fixed-string.hpp:170
constexpr inline int compare(const fixed_string< N2 > &rhs) const noexcept
Compares the string with another fixed_string.
Definition fixed-string.hpp:314
constexpr inline fixed_string(const T(&data)[N+1]) noexcept(noexcept(internal::char_reader< T >::has_throw()))
Constructs a fixed_string from a character array.
Definition fixed-string.hpp:59
constexpr inline const_reference operator[](size_t n) const noexcept
Accesses the character at the specified location with bounds checking.
Definition fixed-string.hpp:246
constexpr inline size_t hash() const noexcept
Calculates the hash of the string.
Definition fixed-string.hpp:340
constexpr inline const_iterator cbegin() const noexcept
Retrieves the constant begin iterator of the fixed_string.
Definition fixed-string.hpp:157
constexpr inline const_iterator end() const noexcept
Retrieves the end iterator of the fixed_string.
Definition fixed-string.hpp:118
constexpr inline fixed_string(const T(&data)[N+1], error_code &code) noexcept
Constructs a fixed_string from a character array.
Definition fixed-string.hpp:82
constexpr inline size_t size() const noexcept
Retrieves the size of the fixed_string.
Definition fixed-string.hpp:219
constexpr inline const_reverse_iterator rbegin() const noexcept
Retrieves the reverse begin iterator of the fixed_string.
Definition fixed-string.hpp:131
constexpr inline void swap(fixed_string &other) noexcept
Swaps the contents with another fixed_string.
Definition fixed-string.hpp:366
constexpr inline const_reference back() const noexcept
Accesses the last element.
Definition fixed-string.hpp:287