Skip to content

Commit 51cbfd5

Browse files
committed
refactor: move more ada::url functions to private
1 parent b9bd174 commit 51cbfd5

File tree

2 files changed

+148
-230
lines changed

2 files changed

+148
-230
lines changed

include/ada/url.h

Lines changed: 69 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -91,51 +91,12 @@ struct url : url_base {
9191
*/
9292
std::optional<std::string> hash{};
9393

94-
/** @private */
95-
inline void clear_pathname() override;
96-
/** @private */
97-
inline void clear_search() override;
98-
/** @private */
99-
inline bool has_hash() const override;
100-
/** @private */
101-
inline bool has_search() const override;
102-
/** @private set this URL's type to file */
103-
inline void set_protocol_as_file();
10494
/** @return true if it has an host but it is the empty string */
10595
[[nodiscard]] inline bool has_empty_hostname() const noexcept;
10696
/** @return true if it has a host (included an empty host) */
10797
[[nodiscard]] inline bool has_hostname() const noexcept;
10898
[[nodiscard]] bool has_valid_domain() const noexcept override;
10999

110-
/**
111-
* @private
112-
*
113-
* Parse the path from the provided input.
114-
* Return true on success. Control characters not
115-
* trimmed from the ends (they should have
116-
* been removed if needed).
117-
*
118-
* The input is expected to be UTF-8.
119-
*
120-
* @see https://url.spec.whatwg.org/
121-
*/
122-
ada_really_inline void parse_path(const std::string_view input);
123-
124-
/**
125-
* Set the scheme for this URL. The provided scheme should be a valid
126-
* scheme string, be lower-cased, not contain spaces or tabs. It should
127-
* have no spurious trailing or leading content.
128-
*/
129-
inline void set_scheme(std::string &&new_scheme) noexcept;
130-
131-
/**
132-
* @private
133-
*
134-
* Take the scheme from another URL. The scheme string is moved from the
135-
* provided url.
136-
*/
137-
inline void copy_scheme(ada::url &&u) noexcept;
138-
139100
/**
140101
* Returns a JSON string representation of this URL.
141102
*/
@@ -269,16 +230,6 @@ struct url : url_base {
269230
*/
270231
bool set_href(const std::string_view input);
271232

272-
/**
273-
* @private
274-
*
275-
* Sets the host or hostname according to override condition.
276-
* Return true on success.
277-
* @see https://url.spec.whatwg.org/#hostname-state
278-
*/
279-
template <bool override_hostname = false>
280-
bool set_host_or_hostname(std::string_view input);
281-
282233
/**
283234
* The password getter steps are to return this’s URL’s password.
284235
* @return a constant reference to the underlying string.
@@ -306,44 +257,6 @@ struct url : url_base {
306257
*/
307258
[[nodiscard]] ada_really_inline bool has_credentials() const noexcept;
308259

309-
/**
310-
* @private
311-
*
312-
* A URL cannot have a username/password/port if its host is null or the empty
313-
* string, or its scheme is "file".
314-
*/
315-
[[nodiscard]] inline bool cannot_have_credentials_or_port() const;
316-
317-
/** @private */
318-
ada_really_inline size_t
319-
parse_port(std::string_view view,
320-
bool check_trailing_content = false) noexcept override;
321-
322-
/**
323-
* @private
324-
*
325-
* Take the scheme from another URL. The scheme string is copied from the
326-
* provided url.
327-
*/
328-
inline void copy_scheme(const ada::url &u);
329-
330-
/**
331-
* @private
332-
*
333-
* Parse the host from the provided input. We assume that
334-
* the input does not contain spaces or tabs. Control
335-
* characters and spaces are not trimmed (they should have
336-
* been removed if needed).
337-
* Return true on success.
338-
* @see https://url.spec.whatwg.org/#host-parsing
339-
*/
340-
[[nodiscard]] ada_really_inline bool parse_host(std::string_view input);
341-
342-
/** @private */
343-
template <bool has_state_override = false>
344-
[[nodiscard]] ada_really_inline bool parse_scheme(
345-
const std::string_view input);
346-
347260
/**
348261
* Useful for implementing efficient serialization for the URL.
349262
*
@@ -376,53 +289,44 @@ struct url : url_base {
376289
friend void ada::helpers::strip_trailing_spaces_from_opaque_path<ada::url>(
377290
ada::url &url) noexcept;
378291

379-
/** @private */
380292
inline void update_unencoded_base_hash(std::string_view input);
381-
/** @private */
382293
inline void update_base_hostname(std::string_view input);
383-
/** @private */
384294
inline void update_base_search(std::string_view input);
385-
/** @private */
386295
inline void update_base_search(std::string_view input,
387296
const uint8_t query_percent_encode_set[]);
388-
/** @private */
389297
inline void update_base_search(std::optional<std::string> input);
390-
/** @private */
391298
inline void update_base_pathname(const std::string_view input);
392-
/** @private */
393299
inline void update_base_username(const std::string_view input);
394-
/** @private */
395300
inline void update_base_password(const std::string_view input);
396-
/** @private */
397301
inline void update_base_port(std::optional<uint16_t> input);
398302

399303
/**
400-
* @private
401-
*
304+
* Sets the host or hostname according to override condition.
305+
* Return true on success.
306+
* @see https://url.spec.whatwg.org/#hostname-state
307+
*/
308+
template <bool override_hostname = false>
309+
bool set_host_or_hostname(std::string_view input);
310+
311+
/**
402312
* Return true on success.
403313
* @see https://url.spec.whatwg.org/#concept-ipv4-parser
404314
*/
405315
[[nodiscard]] bool parse_ipv4(std::string_view input);
406316

407317
/**
408-
* @private
409-
*
410318
* Return true on success.
411319
* @see https://url.spec.whatwg.org/#concept-ipv6-parser
412320
*/
413321
[[nodiscard]] bool parse_ipv6(std::string_view input);
414322

415323
/**
416-
* @private
417-
*
418324
* Return true on success.
419325
* @see https://url.spec.whatwg.org/#concept-opaque-host-parser
420326
*/
421327
[[nodiscard]] bool parse_opaque_host(std::string_view input);
422328

423329
/**
424-
* @private
425-
*
426330
* A URL’s scheme is an ASCII string that identifies the type of URL and can
427331
* be used to dispatch a URL for further processing after parsing. It is
428332
* initially the empty string. We only set non_special_scheme when the scheme
@@ -433,6 +337,67 @@ struct url : url_base {
433337
*/
434338
std::string non_special_scheme{};
435339

340+
/**
341+
* A URL cannot have a username/password/port if its host is null or the empty
342+
* string, or its scheme is "file".
343+
*/
344+
[[nodiscard]] inline bool cannot_have_credentials_or_port() const;
345+
346+
ada_really_inline size_t
347+
parse_port(std::string_view view,
348+
bool check_trailing_content = false) noexcept override;
349+
350+
/**
351+
* Take the scheme from another URL. The scheme string is copied from the
352+
* provided url.
353+
*/
354+
inline void copy_scheme(const ada::url &u);
355+
356+
/**
357+
* Parse the host from the provided input. We assume that
358+
* the input does not contain spaces or tabs. Control
359+
* characters and spaces are not trimmed (they should have
360+
* been removed if needed).
361+
* Return true on success.
362+
* @see https://url.spec.whatwg.org/#host-parsing
363+
*/
364+
[[nodiscard]] ada_really_inline bool parse_host(std::string_view input);
365+
366+
template <bool has_state_override = false>
367+
[[nodiscard]] ada_really_inline bool parse_scheme(
368+
const std::string_view input);
369+
370+
inline void clear_pathname() override;
371+
inline void clear_search() override;
372+
inline bool has_hash() const override;
373+
inline bool has_search() const override;
374+
inline void set_protocol_as_file();
375+
376+
/**
377+
* Parse the path from the provided input.
378+
* Return true on success. Control characters not
379+
* trimmed from the ends (they should have
380+
* been removed if needed).
381+
*
382+
* The input is expected to be UTF-8.
383+
*
384+
* @see https://url.spec.whatwg.org/
385+
*/
386+
ada_really_inline void parse_path(const std::string_view input);
387+
388+
/**
389+
* Set the scheme for this URL. The provided scheme should be a valid
390+
* scheme string, be lower-cased, not contain spaces or tabs. It should
391+
* have no spurious trailing or leading content.
392+
*/
393+
inline void set_scheme(std::string &&new_scheme) noexcept;
394+
395+
/**
396+
* Take the scheme from another URL. The scheme string is moved from the
397+
* provided url.
398+
*/
399+
inline void copy_scheme(ada::url &&u) noexcept;
400+
436401
}; // struct url
437402

438403
inline std::ostream &operator<<(std::ostream &out, const ada::url &u);

0 commit comments

Comments
 (0)