Skip to content

Commit 168e7ed

Browse files
committed
Updated some examples and documentation
1 parent e8444be commit 168e7ed

File tree

7 files changed

+28
-41
lines changed

7 files changed

+28
-41
lines changed

README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ without using a base URL:
9595
#include <iostream>
9696

9797
int main(int argc, char *argv[]) {
98-
auto url = skyr::make_url("http://example.org/\xf0\x9f\x92\xa9");
99-
std::cout << url.value().pathname() << std::endl;
98+
auto url = skyr::url("http://example.org/\xf0\x9f\x92\xa9");
99+
std::cout << url.pathname() << std::endl;
100100
}
101101
```
102102
@@ -131,12 +131,10 @@ This example parses a string, "🏳️‍🌈", using a base URL,
131131
#include <iostream>
132132

133133
int main(int argc, char *argv[]) {
134-
auto base = skyr::make_url("https://example.org/");
135-
auto url = skyr::make_url(
136-
"\xf0\x9f\x8f\xb3\xef\xb8\x8f\xe2\x80\x8d\xf0\x9f\x8c\x88", base.value());
137-
if (url) {
138-
std::cout << url.value().href() << std::endl;
139-
}
134+
auto base = skyr::url("https://example.org/");
135+
auto url = skyr::url(
136+
"\xf0\x9f\x8f\xb3\xef\xb8\x8f\xe2\x80\x8d\xf0\x9f\x8c\x88", base);
137+
std::cout << url.href() << std::endl;
140138
}
141139
```
142140

examples/example_01.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <skyr/url.hpp>
88

99
int main(int argc, char *argv[]) {
10-
auto url = skyr::make_url("http://example.org/\xf0\x9f\x92\xa9");
11-
std::cout << url.value() << std::endl;
12-
std::cout << url.value().pathname() << std::endl;
10+
auto url = skyr::url("http://example.org/\xf0\x9f\x92\xa9");
11+
std::cout << url << std::endl;
12+
std::cout << url.pathname() << std::endl;
1313
}

examples/example_03.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
#include <skyr/url.hpp>
88

99
int main(int argc, char *argv[]) {
10-
auto base = skyr::make_url("https://example.org/");
11-
auto url = skyr::make_url(
12-
"\xf0\x9f\x8f\xb3\xef\xb8\x8f\xe2\x80\x8d\xf0\x9f\x8c\x88", base.value());
13-
if (url) {
14-
std::cout << url.value() << std::endl;
15-
}
10+
auto base = skyr::url("https://example.org/");
11+
auto url = skyr::url(
12+
"\xf0\x9f\x8f\xb3\xef\xb8\x8f\xe2\x80\x8d\xf0\x9f\x8c\x88", base);
13+
std::cout << url << std::endl;
1614
}

examples/example_07.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
int main(int argc, char *argv[]) {
1111
using namespace skyr::percent_encoding;
1212

13-
auto url = skyr::url("https://example.org/\xf0\x9f\x8f\xb3\xef\xb8\x8f\xe2\x80\x8d\xf0\x9f\x8c\x88");
13+
auto url = skyr::url(
14+
"https://example.org/\xf0\x9f\x8f\xb3\xef\xb8\x8f\xe2\x80\x8d\xf0\x9f\x8c\x88");
1415
std::cout << as<std::string>(url | view::decode).value() << std::endl;
1516
}

examples/example_09.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
int main(int argc, char *argv[]) {
1010
auto url = skyr::url("https://example.org/");
11-
url.search_parameters().append("q", "\xf0\x9f\x8f\xb3\xef\xb8\x8f\xe2\x80\x8d\xf0\x9f\x8c\x88");
11+
url.search_parameters().append(
12+
"q", "\xf0\x9f\x8f\xb3\xef\xb8\x8f\xe2\x80\x8d\xf0\x9f\x8c\x88");
1213
std::cout << url << std::endl;
1314
}

include/skyr/url.hpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ class url_parse_error : public std::runtime_error {
5454
///
5555
/// For example:
5656
/// ```
57-
/// auto url = skyr::make_url("http://example.org/");
58-
/// assert("http:" == url.value().scheme());
59-
/// assert("example.org" == url.value().hostname());
60-
/// assert("/" == url.value().pathname());
57+
/// auto url = skyr::url("http://example.org/");
58+
/// assert("http:" == url.scheme());
59+
/// assert("example.org" == url.hostname());
60+
/// assert("/" == url.pathname());
6161
/// ```
6262
class url {
6363

@@ -83,7 +83,7 @@ class url {
8383
/// Constructs an empty `url` object
8484
///
8585
/// \post `empty() == true`
86-
url();
86+
url() : url_(), href_(), view_(href_), parameters_(this) {}
8787

8888
/// Parses a URL from the input string. The input string can be
8989
/// any unicode encoded string (UTF-8, UTF-16 or UTF-32).
@@ -131,19 +131,19 @@ class url {
131131
/// Constructs a URL from an existing record
132132
///
133133
/// \param input A URL record
134-
explicit url(url_record &&input);
134+
explicit url(url_record &&input)
135+
: url() {
136+
update_record(std::forward<url_record>(input));
137+
}
135138

136139
///
137140
/// \param other
138141
url(const url &other)
139-
: url() {
140-
auto other_url = other.url_;
141-
update_record(std::move(other_url));
142-
}
142+
: url(url_record(other.url_)) {}
143143

144144
///
145145
/// \param other
146-
url(url &&other)
146+
url(url &&other) noexcept
147147
: url(std::move(other.url_)) {}
148148

149149
/// Swaps this `url` object with another

src/url/url.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,6 @@
1313
#include "url_schemes.hpp"
1414

1515
namespace skyr {
16-
url::url()
17-
: url_()
18-
, href_()
19-
, view_(href_)
20-
, parameters_(this) {}
21-
22-
url::url(url_record &&input)
23-
: url() {
24-
update_record(std::forward<url_record>(input));
25-
}
26-
2716
void url::swap(url &other) noexcept {
2817
using std::swap;
2918
swap(url_, other.url_);

0 commit comments

Comments
 (0)