diff --git a/.clang-format b/.clang-format index 59d0684df..f6cb8ad93 100644 --- a/.clang-format +++ b/.clang-format @@ -1,2 +1 @@ BasedOnStyle: Google -SortIncludes: Never diff --git a/BUILD.bazel b/BUILD.bazel index 1c87d50a4..f84f96ced 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,20 +1,8 @@ cc_library( name = "ada", - srcs = [ - "src/ada.cpp", - ], - hdrs = glob([ - "include/*.h", - "include/ada/*.h", - # todo: this can be included by every client of the library, but there is no better way - # since .cpp files are included into each other. - "src/*.cpp", - ]), - # todo: once .cpp files are not included, rather then polluting -I flags, src/ should - # be dropped from hdrs and this replaced by `strip_include_prefix = "include"` - includes = [ - "include", - "include/ada", - ], + srcs = glob(["src/*.cpp"]), + hdrs = glob(["include/*.h"]), + includes = ["include"], + strip_include_prefix = "include", visibility = ["//visibility:public"], ) diff --git a/benchmarks/benchmark_header.h b/benchmarks/benchmark_header.h index 3351e2725..bca558ecd 100644 --- a/benchmarks/benchmark_header.h +++ b/benchmarks/benchmark_header.h @@ -1,14 +1,14 @@ +#include +#include +#include #include #include -#include #include -#include -#include #if ADA_VARIOUS_COMPETITION_ENABLED -#include #include #include +#include #endif #if ADA_url_whatwg_ENABLED #include diff --git a/benchmarks/competitors/servo-url/servo_url.h b/benchmarks/competitors/servo-url/servo_url.h index 406d5fc2f..f0d947639 100644 --- a/benchmarks/competitors/servo-url/servo_url.h +++ b/benchmarks/competitors/servo-url/servo_url.h @@ -6,8 +6,8 @@ #include #include #include -#include #include +#include namespace servo_url { diff --git a/benchmarks/performancecounters/event_counter.h b/benchmarks/performancecounters/event_counter.h index 4a1e5eca3..de1014332 100644 --- a/benchmarks/performancecounters/event_counter.h +++ b/benchmarks/performancecounters/event_counter.h @@ -5,11 +5,9 @@ #ifndef _MSC_VER #include #endif +#include #include - #include - -#include #include #include "linux-perf-events.h" diff --git a/benchmarks/performancecounters/linux-perf-events.h b/benchmarks/performancecounters/linux-perf-events.h index 7ed0f8d24..ce4d1c69d 100644 --- a/benchmarks/performancecounters/linux-perf-events.h +++ b/benchmarks/performancecounters/linux-perf-events.h @@ -8,9 +8,8 @@ #include // for errno #include // for memset -#include - #include +#include #include template diff --git a/include/ada.h b/include/ada.h deleted file mode 100644 index 7c579d95d..000000000 --- a/include/ada.h +++ /dev/null @@ -1,38 +0,0 @@ -/** - * @file ada.h - * @brief Includes all definitions for Ada. - */ -#ifndef ADA_H -#define ADA_H - -#include "ada/ada_idna.h" -#include "ada/character_sets-inl.h" -#include "ada/checkers-inl.h" -#include "ada/common_defs.h" -#include "ada/log.h" -#include "ada/encoding_type.h" -#include "ada/helpers.h" -#include "ada/parser.h" -#include "ada/scheme-inl.h" -#include "ada/serializers.h" -#include "ada/state.h" -#include "ada/unicode.h" -#include "ada/url_base.h" -#include "ada/url_base-inl.h" -#include "ada/url-inl.h" -#include "ada/url_components.h" -#include "ada/url_components-inl.h" -#include "ada/url_aggregator.h" -#include "ada/url_aggregator-inl.h" -#include "ada/url_search_params.h" -#include "ada/url_search_params-inl.h" -#include "ada/url_pattern.h" -#include "ada/url_pattern-inl.h" -#include "ada/url_pattern_helpers.h" -#include "ada/url_pattern_helpers-inl.h" - -// Public API -#include "ada/ada_version.h" -#include "ada/implementation.h" - -#endif // ADA_H diff --git a/include/ada/unicode-inl.h b/include/ada/unicode-inl.h deleted file mode 100644 index cd9339e6a..000000000 --- a/include/ada/unicode-inl.h +++ /dev/null @@ -1,50 +0,0 @@ -/** - * @file unicode-inl.h - * @brief Definitions for unicode operations. - */ -#ifndef ADA_UNICODE_INL_H -#define ADA_UNICODE_INL_H -#include "ada/unicode.h" -#include "ada/character_sets-inl.h" - -/** - * Unicode operations. These functions are not part of our public API and may - * change at any time. - * - * private - * @namespace ada::unicode - * @brief Includes the declarations for unicode operations - */ -namespace ada::unicode { -ada_really_inline size_t percent_encode_index(const std::string_view input, - const uint8_t character_set[]) { - const char* data = input.data(); - const size_t size = input.size(); - - // Process 8 bytes at a time using unrolled loop - size_t i = 0; - for (; i + 8 <= size; i += 8) { - unsigned char chunk[8]; - std::memcpy(&chunk, data + i, - 8); // entices compiler to unconditionally process 8 characters - - // Check 8 characters at once - for (size_t j = 0; j < 8; j++) { - if (character_sets::bit_at(character_set, chunk[j])) { - return i + j; - } - } - } - - // Handle remaining bytes - for (; i < size; i++) { - if (character_sets::bit_at(character_set, data[i])) { - return i; - } - } - - return size; -} -} // namespace ada::unicode - -#endif // ADA_UNICODE_INL_H diff --git a/include/ada_c.h b/include/ada_c.h index 44e945c96..100b87b0b 100644 --- a/include/ada_c.h +++ b/include/ada_c.h @@ -6,8 +6,8 @@ #define ADA_C_H #include -#include #include +#include // This is a reference to ada::url_components::omitted // It represents "uint32_t(-1)" diff --git a/include/ada/ada_idna.h b/include/ada_idna.h similarity index 100% rename from include/ada/ada_idna.h rename to include/ada_idna.h diff --git a/include/ada/ada_version.h b/include/ada_version.h similarity index 100% rename from include/ada/ada_version.h rename to include/ada_version.h diff --git a/include/ada/character_sets-inl.h b/include/character_sets-inl.h similarity index 99% rename from include/ada/character_sets-inl.h rename to include/character_sets-inl.h index 7e99a0512..8589184a0 100644 --- a/include/ada/character_sets-inl.h +++ b/include/character_sets-inl.h @@ -7,7 +7,7 @@ #ifndef ADA_CHARACTER_SETS_INL_H #define ADA_CHARACTER_SETS_INL_H -#include "ada/character_sets.h" +#include "character_sets.h" /** * These functions are not part of our public API and may diff --git a/include/ada/character_sets.h b/include/character_sets.h similarity index 95% rename from include/ada/character_sets.h rename to include/character_sets.h index c4ed90387..b66d8354a 100644 --- a/include/ada/character_sets.h +++ b/include/character_sets.h @@ -7,9 +7,10 @@ #ifndef ADA_CHARACTER_SETS_H #define ADA_CHARACTER_SETS_H -#include "ada/common_defs.h" #include +#include "common_defs.h" + /** * These functions are not part of our public API and may * change at any time. diff --git a/include/ada/checkers-inl.h b/include/checkers-inl.h similarity index 98% rename from include/ada/checkers-inl.h rename to include/checkers-inl.h index afe962715..1dbf907a5 100644 --- a/include/ada/checkers-inl.h +++ b/include/checkers-inl.h @@ -8,6 +8,8 @@ #include #include +#include "checkers.h" + namespace ada::checkers { constexpr bool has_hex_prefix_unsafe(std::string_view input) { diff --git a/include/ada/checkers.h b/include/checkers.h similarity index 99% rename from include/ada/checkers.h rename to include/checkers.h index e69cb4dd4..237e71768 100644 --- a/include/ada/checkers.h +++ b/include/checkers.h @@ -5,11 +5,11 @@ #ifndef ADA_CHECKERS_H #define ADA_CHECKERS_H -#include "ada/common_defs.h" - #include #include +#include "common_defs.h" + /** * These functions are not part of our public API and may * change at any time. diff --git a/include/ada/common_defs.h b/include/common_defs.h similarity index 99% rename from include/ada/common_defs.h rename to include/common_defs.h index 30a1ae99b..3060fccd8 100644 --- a/include/ada/common_defs.h +++ b/include/common_defs.h @@ -5,6 +5,10 @@ #ifndef ADA_COMMON_DEFS_H #define ADA_COMMON_DEFS_H +#ifdef ADA_DEVELOPMENT_CHECKS +#include +#endif + // https://en.cppreference.com/w/cpp/feature_test#Library_features // detect C++20 features #include diff --git a/include/ada/encoding_type.h b/include/encoding_type.h similarity index 95% rename from include/ada/encoding_type.h rename to include/encoding_type.h index 931590e2c..a4197f92d 100644 --- a/include/ada/encoding_type.h +++ b/include/encoding_type.h @@ -5,9 +5,10 @@ #ifndef ADA_ENCODING_TYPE_H #define ADA_ENCODING_TYPE_H -#include "ada/common_defs.h" #include +#include "common_defs.h" + namespace ada { /** diff --git a/include/ada/expected.h b/include/expected.h similarity index 100% rename from include/ada/expected.h rename to include/expected.h diff --git a/include/ada/helpers.h b/include/helpers.h similarity index 98% rename from include/ada/helpers.h rename to include/helpers.h index 96c4b5e15..aa6d8dd13 100644 --- a/include/ada/helpers.h +++ b/include/helpers.h @@ -5,12 +5,12 @@ #ifndef ADA_HELPERS_H #define ADA_HELPERS_H -#include "ada/common_defs.h" -#include "ada/state.h" -#include "ada/url_base.h" - -#include #include +#include + +#include "common_defs.h" +#include "state.h" +#include "url_base.h" #if ADA_DEVELOPMENT_CHECKS #include diff --git a/include/ada/implementation.h b/include/implementation.h similarity index 76% rename from include/ada/implementation.h rename to include/implementation.h index 33bf67978..cfe171a78 100644 --- a/include/ada/implementation.h +++ b/include/implementation.h @@ -7,20 +7,27 @@ #define ADA_IMPLEMENTATION_H #include -#include -#include "ada/parser.h" -#include "ada/common_defs.h" -#include "ada/encoding_type.h" -#include "ada/url.h" -#include "ada/state.h" -#include "ada/url_aggregator.h" +#include "common_defs.h" +#include "expected.h" + +/** + * @private + * Forward declarations. + */ +namespace ada { +struct url_pattern_options; +struct url_pattern_init; +class url_pattern; +struct url_aggregator; +struct url; +} // namespace ada namespace ada { enum class errors : uint8_t { type_error }; -template -using result = tl::expected; +template +using result = tl::expected; /** * The URL parser takes a scalar value string input, with an optional null or @@ -31,13 +38,13 @@ using result = tl::expected; * @param base_url the optional URL input to use as a base url. * @return a parsed URL. */ -template -ada_warn_unused ada::result parse( +template +ada_warn_unused result parse( std::string_view input, const result_type* base_url = nullptr); -extern template ada::result parse(std::string_view input, - const url* base_url); -extern template ada::result parse( +extern template result parse(std::string_view input, + const url* base_url); +extern template result parse( std::string_view input, const url_aggregator* base_url); /** diff --git a/include/ada/log.h b/include/log.h similarity index 96% rename from include/ada/log.h rename to include/log.h index c05526ae8..76f257026 100644 --- a/include/ada/log.h +++ b/include/log.h @@ -5,7 +5,7 @@ */ #ifndef ADA_LOG_H #define ADA_LOG_H -#include "ada/common_defs.h" +#include "common_defs.h" // To enable logging, set ADA_LOGGING to 1: #ifndef ADA_LOGGING diff --git a/include/ada/parser.h b/include/parser.h similarity index 88% rename from include/ada/parser.h rename to include/parser.h index 80e97decc..9761737e3 100644 --- a/include/ada/parser.h +++ b/include/parser.h @@ -8,19 +8,9 @@ #include #include -#include "ada/expected.h" - -/** - * @private - */ -namespace ada { -struct url_aggregator; -struct url; -class url_pattern; -struct url_pattern_options; -struct url_pattern_init; -enum class errors : uint8_t; -} // namespace ada +#include "expected.h" +#include "url.h" +#include "url_aggregator.h" /** * @namespace ada::parser diff --git a/include/ada/scheme-inl.h b/include/scheme-inl.h similarity index 99% rename from include/ada/scheme-inl.h rename to include/scheme-inl.h index a327dd049..4b899357e 100644 --- a/include/ada/scheme-inl.h +++ b/include/scheme-inl.h @@ -5,7 +5,7 @@ #ifndef ADA_SCHEME_INL_H #define ADA_SCHEME_INL_H -#include "ada/scheme.h" +#include "scheme.h" namespace ada::scheme { diff --git a/include/ada/scheme.h b/include/scheme.h similarity index 98% rename from include/ada/scheme.h rename to include/scheme.h index b83dccb48..0f6cc15f8 100644 --- a/include/ada/scheme.h +++ b/include/scheme.h @@ -5,11 +5,11 @@ #ifndef ADA_SCHEME_H #define ADA_SCHEME_H -#include "ada/common_defs.h" - #include #include +#include "common_defs.h" + /** * @namespace ada::scheme * @brief Includes the scheme declarations diff --git a/include/ada/serializers.h b/include/serializers.h similarity index 97% rename from include/ada/serializers.h rename to include/serializers.h index 260dcf3a1..463f52f3f 100644 --- a/include/ada/serializers.h +++ b/include/serializers.h @@ -5,11 +5,11 @@ #ifndef ADA_SERIALIZERS_H #define ADA_SERIALIZERS_H -#include "ada/common_defs.h" - #include #include +#include "common_defs.h" + /** * @namespace ada::serializers * @brief Includes the definitions for URL serializers diff --git a/include/ada/state.h b/include/state.h similarity index 98% rename from include/ada/state.h rename to include/state.h index f02c58ba1..ec780e94c 100644 --- a/include/ada/state.h +++ b/include/state.h @@ -5,10 +5,10 @@ #ifndef ADA_STATE_H #define ADA_STATE_H -#include "ada/common_defs.h" - #include +#include "common_defs.h" + namespace ada { /** diff --git a/include/unicode-inl.h b/include/unicode-inl.h new file mode 100644 index 000000000..927c545e6 --- /dev/null +++ b/include/unicode-inl.h @@ -0,0 +1,95 @@ +/** + * @file unicode-inl.h + * @brief Definitions for unicode operations. + */ +#ifndef ADA_UNICODE_INL_H +#define ADA_UNICODE_INL_H + +#include + +#include "character_sets.h" +#include "unicode.h" + +/** + * Unicode operations. These functions are not part of our public API and may + * change at any time. + * + * private + * @namespace ada::unicode + * @brief Includes the declarations for unicode operations + */ +namespace ada::unicode { +// A forbidden host code point is U+0000 NULL, U+0009 TAB, U+000A LF, U+000D CR, +// U+0020 SPACE, U+0023 (#), U+002F (/), U+003A (:), U+003C (<), U+003E (>), +// U+003F (?), U+0040 (@), U+005B ([), U+005C (\), U+005D (]), U+005E (^), or +// U+007C (|). +constexpr static std::array is_forbidden_host_code_point_table = + []() consteval { + std::array result{}; + for (uint8_t c : {'\0', '\x09', '\x0a', '\x0d', ' ', '#', '/', ':', '<', + '>', '?', '@', '[', '\\', ']', '^', '|'}) { + result[c] = true; + } + return result; + }(); + +ada_really_inline constexpr bool is_forbidden_host_code_point( + const char c) noexcept { + return is_forbidden_host_code_point_table[uint8_t(c)]; +} + +constexpr static std::array is_forbidden_domain_code_point_table = + []() consteval { + std::array result{}; + for (uint8_t c : {'\0', '\x09', '\x0a', '\x0d', ' ', '#', '/', ':', '<', + '>', '?', '@', '[', '\\', ']', '^', '|', '%'}) { + result[c] = true; + } + for (uint8_t c = 0; c <= 32; c++) { + result[c] = true; + } + for (size_t c = 127; c < 255; c++) { + result[c] = true; + } + return result; + }(); + +static_assert(sizeof(is_forbidden_domain_code_point_table) == 256); + +ada_really_inline constexpr bool is_forbidden_domain_code_point( + const char c) noexcept { + return is_forbidden_domain_code_point_table[uint8_t(c)]; +} + +ada_really_inline size_t percent_encode_index(const std::string_view input, + const uint8_t character_set[]) { + const char* data = input.data(); + const size_t size = input.size(); + + // Process 8 bytes at a time using unrolled loop + size_t i = 0; + for (; i + 8 <= size; i += 8) { + unsigned char chunk[8]; + std::memcpy(&chunk, data + i, + 8); // entices compiler to unconditionally process 8 characters + + // Check 8 characters at once + for (size_t j = 0; j < 8; j++) { + if (character_sets::bit_at(character_set, chunk[j])) { + return i + j; + } + } + } + + // Handle remaining bytes + for (; i < size; i++) { + if (character_sets::bit_at(character_set, data[i])) { + return i; + } + } + + return size; +} +} // namespace ada::unicode + +#endif // ADA_UNICODE_INL_H diff --git a/include/ada/unicode.h b/include/unicode.h similarity index 99% rename from include/ada/unicode.h rename to include/unicode.h index c380908b0..294733904 100644 --- a/include/ada/unicode.h +++ b/include/unicode.h @@ -5,11 +5,11 @@ #ifndef ADA_UNICODE_H #define ADA_UNICODE_H -#include "ada/common_defs.h" -#include "ada/ada_idna.h" - -#include #include +#include + +#include "ada_idna.h" +#include "common_defs.h" /** * Unicode operations. These functions are not part of our public API and may diff --git a/include/ada/url-inl.h b/include/url-inl.h similarity index 97% rename from include/ada/url-inl.h rename to include/url-inl.h index f2ff0160d..5a918901f 100644 --- a/include/ada/url-inl.h +++ b/include/url-inl.h @@ -5,12 +5,12 @@ #ifndef ADA_URL_INL_H #define ADA_URL_INL_H -#include "ada/checkers.h" -#include "ada/url.h" -#include "ada/url_components.h" - #include #include + +#include "checkers.h" +#include "url.h" +#include "url_components.h" #if ADA_REGULAR_VISUAL_STUDIO #include #endif // ADA_REGULAR_VISUAL_STUDIO @@ -251,6 +251,10 @@ ada_really_inline size_t url::parse_port(std::string_view view, return consumed; } +ada_really_inline size_t url::parse_port(std::string_view view) noexcept { + return parse_port(view, false); +} + } // namespace ada #endif // ADA_URL_H diff --git a/include/ada/url.h b/include/url.h similarity index 97% rename from include/ada/url.h rename to include/url.h index 09279f447..8136e3a15 100644 --- a/include/ada/url.h +++ b/include/url.h @@ -5,22 +5,16 @@ #ifndef ADA_URL_H #define ADA_URL_H -#include #include #include #include #include #include -#include "ada/checkers.h" -#include "ada/common_defs.h" -#include "ada/log.h" -#include "ada/scheme.h" -#include "ada/serializers.h" -#include "ada/unicode.h" -#include "ada/url_base.h" -#include "ada/url_components.h" -#include "ada/helpers.h" +#include "common_defs.h" +#include "helpers.h" +#include "url_base.h" +#include "url_components.h" namespace ada { @@ -357,9 +351,7 @@ struct url : url_base { ada_really_inline size_t parse_port( std::string_view view, bool check_trailing_content) noexcept override; - ada_really_inline size_t parse_port(std::string_view view) noexcept override { - return this->parse_port(view, false); - } + ada_really_inline size_t parse_port(std::string_view view) noexcept override; /** * Parse the host from the provided input. We assume that diff --git a/include/ada/url_aggregator-inl.h b/include/url_aggregator-inl.h similarity index 99% rename from include/ada/url_aggregator-inl.h rename to include/url_aggregator-inl.h index 2012b79d4..d8de19fd4 100644 --- a/include/ada/url_aggregator-inl.h +++ b/include/url_aggregator-inl.h @@ -5,19 +5,20 @@ #ifndef ADA_URL_AGGREGATOR_INL_H #define ADA_URL_AGGREGATOR_INL_H -#include "ada/character_sets.h" -#include "ada/character_sets-inl.h" -#include "ada/checkers.h" -#include "ada/helpers.h" -#include "ada/unicode-inl.h" -#include "ada/url_aggregator.h" -#include "ada/url_components.h" -#include "ada/scheme.h" -#include "ada/log.h" - +#include #include #include +#include "character_sets-inl.h" +#include "checkers-inl.h" +#include "helpers.h" +#include "log.h" +#include "scheme-inl.h" +#include "unicode-inl.h" +#include "url_aggregator.h" +#include "url_base-inl.h" +#include "url_components-inl.h" + namespace ada { inline void url_aggregator::update_base_authority( @@ -886,6 +887,11 @@ ada_really_inline size_t url_aggregator::parse_port( return consumed; } +ada_really_inline size_t +url_aggregator::parse_port(std::string_view view) noexcept { + return parse_port(view, false); +} + constexpr void url_aggregator::set_protocol_as_file() { ada_log("url_aggregator::set_protocol_as_file "); ADA_ASSERT_TRUE(validate()); diff --git a/include/ada/url_aggregator.h b/include/url_aggregator.h similarity index 98% rename from include/ada/url_aggregator.h rename to include/url_aggregator.h index 66f7991c3..30366fb69 100644 --- a/include/ada/url_aggregator.h +++ b/include/url_aggregator.h @@ -8,13 +8,18 @@ #include #include -#include "ada/url_pattern.h" -#include "ada/common_defs.h" -#include "ada/url_base.h" -#include "ada/url_components.h" -#include "ada/parser.h" +#include "common_defs.h" +#include "helpers.h" +#include "url_base.h" +#include "url_components.h" +#include "url_pattern.h" namespace ada { +/** + * @private + * Forward declaration of the URL class. + */ +struct url; /** * @brief Lightweight URL struct. @@ -247,9 +252,7 @@ struct url_aggregator : url_base { ada_really_inline size_t parse_port( std::string_view view, bool check_trailing_content) noexcept override; - ada_really_inline size_t parse_port(std::string_view view) noexcept override { - return this->parse_port(view, false); - } + ada_really_inline size_t parse_port(std::string_view view) noexcept override; /** * Return true on success. The 'in_place' parameter indicates whether the diff --git a/include/ada/url_base-inl.h b/include/url_base-inl.h similarity index 79% rename from include/ada/url_base-inl.h rename to include/url_base-inl.h index 948205eb2..3826c8c78 100644 --- a/include/ada/url_base-inl.h +++ b/include/url_base-inl.h @@ -5,16 +5,16 @@ #ifndef ADA_URL_BASE_INL_H #define ADA_URL_BASE_INL_H -#include "ada/url_aggregator.h" -#include "ada/url_components.h" -#include "ada/scheme.h" -#include "ada/scheme-inl.h" -#include "ada/log.h" -#include "ada/checkers.h" -#include "ada/url.h" - #include #include + +#include "checkers.h" +#include "log.h" +#include "scheme-inl.h" +#include "scheme.h" +#include "url.h" +#include "url_aggregator.h" +#include "url_components.h" #if ADA_REGULAR_VISUAL_STUDIO #include #endif // ADA_REGULAR_VISUAL_STUDIO diff --git a/include/ada/url_base.h b/include/url_base.h similarity index 97% rename from include/ada/url_base.h rename to include/url_base.h index 9d2461d7a..2195dbd92 100644 --- a/include/ada/url_base.h +++ b/include/url_base.h @@ -5,12 +5,11 @@ #ifndef ADA_URL_BASE_H #define ADA_URL_BASE_H -#include "ada/common_defs.h" -#include "ada/url_components.h" -#include "ada/scheme.h" - #include +#include "common_defs.h" +#include "scheme.h" + namespace ada { /** diff --git a/include/ada/url_components-inl.h b/include/url_components-inl.h similarity index 98% rename from include/ada/url_components-inl.h rename to include/url_components-inl.h index 77ab8874a..2b5a89386 100644 --- a/include/ada/url_components-inl.h +++ b/include/url_components-inl.h @@ -5,7 +5,7 @@ #ifndef ADA_URL_COMPONENTS_INL_H #define ADA_URL_COMPONENTS_INL_H -#include "ada/url_components.h" +#include "url_components.h" namespace ada { diff --git a/include/ada/url_components.h b/include/url_components.h similarity index 98% rename from include/ada/url_components.h rename to include/url_components.h index a72767bb0..a30dd1b78 100644 --- a/include/ada/url_components.h +++ b/include/url_components.h @@ -5,11 +5,11 @@ #ifndef ADA_URL_COMPONENTS_H #define ADA_URL_COMPONENTS_H -#include "ada/common_defs.h" - #include #include +#include "common_defs.h" + namespace ada { /** diff --git a/include/ada/url_pattern-inl.h b/include/url_pattern-inl.h similarity index 98% rename from include/ada/url_pattern-inl.h rename to include/url_pattern-inl.h index 2ad9e0af4..72bc18a5e 100644 --- a/include/ada/url_pattern-inl.h +++ b/include/url_pattern-inl.h @@ -5,11 +5,11 @@ #ifndef ADA_URL_PATTERN_INL_H #define ADA_URL_PATTERN_INL_H -#include "ada/common_defs.h" -#include "ada/url_pattern.h" - #include +#include "common_defs.h" +#include "url_pattern.h" + namespace ada { inline bool url_pattern_init::operator==(const url_pattern_init& other) const { diff --git a/include/ada/url_pattern.h b/include/url_pattern.h similarity index 96% rename from include/ada/url_pattern.h rename to include/url_pattern.h index 4c0b897be..4114b06ec 100644 --- a/include/ada/url_pattern.h +++ b/include/url_pattern.h @@ -5,16 +5,21 @@ #ifndef ADA_URL_PATTERN_H #define ADA_URL_PATTERN_H -#include "ada/implementation.h" -#include "ada/expected.h" - #include #include #include #include #include +#include "common_defs.h" +#include "expected.h" + +#ifdef ADA_TESTING +#include +#endif // ADA_TESTING + namespace ada { +enum class errors : uint8_t; namespace parser { template > exec(const url_pattern_input& input, - std::string_view* base_url); + tl::expected, errors> exec( + const url_pattern_input& input, std::string_view* base_url); /** * @see https://urlpattern.spec.whatwg.org/#dom-urlpattern-test */ - result test(const url_pattern_input& input, std::string_view* base_url); + tl::expected test(const url_pattern_input& input, + std::string_view* base_url); /** * @see https://urlpattern.spec.whatwg.org/#url-pattern-match * This function expects a valid UTF-8 string if input is a string. */ - result> match( + tl::expected, errors> match( const url_pattern_input& input, std::string_view* base_url_string); // @see https://urlpattern.spec.whatwg.org/#dom-urlpattern-protocol diff --git a/include/ada/url_pattern_helpers-inl.h b/include/url_pattern_helpers-inl.h similarity index 99% rename from include/ada/url_pattern_helpers-inl.h rename to include/url_pattern_helpers-inl.h index 37311bb2b..09f2ff325 100644 --- a/include/ada/url_pattern_helpers-inl.h +++ b/include/url_pattern_helpers-inl.h @@ -5,11 +5,12 @@ #ifndef ADA_URL_PATTERN_HELPERS_INL_H #define ADA_URL_PATTERN_HELPERS_INL_H -#include "ada/common_defs.h" -#include "ada/expected.h" -#include "ada/url_pattern.h" -#include "ada/url_pattern_helpers.h" -#include "ada/implementation.h" +#include "common_defs.h" +#include "expected.h" +#include "implementation.h" +#include "log.h" +#include "url_pattern.h" +#include "url_pattern_helpers.h" namespace ada::url_pattern_helpers { inline std::string to_string(token_type type) { diff --git a/include/ada/url_pattern_helpers.h b/include/url_pattern_helpers.h similarity index 99% rename from include/ada/url_pattern_helpers.h rename to include/url_pattern_helpers.h index 4d9c29f65..23ad75e6e 100644 --- a/include/ada/url_pattern_helpers.h +++ b/include/url_pattern_helpers.h @@ -5,13 +5,13 @@ #ifndef ADA_URL_PATTERN_HELPERS_H #define ADA_URL_PATTERN_HELPERS_H -#include "ada/expected.h" -#include "ada/url_pattern.h" - #include #include #include +#include "expected.h" +#include "url_pattern.h" + namespace ada::url_pattern_helpers { // @see https://urlpattern.spec.whatwg.org/#token diff --git a/include/ada/url_search_params-inl.h b/include/url_search_params-inl.h similarity index 98% rename from include/ada/url_search_params-inl.h rename to include/url_search_params-inl.h index a4f53c944..175a8af72 100644 --- a/include/ada/url_search_params-inl.h +++ b/include/url_search_params-inl.h @@ -5,11 +5,6 @@ #ifndef ADA_URL_SEARCH_PARAMS_INL_H #define ADA_URL_SEARCH_PARAMS_INL_H -#include "ada.h" -#include "ada/character_sets-inl.h" -#include "ada/unicode.h" -#include "ada/url_search_params.h" - #include #include #include @@ -17,6 +12,10 @@ #include #include +#include "character_sets-inl.h" +#include "unicode.h" +#include "url_search_params.h" + namespace ada { // A default, empty url_search_params for use with empty iterators. diff --git a/include/ada/url_search_params.h b/include/url_search_params.h similarity index 100% rename from include/ada/url_search_params.h rename to include/url_search_params.h diff --git a/singleheader/demo.c b/singleheader/demo.c index 3a2c29ea5..ea278abe1 100644 --- a/singleheader/demo.c +++ b/singleheader/demo.c @@ -1,9 +1,10 @@ -#include "ada_c.h" +#include #include #include -#include #include +#include "ada_c.h" + static void ada_print(ada_string string) { printf("%.*s\n", (int)string.length, string.data); } diff --git a/singleheader/demo.cpp b/singleheader/demo.cpp index c70fa75e8..70a9b763b 100644 --- a/singleheader/demo.cpp +++ b/singleheader/demo.cpp @@ -1,6 +1,7 @@ +#include + #include "ada.cpp" #include "ada.h" -#include int main(int, char *[]) { auto url = ada::parse("https://www.google.com"); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7c8f36e39..dec79dc80 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,13 +1,12 @@ - message(STATUS "Compiler ID : " ${CMAKE_CXX_COMPILER_ID}) message(STATUS "CMAKE_BUILD_TYPE : " ${CMAKE_BUILD_TYPE}) add_library(ada-include-source INTERFACE) target_include_directories(ada-include-source INTERFACE $) add_library(ada-source INTERFACE) -target_sources(ada-source INTERFACE $/ada.cpp) +file(GLOB_RECURSE ada_cpp_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) target_link_libraries(ada-source INTERFACE ada-include-source) -add_library(ada ada.cpp) +add_library(ada ${ada_cpp_files}) target_compile_features(ada PUBLIC cxx_std_20) target_include_directories(ada PRIVATE $ ) target_include_directories(ada PUBLIC "$") diff --git a/src/ada.cpp b/src/ada.cpp deleted file mode 100644 index 3d35569dd..000000000 --- a/src/ada.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "ada.h" -#include "checkers.cpp" -#include "unicode.cpp" -#include "serializers.cpp" -#include "implementation.cpp" -#include "helpers.cpp" -#include "url.cpp" -#include "parser.cpp" -#include "url_components.cpp" -#include "url_aggregator.cpp" -#include "url_pattern.cpp" -#include "url_pattern_helpers.cpp" -#include "ada_c.cpp" diff --git a/src/ada_c.cpp b/src/ada_c.cpp index ffde38ec6..0d1f76eb7 100644 --- a/src/ada_c.cpp +++ b/src/ada_c.cpp @@ -1,5 +1,7 @@ -#include "ada/url_aggregator-inl.h" -#include "ada/url_search_params-inl.h" +#include "ada_idna.h" +#include "implementation.h" +#include "url_aggregator-inl.h" +#include "url_search_params-inl.h" ada::result& get_instance(void* result) noexcept { return *(ada::result*)result; diff --git a/src/checkers.cpp b/src/checkers.cpp index d486f5544..54093647d 100644 --- a/src/checkers.cpp +++ b/src/checkers.cpp @@ -1,12 +1,15 @@ -#include "ada/checkers-inl.h" -#include "ada/checkers.h" -#include "ada/unicode-inl.h" -#include "ada/common_defs.h" +#include "checkers.h" #include #include #include +#include "checkers-inl.h" +#include "checkers.h" +#include "common_defs.h" +#include "unicode-inl.h" +#include "unicode.h" + namespace ada::checkers { ada_really_inline constexpr bool is_ipv4(std::string_view view) noexcept { diff --git a/src/helpers.cpp b/src/helpers.cpp index 0a4216cab..d86a8e874 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -1,10 +1,20 @@ -#include "ada/checkers-inl.h" -#include "ada/common_defs.h" -#include "ada/scheme.h" +#include "helpers.h" #include #include +#include "character_sets-inl.h" +#include "checkers-inl.h" +#include "common_defs.h" +#include "log.h" +#include "scheme-inl.h" +#include "state.h" +#include "unicode-inl.h" + +#if ADA_NEON +#include +#endif + namespace ada::helpers { template diff --git a/src/implementation.cpp b/src/implementation.cpp index cad5af5ff..05accacb2 100644 --- a/src/implementation.cpp +++ b/src/implementation.cpp @@ -1,10 +1,13 @@ +#include "implementation.h" + #include -#include "ada/common_defs.h" -#include "ada/parser.h" -#include "ada/url.h" -#include "ada/url_aggregator.h" -#include "ada/url_pattern.h" +#include "common_defs.h" +#include "unicode.h" +#include "url.h" +#include "url_aggregator.h" +#include "url_base.h" +#include "url_pattern.h" namespace ada { diff --git a/src/parser.cpp b/src/parser.cpp index 09c6ad283..36590fc93 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -1,11 +1,17 @@ -#include "ada/parser.h" +#include "parser.h" #include -#include "ada/character_sets-inl.h" -#include "ada/common_defs.h" -#include "ada/log.h" -#include "ada/unicode.h" +#include "character_sets-inl.h" +#include "checkers-inl.h" +#include "common_defs.h" +#include "helpers.h" +#include "implementation.h" +#include "log.h" +#include "state.h" +#include "unicode-inl.h" +#include "url_aggregator-inl.h" +#include "url_pattern_helpers-inl.h" namespace ada::parser { diff --git a/src/serializers.cpp b/src/serializers.cpp index 3b4f967a6..73fc8d2d8 100644 --- a/src/serializers.cpp +++ b/src/serializers.cpp @@ -1,3 +1,5 @@ +#include "serializers.h" + #include #include #include diff --git a/src/unicode.cpp b/src/unicode.cpp index 00ae20e5a..fb7875117 100644 --- a/src/unicode.cpp +++ b/src/unicode.cpp @@ -1,14 +1,12 @@ -#include "ada/common_defs.h" -#include "ada/character_sets-inl.h" -#include "ada/character_sets.h" -#include "ada/unicode.h" -#include "ada/log.h" - -ADA_PUSH_DISABLE_ALL_WARNINGS -#include "ada_idna.cpp" -ADA_POP_DISABLE_WARNINGS +#include "unicode.h" #include + +#include "ada_idna.h" +#include "character_sets-inl.h" +#include "common_defs.h" +#include "log.h" +#include "unicode-inl.h" #if ADA_NEON #include #elif ADA_SSE2 @@ -152,48 +150,6 @@ ada_really_inline bool has_tabs_or_newline( } #endif -// A forbidden host code point is U+0000 NULL, U+0009 TAB, U+000A LF, U+000D CR, -// U+0020 SPACE, U+0023 (#), U+002F (/), U+003A (:), U+003C (<), U+003E (>), -// U+003F (?), U+0040 (@), U+005B ([), U+005C (\), U+005D (]), U+005E (^), or -// U+007C (|). -constexpr static std::array is_forbidden_host_code_point_table = - []() consteval { - std::array result{}; - for (uint8_t c : {'\0', '\x09', '\x0a', '\x0d', ' ', '#', '/', ':', '<', - '>', '?', '@', '[', '\\', ']', '^', '|'}) { - result[c] = true; - } - return result; - }(); - -ada_really_inline constexpr bool is_forbidden_host_code_point( - const char c) noexcept { - return is_forbidden_host_code_point_table[uint8_t(c)]; -} - -constexpr static std::array is_forbidden_domain_code_point_table = - []() consteval { - std::array result{}; - for (uint8_t c : {'\0', '\x09', '\x0a', '\x0d', ' ', '#', '/', ':', '<', - '>', '?', '@', '[', '\\', ']', '^', '|', '%'}) { - result[c] = true; - } - for (uint8_t c = 0; c <= 32; c++) { - result[c] = true; - } - for (size_t c = 127; c < 255; c++) { - result[c] = true; - } - return result; - }(); - -static_assert(sizeof(is_forbidden_domain_code_point_table) == 256); - -ada_really_inline constexpr bool is_forbidden_domain_code_point( - const char c) noexcept { - return is_forbidden_domain_code_point_table[uint8_t(c)]; -} - ada_really_inline constexpr bool contains_forbidden_domain_code_point( const char* input, size_t length) noexcept { size_t i = 0; diff --git a/src/url.cpp b/src/url.cpp index f35625bed..301e6ac40 100644 --- a/src/url.cpp +++ b/src/url.cpp @@ -1,12 +1,20 @@ -#include "ada/scheme-inl.h" -#include "ada/log.h" -#include "ada/unicode-inl.h" +#include "url.h" -#include #include +#include #include #include +#include "character_sets-inl.h" +#include "checkers.h" +#include "helpers.h" +#include "implementation.h" +#include "log.h" +#include "scheme-inl.h" +#include "serializers.h" +#include "unicode-inl.h" +#include "url-inl.h" + namespace ada { bool url::parse_opaque_host(std::string_view input) { diff --git a/src/url_aggregator.cpp b/src/url_aggregator.cpp index 08211436d..70140037d 100644 --- a/src/url_aggregator.cpp +++ b/src/url_aggregator.cpp @@ -1,16 +1,19 @@ -#include "ada/checkers-inl.h" -#include "ada/helpers.h" -#include "ada/implementation.h" -#include "ada/scheme.h" -#include "ada/unicode-inl.h" -#include "ada/url_components.h" -#include "ada/url_components-inl.h" -#include "ada/url_aggregator.h" -#include "ada/url_aggregator-inl.h" +#include "url_aggregator.h" #include #include +#include "character_sets-inl.h" +#include "checkers-inl.h" +#include "helpers.h" +#include "implementation.h" +#include "log.h" +#include "scheme-inl.h" +#include "serializers.h" +#include "unicode-inl.h" +#include "url_aggregator-inl.h" +#include "url_components-inl.h" + namespace ada { template [[nodiscard]] ada_really_inline bool url_aggregator::parse_scheme_with_colon( diff --git a/src/url_components.cpp b/src/url_components.cpp index da981c09c..bee37b777 100644 --- a/src/url_components.cpp +++ b/src/url_components.cpp @@ -1,9 +1,10 @@ -#include "ada/helpers.h" -#include "ada/url_components.h" +#include "url_components.h" #include #include +#include "helpers.h" + namespace ada { [[nodiscard]] std::string url_components::to_string() const { diff --git a/src/url_pattern.cpp b/src/url_pattern.cpp index 95ec41ded..1bbf242bd 100644 --- a/src/url_pattern.cpp +++ b/src/url_pattern.cpp @@ -1,11 +1,17 @@ -#include "ada/url_pattern-inl.h" +#include "url_pattern.h" #include #include #include #include +#include "helpers.h" +#include "implementation.h" +#include "url_aggregator-inl.h" +#include "url_pattern_helpers.h" + namespace ada { + // The default options is an options struct with delimiter code point set to // the empty string and prefix code point set to the empty string. url_pattern_compile_component_options diff --git a/src/url_pattern_helpers.cpp b/src/url_pattern_helpers.cpp index 56927635b..2871364be 100644 --- a/src/url_pattern_helpers.cpp +++ b/src/url_pattern_helpers.cpp @@ -1,9 +1,16 @@ -#include "ada/url_pattern_helpers.h" - #include #include +#include #include +#include "ada_idna.h" +#include "common_defs.h" +#include "log.h" +#include "parser.h" +#include "unicode.h" +#include "url_aggregator-inl.h" +#include "url_pattern_helpers-inl.h" + namespace ada::url_pattern_helpers { std::tuple> diff --git a/tests/basic_fuzzer.cpp b/tests/basic_fuzzer.cpp index 69c1a7d94..25e9bf04f 100644 --- a/tests/basic_fuzzer.cpp +++ b/tests/basic_fuzzer.cpp @@ -1,7 +1,8 @@ -#include "ada.h" +#include #include #include -#include + +#include "implementation.h" std::string url_examples[] = { "https://www.google.com/" diff --git a/tests/basic_tests.cpp b/tests/basic_tests.cpp index d1d452a42..be793fc2b 100644 --- a/tests/basic_tests.cpp +++ b/tests/basic_tests.cpp @@ -1,8 +1,9 @@ -#include "ada.h" -#include "gtest/gtest.h" #include #include +#include "gtest/gtest.h" +#include "implementation.h" + using Types = testing::Types; template struct basic_tests : testing::Test {}; @@ -462,4 +463,4 @@ TYPED_TEST(basic_tests, negativeport) { auto url = ada::parse("https://www.google.com"); ASSERT_FALSE(url->set_port("-1")); SUCCEED(); -} \ No newline at end of file +} diff --git a/tests/from_file_tests.cpp b/tests/from_file_tests.cpp index 1f10fa850..ec6dd39d9 100644 --- a/tests/from_file_tests.cpp +++ b/tests/from_file_tests.cpp @@ -1,6 +1,7 @@ -#include "ada.h" #include #include + +#include "ada.h" #include "gtest/gtest.h" std::string long_way(std::string path) { diff --git a/tests/url_components.cpp b/tests/url_components.cpp index 4dfe00069..42fcc2ae1 100644 --- a/tests/url_components.cpp +++ b/tests/url_components.cpp @@ -1,13 +1,14 @@ +#include "url_components.h" + #include #include #include #include #include -#include "simdjson.h" #include "gtest/gtest.h" -#include "ada.h" -#include "ada/url_components.h" +#include "implementation.h" +#include "simdjson.h" using namespace simdjson; diff --git a/tests/wasm/wasm.cpp b/tests/wasm/wasm.cpp index 3df8e5ab1..acdf60bd1 100644 --- a/tests/wasm/wasm.cpp +++ b/tests/wasm/wasm.cpp @@ -1,6 +1,7 @@ -#include "ada.h" -#include #include +#include + +#include "ada.h" using namespace emscripten; diff --git a/tests/wpt_url_tests.cpp b/tests/wpt_url_tests.cpp index 7d916780d..2a96d1e45 100644 --- a/tests/wpt_url_tests.cpp +++ b/tests/wpt_url_tests.cpp @@ -6,12 +6,12 @@ #include #include -#include "gtest/gtest.h" #include "ada.h" #include "ada/character_sets-inl.h" #include "ada/parser.h" #include "ada/url.h" #include "ada/url_aggregator.h" +#include "gtest/gtest.h" // This function copies your input onto a memory buffer that // has just the necessary size. This will entice tools to detect diff --git a/tests/wpt_urlpattern_tests.cpp b/tests/wpt_urlpattern_tests.cpp index 6b9263a85..e1c22035c 100644 --- a/tests/wpt_urlpattern_tests.cpp +++ b/tests/wpt_urlpattern_tests.cpp @@ -1,13 +1,13 @@ #include #include -#include "ada/log.h" #include "gtest/gtest.h" +#include "implementation.h" +#include "log.h" +#include "parser.h" #include "simdjson.h" - -#include "ada.h" -#include "ada/url_pattern.h" -#include "ada/parser.h" +#include "url_pattern.h" +#include "url_pattern_helpers-inl.h" using namespace simdjson; diff --git a/tools/cli/adaparse.cpp b/tools/cli/adaparse.cpp index b91b61cd8..e721d3de5 100644 --- a/tools/cli/adaparse.cpp +++ b/tools/cli/adaparse.cpp @@ -1,7 +1,8 @@ +#include + #include #include #include -#include #include "ada.h" #include "line_iterator.h"