Parses an SSH "scp-like" address - user@host:path (what scp, rsync, sshfs, and git all accept, e.g. "git@github.com:user/repo.git") - by normalizing it to a standard ssh://user@host/path URI and handing that to url. Not URI syntax per RFC 3986 (that colon is a path separator, not a port), so plain url() either misparses it or throws.
More...
#include <urlparser.h>
|
| | scp_url (std::string_view input) |
| | Parse input - scp-like or already a normal URI - as a URL. scp-like input is normalize()d to "ssh://" first; anything else is parsed as-is (so this also accepts "https://...", "ssh://...", etc. unchanged).
|
| |
| const url & | as_url () const noexcept |
| | The parsed result, as a normal url.
|
| |
| | operator const url & () const noexcept |
| | Implicit conversion, so an scp_url can be passed anywhere a const url& is expected.
|
| |
| bool | was_scp_like () const noexcept |
| | Whether input (as given to the constructor) was scp-like, as opposed to already a normal URI.
|
| |
|
| static bool | is_scp_like (std::string_view input) noexcept |
| | True iff input matches the scp-like address shape: [user@]host:path. Per git's own rule for this syntax (see git help clone, "GIT URLS"): recognized only when there's no "://" and no '/' before the first ':' - e.g. "host:22/repo" is scp-like too (path "22/repo"), since there's no slash before that colon; only an actual "scheme://" prevents the match.
|
| |
| static std::string | normalize (std::string_view input) |
| | Rewrite an scp-like address to an equivalent "ssh://" URI. Input that doesn't match is_scp_like() is returned unchanged.
|
| |
Parses an SSH "scp-like" address - user@host:path (what scp, rsync, sshfs, and git all accept, e.g. "git@github.com:user/repo.git") - by normalizing it to a standard ssh://user@host/path URI and handing that to url. Not URI syntax per RFC 3986 (that colon is a path separator, not a port), so plain url() either misparses it or throws.
Composition (holds a url), not inheritance: url has no virtual destructor and isn't marked final, so publicly deriving from it is the same "delete through a base pointer -> UB" footgun the host class's own doc comment above already calls out for a different class - and since url's data members are private (not protected), inheriting wouldn't even grant any access beyond what url's own public API (used here via composition) already gives.
◆ scp_url()
| urlparser::scp_url::scp_url |
( |
std::string_view |
input | ) |
|
|
explicit |
Parse input - scp-like or already a normal URI - as a URL. scp-like input is normalize()d to "ssh://" first; anything else is parsed as-is (so this also accepts "https://...", "ssh://...", etc. unchanged).
- Exceptions
-
| std::invalid_argument | If the (possibly normalized) result isn't a parseable URL. |
◆ as_url()
| const url & urlparser::scp_url::as_url |
( |
| ) |
const |
|
inlinenoexcept |
The parsed result, as a normal url.
◆ is_scp_like()
| static bool urlparser::scp_url::is_scp_like |
( |
std::string_view |
input | ) |
|
|
staticnoexcept |
True iff input matches the scp-like address shape: [user@]host:path. Per git's own rule for this syntax (see git help clone, "GIT URLS"): recognized only when there's no "://" and no '/' before the first ':' - e.g. "host:22/repo" is scp-like too (path "22/repo"), since there's no slash before that colon; only an actual "scheme://" prevents the match.
◆ normalize()
| static std::string urlparser::scp_url::normalize |
( |
std::string_view |
input | ) |
|
|
static |
Rewrite an scp-like address to an equivalent "ssh://" URI. Input that doesn't match is_scp_like() is returned unchanged.
◆ operator const url &()
| urlparser::scp_url::operator const url & |
( |
| ) |
const |
|
inlinenoexcept |
Implicit conversion, so an scp_url can be passed anywhere a const url& is expected.
◆ was_scp_like()
| bool urlparser::scp_url::was_scp_like |
( |
| ) |
const |
|
inlinenoexcept |
Whether input (as given to the constructor) was scp-like, as opposed to already a normal URI.
The documentation for this class was generated from the following file:
- /home/runner/work/liburlparser/liburlparser/include/urlparser.h