Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
VladimirShaleev committed Apr 26, 2024
1 parent 2f8451c commit 647788e
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 28 deletions.
10 changes: 0 additions & 10 deletions include/ipaddress/uint128.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1565,17 +1565,11 @@ class uint128_t final { // NOLINT(cppcoreguidelines-special-member-functions)
return result;
}


#pragma warning(push, 3)
#ifdef __GNUC__
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wundefined-inline"
#endif
#ifdef __clang__
_Pragma("clang diagnostic push")
_Pragma("clang diagnostic ignored \"-Wundefined-inline\"")
#endif

template <typename T>
IPADDRESS_NODISCARD static IPADDRESS_CONSTEXPR IPADDRESS_FORCE_INLINE optional<uint128_t> str_to_uint128(const T* begin, const T* end, format fmt) IPADDRESS_NOEXCEPT {
switch (fmt) {
Expand All @@ -1587,13 +1581,9 @@ class uint128_t final { // NOLINT(cppcoreguidelines-special-member-functions)
return dec_str_to_uint128(begin, end);
}
}

#ifdef __clang__
_Pragma("clang diagnostic pop")
#endif
#ifdef __GNUC__
# pragma GCC diagnostic pop
#endif
#pragma warning(pop)

template <typename T>
Expand Down
6 changes: 3 additions & 3 deletions tests/ip-address-tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,8 @@ INSTANTIATE_TEST_SUITE_P(
std::make_tuple("::1%scope_id/24", error_code::invalid_scope_id, "invalid scope id in address ::1%scope_id/24")
));

template <typename T, size_t N1, size_t N2, size_t N3>
static void parse_unexpected_symbol(const T (&expected_address)[N1], const T (&expected_scope)[N2], const T (&str)[N3]) { // NOLINT(readability-function-cognitive-complexity)
template <typename T, size_t N1, size_t N2>
static void parse_unexpected_symbol(const T (&expected_address)[N1], const T (&expected_scope)[N2]) { // NOLINT(readability-function-cognitive-complexity)
using tstring = std::basic_string<T, std::char_traits<T>, std::allocator<T>>;
using tistringstream = std::basic_istringstream<T, std::char_traits<T>, std::allocator<T>>;

Expand Down Expand Up @@ -486,7 +486,7 @@ static void parse_unexpected_symbol(const T (&expected_address)[N1], const T (&e
ASSERT_THROW((ip.set_scope_id(tstring(expected_scope))), parse_error);
#endif
}
#define PARSE_UNEXPECTED_SYMBOL(unicode) parse_unexpected_symbol(unicode##"200\U00010348:d\ud55c8::1", unicode##"12\ud55c3", unicode##"2001:db8::1%123 200\U00010348:d\ud55c8::1 2001:db8::1%12\ud55c3")
#define PARSE_UNEXPECTED_SYMBOL(unicode) parse_unexpected_symbol(unicode##"200\U00010348:d\ud55c8::1", unicode##"12\ud55c3")

#if __cpp_char8_t >= 201811L
TEST(ip_address, ParseUnexpectedUtf8) {
Expand Down
6 changes: 3 additions & 3 deletions tests/ip-network-tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ INSTANTIATE_TEST_SUITE_P(
std::make_tuple("1234:axy::b%scope", error_code::part_has_invalid_symbol, "in part 0 of address 1234:axy::b%scope has invalid symbols")
));

template <typename T, size_t N1, size_t N2>
static void parse_unexpected_symbol(const T (&expected_address)[N1], const T (&str)[N2]) {
template <typename T, size_t N>
static void parse_unexpected_symbol(const T (&expected_address)[N]) {
using tstring = std::basic_string<T, std::char_traits<T>, std::allocator<T>>;
using tistringstream = std::basic_istringstream<T, std::char_traits<T>, std::allocator<T>>;

Expand Down Expand Up @@ -377,7 +377,7 @@ static void parse_unexpected_symbol(const T (&expected_address)[N1], const T (&s
ASSERT_THROW((ip_network::parse(tstring(expected_address))), parse_error);
#endif
}
#define PARSE_UNEXPECTED_SYMBOL(unicode) parse_unexpected_symbol(unicode##"2001:dc8::/1\ud55c2\ud55c", unicode##"2001:db8::1/96 2001:db8::/3\ud55c")
#define PARSE_UNEXPECTED_SYMBOL(unicode) parse_unexpected_symbol(unicode##"2001:dc8::/1\ud55c2\ud55c")

#if __cpp_char8_t >= 201811L
TEST(ip_network, ParseUnexpectedUtf8) {
Expand Down
6 changes: 3 additions & 3 deletions tests/ipv4-address-tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,8 @@ INSTANTIATE_TEST_SUITE_P(
std::make_tuple("1.2.3.040", error_code::leading_0_are_not_permitted, "leading zeros are not permitted in octet 3 of address 1.2.3.040")
));

template <typename T, size_t N1, size_t N2>
static void parse_unexpected_symbol(const T (&expected_address)[N1], const T (&str)[N2]) {
template <typename T, size_t N>
static void parse_unexpected_symbol(const T (&expected_address)[N]) {
using tstring = std::basic_string<T, std::char_traits<T>, std::allocator<T>>;
using tistringstream = std::basic_istringstream<T, std::char_traits<T>, std::allocator<T>>;

Expand Down Expand Up @@ -412,7 +412,7 @@ static void parse_unexpected_symbol(const T (&expected_address)[N1], const T (&s
ASSERT_THROW((ipv4_address::parse(tstring(expected_address))), parse_error);
#endif
}
#define PARSE_UNEXPECTED_SYMBOL(unicode) parse_unexpected_symbol(unicode##"127.\U00010348.\ud55c.1", unicode##"127.0.0.1 127.\U00010348.\ud55c.1")
#define PARSE_UNEXPECTED_SYMBOL(unicode) parse_unexpected_symbol(unicode##"127.\U00010348.\ud55c.1")

#if __cpp_char8_t >= 201811L
TEST(ipv4_address, ParseUnexpectedUtf8) {
Expand Down
6 changes: 3 additions & 3 deletions tests/ipv4-network-tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,8 +634,8 @@ INSTANTIATE_TEST_SUITE_P(
std::make_tuple("1.2.3.256", error_code::octet_exceeded_255, "octet 0 of address 1.2.3.256 exceeded 255")
));

template <typename T, size_t N1, size_t N2>
static void parse_unexpected_symbol(const T (&expected_address)[N1], const T (&str)[N2]) {
template <typename T, size_t N>
static void parse_unexpected_symbol(const T (&expected_address)[N]) {
using tstring = std::basic_string<T, std::char_traits<T>, std::allocator<T>>;
using tistringstream = std::basic_istringstream<T, std::char_traits<T>, std::allocator<T>>;

Expand Down Expand Up @@ -667,7 +667,7 @@ static void parse_unexpected_symbol(const T (&expected_address)[N1], const T (&s
ASSERT_THROW((ipv4_network::parse(tstring(expected_address))), parse_error);
#endif
}
#define PARSE_UNEXPECTED_SYMBOL(unicode) parse_unexpected_symbol(unicode##"127.0.0.1/3\ud55c", unicode##"127.0.0.1/16 127.0.0.1/3\ud55c")
#define PARSE_UNEXPECTED_SYMBOL(unicode) parse_unexpected_symbol(unicode##"127.0.0.1/3\ud55c")

#if __cpp_char8_t >= 201811L
TEST(ipv4_network, ParseUnexpectedUtf8) {
Expand Down
6 changes: 3 additions & 3 deletions tests/ipv6-address-tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,8 +620,8 @@ INSTANTIATE_TEST_SUITE_P(
std::make_tuple("::1%scope_id/24", error_code::invalid_scope_id, "invalid scope id in address ::1%scope_id/24")
));

template <typename T, size_t N1, size_t N2, size_t N3>
static void parse_unexpected_symbol(const T (&expected_address)[N1], const T (&expected_scope)[N2], const T (&str)[N3]) { // NOLINT(readability-function-cognitive-complexity)
template <typename T, size_t N1, size_t N2>
static void parse_unexpected_symbol(const T (&expected_address)[N1], const T (&expected_scope)[N2]) { // NOLINT(readability-function-cognitive-complexity)
using tstring = std::basic_string<T, std::char_traits<T>, std::allocator<T>>;
using tistringstream = std::basic_istringstream<T, std::char_traits<T>, std::allocator<T>>;

Expand Down Expand Up @@ -683,7 +683,7 @@ static void parse_unexpected_symbol(const T (&expected_address)[N1], const T (&e
ASSERT_THROW((ip.set_scope_id(tstring(expected_scope))), parse_error);
#endif
}
#define PARSE_UNEXPECTED_SYMBOL(unicode) parse_unexpected_symbol(unicode##"200\U00010348:d\ud55c8::1", unicode##"12\ud55c3", unicode##"2001:db8::1%123 200\U00010348:d\ud55c8::1 2001:db8::1%12\ud55c3")
#define PARSE_UNEXPECTED_SYMBOL(unicode) parse_unexpected_symbol(unicode##"200\U00010348:d\ud55c8::1", unicode##"12\ud55c3")

#if __cpp_char8_t >= 201811L
TEST(ipv6_address, ParseUnexpectedUtf8) {
Expand Down
6 changes: 3 additions & 3 deletions tests/ipv6-network-tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,8 +633,8 @@ INSTANTIATE_TEST_SUITE_P(
std::make_tuple("1234:axy::b%scope", error_code::part_has_invalid_symbol, "in part 0 of address 1234:axy::b%scope has invalid symbols")
));

template <typename T, size_t N1, size_t N2>
static void parse_unexpected_symbol(const T (&expected_address)[N1], const T (&str)[N2]) {
template <typename T, size_t N>
static void parse_unexpected_symbol(const T (&expected_address)[N]) {
using tstring = std::basic_string<T, std::char_traits<T>, std::allocator<T>>;
using tistringstream = std::basic_istringstream<T, std::char_traits<T>, std::allocator<T>>;

Expand Down Expand Up @@ -666,7 +666,7 @@ static void parse_unexpected_symbol(const T (&expected_address)[N1], const T (&s
ASSERT_THROW((ipv6_network::parse(tstring(expected_address))), parse_error);
#endif
}
#define PARSE_UNEXPECTED_SYMBOL(unicode) parse_unexpected_symbol(unicode##"2001:dc8::/1\ud55c2\ud55c", unicode##"2001:db8::1/96 2001:db8::/3\ud55c")
#define PARSE_UNEXPECTED_SYMBOL(unicode) parse_unexpected_symbol(unicode##"2001:dc8::/1\ud55c2\ud55c")

#if __cpp_char8_t >= 201811L
TEST(ipv6_network, ParseUnexpectedUtf8) {
Expand Down

0 comments on commit 647788e

Please sign in to comment.