Skip to content

Commit bcdde1a

Browse files
authored
Refactor v2 parser (#149)
* Minor changes to serializing IPv4 and IPv6 addresses * Updated concept names * Applied clang-format * Added script to generate IDNA table data for v2 * Refactored punycode function internals * Refactored host parsing and serialization functions so that they use fmt and ranges libraries (to be later replaced with the std versions) * Refactored url_parser_context.hpp * Refactored part of the parser * These are only minor changes
1 parent 403b168 commit bcdde1a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+6473
-1599
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ option(skyr_USE_STATIC_CRT "Use static C Runtime library (/MT or MTd)." ON)
2525
option(skyr_BUILD_WITH_LLVM_LIBCXX "Instruct Clang to use LLVM's implementation of C++ standard library" OFF)
2626
option(skyr_ENABLE_FILESYSTEM_FUNCTIONS "Enable functions to convert URL to std::filesystem::path" ON)
2727
option(skyr_ENABLE_JSON_FUNCTIONS "Enable functions to convert URL components to JSON" ON)
28-
option(skyr_BUILD_V2 "Build v2, which uses C++20 features" ON)
28+
option(skyr_BUILD_V2 "Build v2, which uses C++20 features" OFF)
2929

3030
set(CMAKE_VERBOSE_MAKEFILE true)
3131
if (skyr_BUILD_V2)

include/skyr/v2/concepts/url_concepts.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Glyn Matthews 2018-19.
1+
// Copyright (c) Glyn Matthews 2018-20.
22
// Distributed under the Boost Software License, Version 1.0.
33
// (See accompanying file LICENSE_1_0.txt or copy at
44
// http://www.boost.org/LICENSE_1_0.txt)
@@ -25,13 +25,13 @@ template <class T, class charT>
2525
concept is_char_pointer = std::conjunction_v<std::is_pointer<T>, std::is_same<std::remove_pointer_t<T>, charT>>;
2626

2727
template <class T, class charT>
28-
concept is_string_convertible =
28+
concept is_string_container =
2929
is_basic_string<T, charT> || is_basic_string_view<T, charT> || is_char_array<T, charT> || is_char_pointer<T, charT>;
3030

3131
template <typename T>
32-
concept is_url_convertible =
33-
is_string_convertible<T, char> || is_string_convertible<T, char8_t> || is_string_convertible<T, wchar_t> ||
34-
is_string_convertible<T, char16_t> || is_string_convertible<T, char32_t>;
35-
} // namespace skyr::v2
32+
concept is_u8_convertible =
33+
is_string_container<T, char> || is_string_container<T, char8_t> || is_string_container<T, wchar_t> ||
34+
is_string_container<T, char16_t> || is_string_container<T, char32_t>;
35+
} // namespace skyr::inline v2
3636

3737
#endif // SKYR_V2_CONCEPTS_URL_CONCEPTS_HPP

include/skyr/v2/containers/static_vector.hpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,15 @@ namespace skyr::inline v2 {
1515
///
1616
/// \tparam T
1717
/// \tparam Capacity
18-
template <
19-
class T,
20-
std::size_t Capacity
21-
>
18+
template <class T, std::size_t Capacity>
2219
class static_vector {
2320
private:
24-
2521
using impl_type = std::array<T, Capacity>;
2622

2723
impl_type impl_;
2824
std::size_t size_ = 0;
2925

3026
public:
31-
3227
///
3328
using value_type = T;
3429
///
@@ -105,8 +100,7 @@ class static_vector {
105100
/// \pre `size() < capacity()`
106101
/// \post `size() > 0 && size() <= capacity()`
107102
template <class... Args>
108-
constexpr auto emplace_back(Args &&... args)
109-
noexcept(std::is_trivially_move_assignable_v<T>) -> reference {
103+
constexpr auto emplace_back(Args &&... args) noexcept(std::is_trivially_move_assignable_v<T>) -> reference {
110104
impl_[size_++] = value_type{std::forward<Args>(args)...};
111105
return back();
112106
}
@@ -143,7 +137,13 @@ class static_vector {
143137
}
144138

145139
///
146-
/// \return `true` if there are elements
140+
/// \return
141+
[[nodiscard]] constexpr auto capacity() const noexcept -> size_type {
142+
return Capacity;
143+
}
144+
145+
///
146+
/// \return `true` if there are no elements
147147
[[nodiscard]] constexpr auto empty() const noexcept -> bool {
148148
return size_ == 0;
149149
}
@@ -195,8 +195,7 @@ class static_vector {
195195
[[nodiscard]] constexpr auto end() const noexcept -> const_iterator {
196196
return cend();
197197
}
198-
199198
};
200-
} // namespace skyr::v2
199+
} // namespace skyr::inline v2
201200

202201
#endif // SKYR_V2_CONTAINERS_STATIC_VECTOR_HPP

include/skyr/v2/core/check_input.hpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <iterator>
1313

1414
namespace skyr::inline v2 {
15-
constexpr static auto is_c0_control_or_space = [] (auto byte) {
15+
constexpr static auto is_c0_control_or_space = [](auto byte) {
1616
return std::iscntrl(byte, std::locale::classic()) || std::isspace(byte, std::locale::classic());
1717
};
1818

@@ -31,16 +31,6 @@ constexpr inline auto remove_trailing_c0_control_or_space(std::string_view input
3131
input.remove_suffix(std::distance(first, it));
3232
return input;
3333
}
34-
35-
inline auto remove_tabs_and_newlines(std::string &input, bool *validation_error) {
36-
constexpr auto is_tab_or_newline = [] (auto byte) {
37-
return (byte == '\t') || (byte == '\r') || (byte == '\n');
38-
};
39-
40-
auto it = std::remove_if(std::begin(input), std::end(input), is_tab_or_newline);
41-
*validation_error |= (it != std::cend(input));
42-
input.erase(it, std::cend(input));
43-
}
44-
} // namespace skyr::v2
34+
} // namespace skyr::inline v2
4535

4636
#endif // SKYR_V2_CORE_CHECK_INPUT_HPP

include/skyr/v2/core/errors.hpp

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,36 @@ enum class url_parse_errc {
4343
namespace details {
4444
class url_parse_error_category : public std::error_category {
4545
public:
46-
[[nodiscard]] auto name() const noexcept -> const char * override {
46+
[[nodiscard]] auto name() const noexcept -> const char* override {
4747
return "url parse";
4848
}
4949

5050
[[nodiscard]] auto message(int error) const noexcept -> std::string override {
5151
switch (static_cast<url_parse_errc>(error)) {
52-
case url_parse_errc::invalid_scheme_character:return "Invalid URL scheme";
53-
case url_parse_errc::not_an_absolute_url_with_fragment:return "Not an absolute URL with fragment";
54-
case url_parse_errc::empty_hostname:return "Empty hostname";
55-
case url_parse_errc::invalid_ipv4_address:return "Invalid IPv4 address";
56-
case url_parse_errc::invalid_ipv6_address:return "Invalid IPv6 address";
57-
case url_parse_errc::forbidden_host_point:return "Forbidden host point";
58-
case url_parse_errc::cannot_decode_host_point:return "Cannot decode host point";
59-
case url_parse_errc::domain_error:return "Domain error";
60-
case url_parse_errc::cannot_be_a_base_url:return "Cannot be a base URL";
61-
case url_parse_errc::cannot_have_a_username_password_or_port:return "Cannot have a username, password or port";
62-
case url_parse_errc::invalid_port:return "Invalid port";
63-
default:return "(Unknown error)";
52+
case url_parse_errc::invalid_scheme_character:
53+
return "Invalid URL scheme";
54+
case url_parse_errc::not_an_absolute_url_with_fragment:
55+
return "Not an absolute URL with fragment";
56+
case url_parse_errc::empty_hostname:
57+
return "Empty hostname";
58+
case url_parse_errc::invalid_ipv4_address:
59+
return "Invalid IPv4 address";
60+
case url_parse_errc::invalid_ipv6_address:
61+
return "Invalid IPv6 address";
62+
case url_parse_errc::forbidden_host_point:
63+
return "Forbidden host point";
64+
case url_parse_errc::cannot_decode_host_point:
65+
return "Cannot decode host point";
66+
case url_parse_errc::domain_error:
67+
return "Domain error";
68+
case url_parse_errc::cannot_be_a_base_url:
69+
return "Cannot be a base URL";
70+
case url_parse_errc::cannot_have_a_username_password_or_port:
71+
return "Cannot have a username, password or port";
72+
case url_parse_errc::invalid_port:
73+
return "Invalid port";
74+
default:
75+
return "(Unknown error)";
6476
}
6577
}
6678
};
@@ -73,11 +85,11 @@ inline auto make_error_code(url_parse_errc error) noexcept -> std::error_code {
7385
static const details::url_parse_error_category category{};
7486
return std::error_code(static_cast<int>(error), category);
7587
}
76-
} // namespace skyr::v2
88+
} // namespace skyr::inline v2
7789

7890
namespace std {
7991
template <>
8092
struct is_error_code_enum<skyr::v2::url_parse_errc> : true_type {};
8193
} // namespace std
8294

83-
#endif // SKYR_V2_CORE_ERRORS_HPP
95+
#endif // SKYR_V2_CORE_ERRORS_HPP

0 commit comments

Comments
 (0)