ada-url / ada

WHATWG-compliant and fast URL parser written in modern C++

Home Page:https://ada-url.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Search parameters reset functionality

bungle opened this issue · comments

What is the problem this feature will solve?

The Ada URL has this C API:

bool ada_set_href(ada_url result, const char* input, size_t length);

This allows you to create a singleton of ada_url and then reuse that singleton with different URLs and perhaps eases the bindings writing if you want to create both static API (for quick single operations, like adding or removing parameter and getting a string back) and one where you create an instance (when you need more thorough processing or reading).

But there is no similar function for ada_url_search_params. I am not sure if there is a reason for that, and if there is, you are welcomed to close this feature request.

What is the feature you are proposing to solve the problem?

Introduce a new function:

void ada_search_params_reset(ada_url_search_params result, const char* input, size_t length);

The naming here is just an example, feel free to pick a better name.

And similar perhaps on C++ side, if there is not already support for something like that?

What alternatives have you considered?

Alternative is to always call the ada_parse_search_params, but this I think may result unnecessary memory allocations and processing in some case. Especially when writing efficient language bindings to Ada.

Congratulations for good library that is well designed and easily integrated with other ecosystems.

P.S. I am currently finishing my LuaJIT FFI bindings to this library.

Hi @bungle,

Thank you for the kind words. ada_set_href resolves into href setter in the URL spec. Unfortunately, URLSearchParams does not provide a similar API. We can definitely add it if it helps, but that would diverge us from the spec.

If you think the benefit of having a similar function is worth it, still, after my comments, I'm more than happy to open a PR and add it.

I went ahead and implemented it #701

The proposed API is available starting from v2.9.0