Skip to content
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

Reduction of issue with PR implement URLPattern #785 #823

Closed
wants to merge 7 commits into from
Closed
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: 2 additions & 0 deletions include/ada.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include "ada/url_aggregator-inl.h"
#include "ada/url_search_params.h"
#include "ada/url_search_params-inl.h"
#include "ada/url_pattern_helpers.h"
#include "ada/url_pattern_helpers-inl.h"

// Public API
#include "ada/ada_version.h"
Expand Down
24 changes: 23 additions & 1 deletion include/ada/ada_idna.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* auto-generated on 2024-12-05 20:44:13 -0500. Do not edit! */
/* auto-generated on 2025-01-03 11:50:18 -0500. Do not edit! */
/* begin file include/idna.h */
#ifndef ADA_IDNA_H
#define ADA_IDNA_H
Expand Down Expand Up @@ -141,6 +141,28 @@ std::string to_unicode(std::string_view input);

#endif // ADA_IDNA_TO_UNICODE_H
/* end file include/ada/idna/to_unicode.h */
/* begin file include/ada/idna/identifier.h */
#ifndef ADA_IDNA_IDENTIFIER_H
#define ADA_IDNA_IDENTIFIER_H

#include <string>
#include <string_view>

namespace ada::idna {

// Verify if it is valid name code point given a Unicode code point and a
// boolean first: If first is true return the result of checking if code point
// is contained in the IdentifierStart set of code points. Otherwise return the
// result of checking if code point is contained in the IdentifierPart set of
// code points. Returns false if the input is empty or the code point is not
// valid. There is minimal Unicode error handling: the input should be valid
// UTF-8. https://urlpattern.spec.whatwg.org/#is-a-valid-name-code-point
bool valid_name_code_point(char32_t code_point, bool first);

} // namespace ada::idna

#endif
/* end file include/ada/idna/identifier.h */

#endif
/* end file include/idna.h */
2 changes: 1 addition & 1 deletion include/ada/implementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "ada/url_aggregator.h"

namespace ada {
enum class errors { generic_error };
enum class errors { generic_error, type_error };

template <class result_type = ada::url_aggregator>
using result = tl::expected<result_type, ada::errors>;
Expand Down
7 changes: 7 additions & 0 deletions include/ada/unicode.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ ada_really_inline constexpr bool is_forbidden_domain_code_point(
*/
ada_really_inline constexpr bool is_alnum_plus(char c) noexcept;

/**
* @private
* @details If a char is between U+0000 and U+007F inclusive, then it's an ASCII
* character.
*/
ada_really_inline constexpr bool is_ascii(char32_t c) noexcept;

/**
* @private
* @details An ASCII hex digit is an ASCII upper hex digit or ASCII lower hex
Expand Down
2 changes: 1 addition & 1 deletion include/ada/url_aggregator-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ inline void url_aggregator::append_base_username(const std::string_view input) {
}

constexpr void url_aggregator::clear_password() {
ada_log("url_aggregator::clear_password ", to_string(), "\n", to_diagram());
ada_log("url_aggregator::clear_password ", to_string(), "\n");
ADA_ASSERT_TRUE(validate());
if (!has_password()) {
return;
Expand Down
9 changes: 9 additions & 0 deletions include/ada/url_pattern_helpers-inl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* @file url_pattern_helpers-inl.h
* @brief Declaration for the URLPattern helpers.
*/
#ifndef ADA_URL_PATTERN_HELPERS_INL_H
#define ADA_URL_PATTERN_HELPERS_INL_H

namespace ada::url_pattern_helpers {} // namespace ada::url_pattern_helpers
#endif
13 changes: 13 additions & 0 deletions include/ada/url_pattern_helpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* @file url_pattern_helpers.h
* @brief Declaration for the URLPattern helpers.
*/
#ifndef ADA_URL_PATTERN_HELPERS_H
#define ADA_URL_PATTERN_HELPERS_H

#include <vector>

namespace ada::url_pattern_helpers {
std::vector<int> tokenize();
} // namespace ada::url_pattern_helpers
#endif
4 changes: 0 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ endif()
if(ADA_DEVELOPMENT_CHECKS)
target_compile_definitions(ada PUBLIC ADA_DEVELOPMENT_CHECKS=1)
endif()
if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND (CMAKE_BUILD_TYPE STREQUAL "Debug"))
message(STATUS "Enabling _GLIBCXX_DEBUG")
target_compile_definitions(ada PRIVATE _GLIBCXX_DEBUG=1)
endif()

if(ADA_SANITIZE)
target_compile_options(ada PUBLIC -fsanitize=address -fno-omit-frame-pointer -fno-sanitize-recover=all)
Expand Down
1 change: 1 addition & 0 deletions src/ada.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
#include "parser.cpp"
#include "url_components.cpp"
#include "url_aggregator.cpp"
#include "url_pattern_helpers.cpp"
#include "ada_c.cpp"
640 changes: 639 additions & 1 deletion src/ada_idna.cpp

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/unicode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@ ada_really_inline constexpr bool is_ascii_hex_digit(const char c) noexcept {
(c >= 'a' && c <= 'f');
}

ada_really_inline constexpr bool is_ascii(const char32_t c) noexcept {
// If code point is between U+0000 and U+007F inclusive, then return true.
return c <= 0x7F;
}

ada_really_inline constexpr bool is_c0_control_or_space(const char c) noexcept {
return (unsigned char)c <= ' ';
}
Expand Down
10 changes: 10 additions & 0 deletions src/url_pattern_helpers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "ada/url_pattern_helpers.h"

namespace ada::url_pattern_helpers {

std::vector<int> tokenize() {
std::vector<int> token_list;
return token_list;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if you return std::move(token_list) here? @jasnell's recommendation

}

} // namespace ada::url_pattern_helpers
5 changes: 5 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,25 @@ if(MSVC AND BUILD_SHARED_LIBS)
else()
include(GoogleTest)
add_executable(wpt_tests wpt_tests.cpp)
add_executable(wpt_urlpattern_tests wpt_urlpattern_tests.cpp)
add_executable(simple_wpt_urlpattern_tests simple_wpt_urlpattern_tests.cpp)

add_executable(url_components url_components.cpp)
add_executable(basic_tests basic_tests.cpp)
add_executable(from_file_tests from_file_tests.cpp)
add_executable(ada_c ada_c.cpp)
add_executable(url_search_params url_search_params.cpp)

target_link_libraries(wpt_tests PRIVATE simdjson GTest::gtest_main)
target_link_libraries(wpt_urlpattern_tests PRIVATE GTest::gtest_main)
target_link_libraries(url_components PRIVATE simdjson GTest::gtest_main)
target_link_libraries(basic_tests PRIVATE simdjson GTest::gtest_main)
target_link_libraries(from_file_tests PRIVATE simdjson GTest::gtest_main)
target_link_libraries(ada_c PRIVATE simdjson GTest::gtest_main)
target_link_libraries(url_search_params PRIVATE simdjson GTest::gtest_main)

gtest_discover_tests(wpt_tests PROPERTIES TEST_DISCOVERY_TIMEOUT 600)
gtest_discover_tests(wpt_urlpattern_tests PROPERTIES TEST_DISCOVERY_TIMEOUT 600)
gtest_discover_tests(url_components PROPERTIES TEST_DISCOVERY_TIMEOUT 600)
gtest_discover_tests(basic_tests PROPERTIES TEST_DISCOVERY_TIMEOUT 600)
gtest_discover_tests(from_file_tests PROPERTIES TEST_DISCOVERY_TIMEOUT 600)
Expand Down
13 changes: 13 additions & 0 deletions tests/simple_wpt_urlpattern_tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <cstdlib>

#include "ada.h"

bool test() {
auto tokenize_result = ada::url_pattern_helpers::tokenize();
return tokenize_result.empty();
}

int main() {
test();
return EXIT_SUCCESS;
}
7 changes: 7 additions & 0 deletions tests/wpt_urlpattern_tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "gtest/gtest.h"

#include "ada.h"

TEST(wpt_urlpattern_tests, parser_tokenize_basic_tests) {
auto tokenize_result = ada::url_pattern_helpers::tokenize();
}
Loading