Skip to content

Commit f4631ac

Browse files
authored
Added JSON query encoding/decoding and modular changes (#65)
* Added prototype for converting between URL components and JSON * Added implementation and tests for converting a query string to a JSON data structure and back * Added optional value to query_iterator * Added error object for JSON query objects * Moved some more deckchairs around
1 parent f2dd72f commit f4631ac

Some content is hidden

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

43 files changed

+469
-6997
lines changed

.appveyor.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ before_build:
3030
-A x64
3131
-Dskyr_WARNINGS_AS_ERRORS=OFF
3232
-Dskyr_BUILD_TESTS=ON
33-
-Dskyr_BUILD_WPT_TESTS=ON
3433
-Dskyr_BUILD_DOCS=OFF
3534
-Dskyr_BUILD_EXAMPLES=OFF
3635
-DCMAKE_TOOLCHAIN_FILE=C:\Tools\vcpkg\scripts\buildsystems\vcpkg.cmake

.clang-tidy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Checks: '-*,bugprone-*,-bugprone-exception-escape,clang-diagnostic-*,cppcoreguidelines-*,-cppcoreguidelines-avoid-magic-numbers,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-macro-usage,-cppcoreguidelines-non-private-member-variables-in-classes,-cppcoreguidelines-avoid-c-arrays,misc-*,-misc-unused-parameters,-misc-non-private-member-variables-in-classes,modernize-*,-modernize-use-trailing-return-type,performance-*'
1+
Checks: '-*,bugprone-*,-bugprone-exception-escape,clang-diagnostic-*,cppcoreguidelines-*,-cppcoreguidelines-avoid-magic-numbers,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-macro-usage,-cppcoreguidelines-non-private-member-variables-in-classes,-cppcoreguidelines-avoid-c-arrays,misc-*,-misc-unused-parameters,-misc-non-private-member-variables-in-classes,modernize-*,performance-*'
22
CheckOptions:
33
- key: readability-identifier-naming.ClassCase
44
value: lower_case

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ set(CMAKE_CXX_EXTENSIONS OFF)
2929
set(CMAKE_CXX_STANDARD_REQUIRED ON)
3030

3131
find_package(tl-expected CONFIG REQUIRED)
32+
find_package(nlohmann_json CONFIG REQUIRED)
3233

3334
if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU OR
3435
${CMAKE_CXX_COMPILER_ID} MATCHES Clang)

examples/example_04.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
// http://www.boost.org/LICENSE_1_0.txt)
55

66
#include <iostream>
7-
#include <skyr/core/url_parse.hpp>
8-
#include <skyr/core/url_serialize.hpp>
7+
#include <skyr/core/parse.hpp>
8+
#include <skyr/core/serialize.hpp>
99

1010
int main(int argc, char *argv[]) {
1111
auto base = skyr::parse("https://example.org/");
Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,45 @@
33
// (See accompanying file LICENSE_1_0.txt or copy at
44
// http://www.boost.org/LICENSE_1_0.txt)
55

6-
#include <string>
7-
#include "skyr/core/url_error.hpp"
6+
#ifndef SKYR_CORE_URL_ERROR_INC
7+
#define SKYR_CORE_URL_ERROR_INC
8+
9+
#include <system_error>
810

911
namespace skyr {
1012
inline namespace v1 {
11-
namespace {
13+
/// \enum url_parse_errc
14+
/// Enumerates URL parser errors
15+
enum class url_parse_errc {
16+
/// The string contains an invalid Unicode character
17+
invalid_unicode_character = 1,
18+
/// A character is not a valid scheme character
19+
invalid_scheme_character,
20+
/// The URL is not an absolute URL with fragment
21+
not_an_absolute_url_with_fragment,
22+
/// Cannot set scheme value
23+
cannot_override_scheme,
24+
/// The ostname is empty
25+
empty_hostname,
26+
/// Invalid IPv4 address
27+
invalid_ipv4_address,
28+
/// Invalid IPv6 address
29+
invalid_ipv6_address,
30+
/// A character is a forbidden host point
31+
forbidden_host_point,
32+
/// Unable to decode host point
33+
cannot_decode_host_point,
34+
/// Invalid domain string
35+
domain_error,
36+
/// The URL cannot be a base URL
37+
cannot_be_a_base_url,
38+
/// The URL cannot have a username, password or port
39+
cannot_have_a_username_password_or_port,
40+
/// Invalid port value
41+
invalid_port,
42+
};
43+
44+
namespace details {
1245
class url_parse_error_category : public std::error_category {
1346
public:
1447
[[nodiscard]] auto name() const noexcept -> const char * override {
@@ -32,12 +65,21 @@ class url_parse_error_category : public std::error_category {
3265
}
3366
}
3467
};
68+
} // namespace details
3569

36-
const url_parse_error_category category{};
37-
} // namespace
38-
39-
auto make_error_code(url_parse_errc error) noexcept -> std::error_code {
70+
/// Creates a `std::error_code` given a `skyr::url_parse_errc` value
71+
/// \param error A URL parse error
72+
/// \returns A `std::error_code` object
73+
inline auto make_error_code(url_parse_errc error) noexcept -> std::error_code {
74+
static const details::url_parse_error_category category{};
4075
return std::error_code(static_cast<int>(error), category);
4176
}
4277
} // namespace v1
4378
} // namespace skyr
79+
80+
namespace std {
81+
template <>
82+
struct is_error_code_enum<skyr::v1::url_parse_errc> : true_type {};
83+
} // namespace std
84+
85+
#endif // SKYR_CORE_URL_ERROR_INC
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ inline namespace v1 {
2020
/// \returns A `url_record` on success and an error code on failure
2121
auto parse(
2222
std::string_view input,
23-
std::optional<url_record> base = std::nullopt) -> tl::expected<url_record, std::error_code>;
23+
std::optional<url_record> base=std::nullopt) -> tl::expected<url_record, std::error_code>;
2424
} // namespace v1
2525
} // namespace skyr
2626

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ inline namespace v1 {
1818
/// serialization, if set
1919
/// \returns A serialized URL string
2020
auto serialize(
21-
const url_record &url, bool exclude_fragment = false) -> url_record::string_type;
21+
const url_record &url, bool exclude_fragment=false) -> url_record::string_type;
2222
} // namespace v1
2323
} // namespace skyr
2424

include/skyr/core/url_error.hpp

Lines changed: 0 additions & 56 deletions
This file was deleted.

include/skyr/core/url_record.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <string>
1111
#include <cstdint>
1212
#include <optional>
13-
#include <skyr/core/url_schemes.hpp>
13+
#include <skyr/core/schemes.hpp>
1414

1515
namespace skyr {
1616
inline namespace v1 {

0 commit comments

Comments
 (0)