Skip to content

Commit

Permalink
feat: add ada_copy c function
Browse files Browse the repository at this point in the history
Co-authored-by: Steve Klabnik <[email protected]>
  • Loading branch information
anonrig and steveklabnik committed Aug 26, 2023
1 parent 38a92c1 commit 012d80c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
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

0 comments on commit 012d80c

Please sign in to comment.