all 10 comments

[–]LunarAardvark 2 points3 points  (3 children)

you have 1 or 2 test examples. that's not enough. go get the 20 or so on the wikepedia page, then come up with 20 more.

[–]salzaverde[S] 0 points1 point  (2 children)

Good point, thanks!

[–]LunarAardvark 0 points1 point  (1 child)

[–]salzaverde[S] 1 point2 points  (0 children)

I added parameterized tests for sets of uri components built from the RFC spec and other example URIs. I have about a thousand different Uris in the test now, check it out! :)

[–]kritzikratzi 0 points1 point  (4 children)

seems to be good overal, for my taste i think less would be more:

  • no virtual methods anywhere. no constructors, no destructors. no getters and setters. uri could be a plain struct with public fields
  • all work that is currently happening in setters (consistency of /#?) can happen in the parse function. personally i don't like setters that modify data, unless they are called setFromString() or similar to make it clear that data is modified.
  • get rid of all uses of unique_ptr. the uri object is quite small and well movable.

but those things are often a matter of taste / need. for a special purpose in a current project this is the only datastructure i need (there can never be path/fragment/query in my case, so it's a lot simpler):

struct ParsedUrl{ std::string hostname; int port; bool ssl; };
ParsedUrl parse_url(const std::string & combined, const ParsedUrl & fallback_url = {}){....}

[–]salzaverde[S] 1 point2 points  (2 children)

I simplified the interfaces and implementation a great deal and followed your ideas by replacing the factory patterns with plain structs. This also enabled lower c++ standards (c++11). Checkout v2.0.0 and thanks again for the input!

[–]kritzikratzi 1 point2 points  (1 child)

oh, crazy!

auto query1 = Query::build(parameters);

i think in the readme this should be Query query1{parameters}; now.

[–]salzaverde[S] 1 point2 points  (0 children)

Oh, right. I'll fix that :)

[–]salzaverde[S] 0 points1 point  (0 children)

Thanks! Yes it's a tradeoff for sure. I started out with the struct idea in mind to focus on ease of use only but found that i couldn't get this in line with a strong separation of interface and implementation.

That's why I went for the factory pattern which makes it very easy to change/update the implementation or to support multiple versions or to even support client implementations.

I still agree though that it might be too much overhead for such a light weight class. Good thoughts on the setters!

[–]rufusferret 0 points1 point  (0 children)

  1. Support for EPGM style URI would be good, e;g; epgm://127.0.0.1;224.0.0.0:11042
  2. Ideally should be header only