Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Refactor v2 parser #149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ option(skyr_USE_STATIC_CRT "Use static C Runtime library (/MT or MTd)." ON)
option(skyr_BUILD_WITH_LLVM_LIBCXX "Instruct Clang to use LLVM's implementation of C++ standard library" OFF)
option(skyr_ENABLE_FILESYSTEM_FUNCTIONS "Enable functions to convert URL to std::filesystem::path" ON)
option(skyr_ENABLE_JSON_FUNCTIONS "Enable functions to convert URL components to JSON" ON)
option(skyr_BUILD_V2 "Build v2, which uses C++20 features" ON)
option(skyr_BUILD_V2 "Build v2, which uses C++20 features" OFF)

set(CMAKE_VERBOSE_MAKEFILE true)
if (skyr_BUILD_V2)
Expand Down
12 changes: 6 additions & 6 deletions include/skyr/v2/concepts/url_concepts.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Glyn Matthews 2018-19.
// Copyright (c) Glyn Matthews 2018-20.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
Expand All @@ -25,13 +25,13 @@ template <class T, class charT>
concept is_char_pointer = std::conjunction_v<std::is_pointer<T>, std::is_same<std::remove_pointer_t<T>, charT>>;

template <class T, class charT>
concept is_string_convertible =
concept is_string_container =
is_basic_string<T, charT> || is_basic_string_view<T, charT> || is_char_array<T, charT> || is_char_pointer<T, charT>;

template <typename T>
concept is_url_convertible =
is_string_convertible<T, char> || is_string_convertible<T, char8_t> || is_string_convertible<T, wchar_t> ||
is_string_convertible<T, char16_t> || is_string_convertible<T, char32_t>;
} // namespace skyr::v2
concept is_u8_convertible =
is_string_container<T, char> || is_string_container<T, char8_t> || is_string_container<T, wchar_t> ||
is_string_container<T, char16_t> || is_string_container<T, char32_t>;
} // namespace skyr::inline v2

#endif // SKYR_V2_CONCEPTS_URL_CONCEPTS_HPP
21 changes: 10 additions & 11 deletions include/skyr/v2/containers/static_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,15 @@ namespace skyr::inline v2 {
///
/// \tparam T
/// \tparam Capacity
template <
class T,
std::size_t Capacity
>
template <class T, std::size_t Capacity>
class static_vector {
private:

using impl_type = std::array<T, Capacity>;

impl_type impl_;
std::size_t size_ = 0;

public:

///
using value_type = T;
///
Expand Down Expand Up @@ -105,8 +100,7 @@ class static_vector {
/// \pre `size() < capacity()`
/// \post `size() > 0 && size() <= capacity()`
template <class... Args>
constexpr auto emplace_back(Args &&... args)
noexcept(std::is_trivially_move_assignable_v<T>) -> reference {
constexpr auto emplace_back(Args &&... args) noexcept(std::is_trivially_move_assignable_v<T>) -> reference {
impl_[size_++] = value_type{std::forward<Args>(args)...};
return back();
}
Expand Down Expand Up @@ -143,7 +137,13 @@ class static_vector {
}

///
/// \return `true` if there are elements
/// \return
[[nodiscard]] constexpr auto capacity() const noexcept -> size_type {
return Capacity;
}

///
/// \return `true` if there are no elements
[[nodiscard]] constexpr auto empty() const noexcept -> bool {
return size_ == 0;
}
Expand Down Expand Up @@ -195,8 +195,7 @@ class static_vector {
[[nodiscard]] constexpr auto end() const noexcept -> const_iterator {
return cend();
}

};
} // namespace skyr::v2
} // namespace skyr::inline v2

#endif // SKYR_V2_CONTAINERS_STATIC_VECTOR_HPP
14 changes: 2 additions & 12 deletions include/skyr/v2/core/check_input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <iterator>

namespace skyr::inline v2 {
constexpr static auto is_c0_control_or_space = [] (auto byte) {
constexpr static auto is_c0_control_or_space = [](auto byte) {
return std::iscntrl(byte, std::locale::classic()) || std::isspace(byte, std::locale::classic());
};

Expand All @@ -31,16 +31,6 @@ constexpr inline auto remove_trailing_c0_control_or_space(std::string_view input
input.remove_suffix(std::distance(first, it));
return input;
}

inline auto remove_tabs_and_newlines(std::string &input, bool *validation_error) {
constexpr auto is_tab_or_newline = [] (auto byte) {
return (byte == '\t') || (byte == '\r') || (byte == '\n');
};

auto it = std::remove_if(std::begin(input), std::end(input), is_tab_or_newline);
*validation_error |= (it != std::cend(input));
input.erase(it, std::cend(input));
}
} // namespace skyr::v2
} // namespace skyr::inline v2

#endif // SKYR_V2_CORE_CHECK_INPUT_HPP
42 changes: 27 additions & 15 deletions include/skyr/v2/core/errors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,36 @@ enum class url_parse_errc {
namespace details {
class url_parse_error_category : public std::error_category {
public:
[[nodiscard]] auto name() const noexcept -> const char * override {
[[nodiscard]] auto name() const noexcept -> const char* override {
return "url parse";
}

[[nodiscard]] auto message(int error) const noexcept -> std::string override {
switch (static_cast<url_parse_errc>(error)) {
case url_parse_errc::invalid_scheme_character:return "Invalid URL scheme";
case url_parse_errc::not_an_absolute_url_with_fragment:return "Not an absolute URL with fragment";
case url_parse_errc::empty_hostname:return "Empty hostname";
case url_parse_errc::invalid_ipv4_address:return "Invalid IPv4 address";
case url_parse_errc::invalid_ipv6_address:return "Invalid IPv6 address";
case url_parse_errc::forbidden_host_point:return "Forbidden host point";
case url_parse_errc::cannot_decode_host_point:return "Cannot decode host point";
case url_parse_errc::domain_error:return "Domain error";
case url_parse_errc::cannot_be_a_base_url:return "Cannot be a base URL";
case url_parse_errc::cannot_have_a_username_password_or_port:return "Cannot have a username, password or port";
case url_parse_errc::invalid_port:return "Invalid port";
default:return "(Unknown error)";
case url_parse_errc::invalid_scheme_character:
return "Invalid URL scheme";
case url_parse_errc::not_an_absolute_url_with_fragment:
return "Not an absolute URL with fragment";
case url_parse_errc::empty_hostname:
return "Empty hostname";
case url_parse_errc::invalid_ipv4_address:
return "Invalid IPv4 address";
case url_parse_errc::invalid_ipv6_address:
return "Invalid IPv6 address";
case url_parse_errc::forbidden_host_point:
return "Forbidden host point";
case url_parse_errc::cannot_decode_host_point:
return "Cannot decode host point";
case url_parse_errc::domain_error:
return "Domain error";
case url_parse_errc::cannot_be_a_base_url:
return "Cannot be a base URL";
case url_parse_errc::cannot_have_a_username_password_or_port:
return "Cannot have a username, password or port";
case url_parse_errc::invalid_port:
return "Invalid port";
default:
return "(Unknown error)";
}
}
};
Expand All @@ -73,11 +85,11 @@ inline auto make_error_code(url_parse_errc error) noexcept -> std::error_code {
static const details::url_parse_error_category category{};
return std::error_code(static_cast<int>(error), category);
}
} // namespace skyr::v2
} // namespace skyr::inline v2

namespace std {
template <>
struct is_error_code_enum<skyr::v2::url_parse_errc> : true_type {};
} // namespace std

#endif // SKYR_V2_CORE_ERRORS_HPP
#endif // SKYR_V2_CORE_ERRORS_HPP
Loading