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: add ada_copy c function #482

Merged
merged 1 commit into from
Aug 26, 2023
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
1 change: 1 addition & 0 deletions include/ada_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ bool ada_can_parse_with_base(const char* input, size_t input_length,

void ada_free(ada_url result);
void ada_free_owned_string(ada_owned_string owned);
ada_url ada_copy(ada_url input);

bool ada_is_valid(ada_url result);

Expand Down
5 changes: 5 additions & 0 deletions src/ada_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ void ada_free(ada_url result) noexcept {
delete r;
}

ada_url ada_copy(ada_url input) noexcept {
ada::result<ada::url_aggregator>& r = get_instance(input);
return new ada::result<ada::url_aggregator>(r);
}

bool ada_is_valid(ada_url result) noexcept {
ada::result<ada::url_aggregator>& r = get_instance(result);
return r.has_value();
Expand Down
17 changes: 17 additions & 0 deletions tests/ada_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,23 @@ TEST(ada_c, ada_url_components) {
SUCCEED();
}

TEST(ada_c, ada_copy) {
std::string lemire_blog = "https://lemire.me";
std::string anonrig_blog = "https://yagiz.co";
ada_url first = ada_parse(lemire_blog.data(), lemire_blog.length());
ada_url second = ada_copy(first);

ASSERT_TRUE(ada_set_href(second, anonrig_blog.data(), anonrig_blog.size()));

ASSERT_EQ(convert_string(ada_get_href(first)), "https://lemire.me/");
ASSERT_EQ(convert_string(ada_get_href(second)), "https://yagiz.co/");

ada_free(first);
ada_free(second);

SUCCEED();
}

TEST(ada_c, ada_idna) {
std::string_view ascii_input = "straße.de";
std::string_view unicode_input = "xn--strae-oqa.de";
Expand Down
Loading