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

feat: adds urlpattern to ada #381

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e466165
urlpattern: adds id_start and id_pard lookup table
miguelteixeiraa May 8, 2023
4aa5f55
urlpattern: adds id_start & id_part + tokenizer sketch
miguelteixeiraa May 9, 2023
842f5b1
urlpattern: adds missing eof
miguelteixeiraa May 9, 2023
dadb665
merge branch 'main' into urlpattern
miguelteixeiraa May 9, 2023
ee41c6f
urlpattern: adds bitset lib
miguelteixeiraa May 9, 2023
df58be4
urlpattern: adds comments to unicode.h
miguelteixeiraa May 10, 2023
582a649
urlpattern: component_result -> urlpattern_component_result
miguelteixeiraa May 10, 2023
0516de4
urlpattern: wip constructors
miguelteixeiraa May 11, 2023
179a065
urlpattern: WIP contructor_string_parser
miguelteixeiraa May 13, 2023
2e80ab3
urlpattern: introducing canonicalize_protocol
miguelteixeiraa May 14, 2023
17ee73d
urlpatter: adds pragma regions
miguelteixeiraa May 14, 2023
9ae30c4
urlpattern: breakdown in multiple files
miguelteixeiraa May 15, 2023
95e5c70
urlpattern: minor fixes
miguelteixeiraa May 15, 2023
b9041fb
urlpattern: fixup to make it compile
miguelteixeiraa May 15, 2023
50d6d09
Merge branch 'main' into urlpattern
miguelteixeiraa May 15, 2023
5651a1f
urlpattern: adds missing cassert lib + fixes
miguelteixeiraa May 15, 2023
ca49555
urlpattern: fix assert for token type
miguelteixeiraa May 15, 2023
58342b3
urlpattern: introducing tests for tokenizer
miguelteixeiraa May 20, 2023
3f5fac8
urlpattern: update id_start and id_part tables
miguelteixeiraa Jun 7, 2023
824725d
urlpattern: WIP fix tokenizer
miguelteixeiraa Jun 7, 2023
88453a5
urlpattern: update tokenizer
miguelteixeiraa Jun 7, 2023
6e14684
urlpattern: updates tokenizer's test
miguelteixeiraa Jun 7, 2023
81fa16d
urlpattern: make tokenizer pass the tests
miguelteixeiraa Jun 8, 2023
5016786
urlpattern: WIP compile a component
miguelteixeiraa Jun 9, 2023
8c8942a
urlpattern: WIP pattern parser
miguelteixeiraa Jun 10, 2023
aa8522f
Merge branch 'main' into urlpattern
miguelteixeiraa Jun 10, 2023
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
1 change: 1 addition & 0 deletions include/ada.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "ada/url_components.h"
#include "ada/url_aggregator.h"
#include "ada/url_aggregator-inl.h"
#include "ada/urlpattern.h"

// Public API
#include "ada/ada_version.h"
Expand Down
4 changes: 4 additions & 0 deletions include/ada/unicode.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ ada_really_inline size_t percent_encode_index(const std::string_view input,
* Return true if the content was ASCII.
*/
constexpr bool to_lower_ascii(char* input, size_t length) noexcept;

bool is_valid_identifier_part(const char32_t& c) noexcept;
anonrig marked this conversation as resolved.
Show resolved Hide resolved
bool is_valid_identifier_start(const char32_t& c) noexcept;

} // namespace ada::unicode

#endif // ADA_UNICODE_H
82 changes: 82 additions & 0 deletions include/ada/urlpattern.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#ifndef ADA_URL_PATTERN_H
#define ADA_URL_PATTERN_H

#include "ada/common_defs.h"

#include <unordered_map>
#include <array>
#include <string_view>
#include <optional>

namespace ada {

ada_really_inline bool is_valid_name_code_point(const char32_t& c,
bool is_first) noexcept;

struct urlpattern_options {
bool ignore_case = false;
};

struct component_result {
Copy link
Member

Choose a reason for hiding this comment

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

ada::component_result seems a really vague naming, since it might be mistaken with ada::url_components

std::string_view input;
std::unordered_map<std::string_view, std::optional<std::string_view>> groups;
Copy link
Member

Choose a reason for hiding this comment

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

@lemire How's the performance comparison of using std::optional in here versus std::variant<std::nullopt, std::string_view>?

Copy link
Member

Choose a reason for hiding this comment

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

I don't expect it matters much.

};

struct urlpattern_init {
std::string_view protocol;
std::string_view username;
std::string_view password;
std::string_view hostname;
std::string_view port;
std::string_view pathname;
std::string_view search;
std::string_view hash;
std::string_view base_url;
};

union input_union {
urlpattern_options urlpattern_init;
std::string_view str;
};

typedef input_union urlpattern_input;

struct urlpattern_result {
component_result protocol;
component_result username;
component_result password;
component_result hostname;
component_result port;
component_result pathname;
component_result search;
component_result hash;
urlpattern_input input[];
};

struct urlpattern {
urlpattern(urlpattern_input input, std::string_view base_url,
std::optional<urlpattern_options> options);
anonrig marked this conversation as resolved.
Show resolved Hide resolved

urlpattern(std::optional<urlpattern_input> input,
anonrig marked this conversation as resolved.
Show resolved Hide resolved
std::optional<urlpattern_options>);

bool test(std::optional<urlpattern_input> input,
std::optional<std::string_view> base_url);

std::optional<urlpattern_result> exec(
std::optional<urlpattern_input> input,
std::optional<std::string_view> base_url);

const std::string_view protocol;
const std::string_view username;
const std::string_view password;
const std::string_view hostname;
const std::string_view port;
const std::string_view pathname;
const std::string_view search;
const std::string_view hash;
};

} // namespace ada

#endif
1 change: 1 addition & 0 deletions src/ada.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
#include "parser.cpp"
#include "url_components.cpp"
#include "url_aggregator.cpp"
#include "urlpattern.cpp"
#include "ada_c.cpp"
Loading