Skip to content

Commit

Permalink
create url_pattern-inl.h
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Nov 30, 2024
1 parent 02492e1 commit 0ccd6d3
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 20 deletions.
1 change: 1 addition & 0 deletions include/ada.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "ada/url_search_params.h"
#include "ada/url_search_params-inl.h"
#include "ada/url_pattern.h"
#include "ada/url_pattern-inl.h"

// Public API
#include "ada/ada_version.h"
Expand Down
64 changes: 64 additions & 0 deletions include/ada/url_pattern-inl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* @file url_pattern-inl.h
* @brief Declaration for the URLPattern inline functions.
*/
#ifndef ADA_URL_PATTERN_INL_H
#define ADA_URL_PATTERN_INL_H

#include "common_defs.h"
#include "url_pattern.h"

#include <string_view>

namespace ada {
inline std::string_view URLPattern::Component::get_pattern() const noexcept
ada_lifetime_bound {
return pattern;
}

inline std::string_view URLPattern::Component::get_regex() const noexcept
ada_lifetime_bound {
return regex;
}

inline const std::vector<std::string>& URLPattern::Component::get_names()
const noexcept ada_lifetime_bound {
return names;
}

inline const URLPattern::Component& URLPattern::get_protocol() const
ada_lifetime_bound {
return protocol;
}
inline const URLPattern::Component& URLPattern::get_username() const
ada_lifetime_bound {
return username;
}
inline const URLPattern::Component& URLPattern::get_password() const
ada_lifetime_bound {
return password;
}
inline const URLPattern::Component& URLPattern::get_port() const
ada_lifetime_bound {
return port;
}
inline const URLPattern::Component& URLPattern::get_pathname() const
ada_lifetime_bound {
return pathname;
}
inline const URLPattern::Component& URLPattern::get_search() const
ada_lifetime_bound {
return search;
}
inline const URLPattern::Component& URLPattern::get_hash() const
ada_lifetime_bound {
return hash;
}

inline bool URLPattern::case_ignored() const ada_lifetime_bound {
return ignore_case;
}

} // namespace ada

#endif
31 changes: 11 additions & 20 deletions include/ada/url_pattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,10 @@ class URLPattern {
explicit Component(std::string_view pattern, std::string_view regex,
const std::vector<std::string>& names);

// TODO(anonrig): Move these implementations to `url_pattern-inl.h`
std::string_view get_pattern() const noexcept ada_lifetime_bound {
return pattern;
}
std::string_view get_regex() const noexcept ada_lifetime_bound {
return regex;
}
std::string_view get_pattern() const noexcept ada_lifetime_bound;
std::string_view get_regex() const noexcept ada_lifetime_bound;
const std::vector<std::string>& get_names() const noexcept
ada_lifetime_bound {
return names;
}
ada_lifetime_bound;

private:
// Disallow copy.
Expand Down Expand Up @@ -106,19 +99,17 @@ class URLPattern {
bool test(std::optional<Input> input,
std::optional<std::string_view> base_url);

// TODO(anonrig): Move these to `url_pattern-inl.h`.
const Component& get_protocol() const ada_lifetime_bound { return protocol; }
const Component& get_username() const ada_lifetime_bound { return username; }
const Component& get_password() const ada_lifetime_bound { return password; }
const Component& get_port() const ada_lifetime_bound { return port; }
const Component& get_pathname() const ada_lifetime_bound { return pathname; }
const Component& get_search() const ada_lifetime_bound { return search; }
const Component& get_hash() const ada_lifetime_bound { return hash; }
const Component& get_protocol() const ada_lifetime_bound;
const Component& get_username() const ada_lifetime_bound;
const Component& get_password() const ada_lifetime_bound;
const Component& get_port() const ada_lifetime_bound;
const Component& get_pathname() const ada_lifetime_bound;
const Component& get_search() const ada_lifetime_bound;
const Component& get_hash() const ada_lifetime_bound;

// If ignoreCase is true, the JavaScript regular expression created for each
// pattern must use the `vi` flag. Otherwise, they must use the `v` flag.
// TODO(anonrig): Move these to `url_pattern-inl.h`.
bool case_ignored() const ada_lifetime_bound { return ignore_case; }
bool case_ignored() const ada_lifetime_bound;

private:
Component protocol;
Expand Down

0 comments on commit 0ccd6d3

Please sign in to comment.