Skip to content

Commit db2791c

Browse files
authored
Update docs (#120)
* Updated documentation * Updated example in README.md
1 parent a51e1cd commit db2791c

File tree

9 files changed

+113
-99
lines changed

9 files changed

+113
-99
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ cmake_minimum_required(VERSION 3.14)
88

99
project(
1010
skyr-url
11-
VERSION 1.10.0
11+
VERSION 1.11.0
1212
HOMEPAGE_URL https://cpp-netlib.github.io/url
1313
DESCRIPTION "A C++ library that implements the WhatWG URL specification"
1414
LANGUAGES CXX

README.md

Lines changed: 67 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
[![AppVeyor](https://ci.appveyor.com/api/projects/status/1iblsi5apka29dmg?svg=true)](
1212
https://ci.appveyor.com/project/glynos/url-3aeqd)
1313

14-
1514
## Introduction
1615

1716
This library provides:
@@ -62,7 +61,7 @@ Using `vcpkg`, install the library dependencies:
6261
> ./vcpkg install tl-expected catch2 nlohmann-json fmt
6362
```
6463

65-
### Building with `CMake` and `Ninja`
64+
### Building the project with `CMake` and `Ninja`
6665

6766
From a terminal, execute the following sequence of commands:
6867

@@ -82,101 +81,112 @@ To run the tests:
8281
> cmake --build _build --target test
8382
```
8483

85-
On Windows, replace the target with ``RUN_TESTS``.
84+
On Windows, replace the target with ``RUN_TESTS``:
85+
86+
```powershell
87+
> cmake --build _build --target RUN_TESTS
88+
```
8689

8790
To install the library:
8891

8992
```bash
9093
> cmake --build _build --target install
9194
```
9295

93-
## Examples
96+
## Testing and installing the project
9497

95-
These examples are based on the
96-
[WhatWG API specification](https://url.spec.whatwg.org/#example-5434421b)
97-
98-
To build the examples with the sources, run `cmake` as follows:
98+
### Installing with `CMake` and `Ninja`
9999

100100
```bash
101101
> cmake .. \
102102
-G "Ninja" \
103-
-DSkyr_BUILD_EXAMPLES=ON \
104-
-DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/vcpkg/scripts/buildsystems/vcpkg.cmake
103+
-DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/vcpkg/scripts/buildsystems/vcpkg.cmake \
104+
-DCMAKE_INSTALL_PREFIX=$PREFIX
105+
> ninja
106+
> ninja test
107+
> ninja install
105108
```
106109

107-
### Creating a URL without a base URL
110+
Where `$PREFIX` is the location where you want to install the
111+
library. Depending on the location of `$PREFIX`, you may need to run
112+
the install command as an administrator (e.g. on Linux as `sudo`).
113+
114+
115+
## Example usage
116+
117+
### Source code
108118

109-
[This example](examples/example_01.md) parses a string,
110-
"https://example.org/💩", without using a base URL:
119+
Here is an example of how to use the ``skyr::url`` class to parse a
120+
URL string and to process the components:
111121

112122
```c++
123+
// url_parts.cpp
124+
113125
#include <skyr/url.hpp>
126+
#include <skyr/percent_encoding/percent_decode.hpp>
114127
#include <iostream>
115128

116-
int main(int argc, char *argv[]) {
117-
auto url = skyr::url("http://example.org/\xf0\x9f\x92\xa9");
118-
std::cout << url.pathname() << std::endl;
119-
}
120-
```
129+
int main() {
130+
using namespace skyr::literals;
121131

122-
Gives the output: `/%F0%9F%92%A9`
132+
auto url =
133+
"http://sub.example.إختبار:8090/\xcf\x80?a=1&c=2&b=\xe2\x80\x8d\xf0\x9f\x8c\x88"_url;
123134

124-
### Creating a non-absolute URL without a base URL
135+
std::cout << "Protocol: " << url.protocol() << std::endl;
125136

126-
[This example](examples/example_02.md) gives an error if
127-
the input, "/🍣🍺", is not an *absolute-URL-with-fragment-string*:
137+
std::cout << "Domain? " << std::boolalpha << url.is_domain() << std::endl;
138+
std::cout << "Domain: " << url.hostname() << std::endl;
139+
std::cout << "Domain: "
140+
<< skyr::domain_to_unicode(url.hostname()).value() << std::endl;
128141

129-
```c++
130-
#include <skyr/url.hpp>
131-
#include <iostream>
142+
std::cout << "Port: " << url.port<std::uint16_t>().value() << std::endl;
143+
144+
std::cout << "Pathname: "
145+
<< skyr::percent_decode<std::string>(url.pathname()).value() << std::endl;
132146

133-
int main(int argc, char *argv[]) {
134-
auto url = skyr::make_url("\xf0\x9f\x8d\xa3\xf0\x9f\x8d\xba");
135-
if (!url) {
136-
std::cerr << "Parsing failed: " << url.error().message() << std::endl;
147+
std::cout << "Search parameters:" << std::endl;
148+
const auto &search = url.search_parameters();
149+
for (const auto &[key, value] : search) {
150+
std::cout << " " << "key: " << key << ", value = " << value << std::endl;
137151
}
138152
}
139153
```
140154

141-
This gives the output: `Parsing failed: Not an absolute URL with fragment`
155+
### Build script
142156

143-
### Creating a non-absolute URL with a base URL
157+
Here is the ``CMake`` script to build the example:
144158

145-
[This example](examples/example_03.md) parses a string,
146-
"🏳️‍🌈", using a base URL, "https://example.org/":
159+
```cmake
160+
# CMakeLists.txt
147161
148-
```c++
149-
#include <skyr/url.hpp>
150-
#include <iostream>
162+
project(my_project)
151163
152-
int main(int argc, char *argv[]) {
153-
auto base = skyr::url("https://example.org/");
154-
auto url = skyr::url(
155-
"\xf0\x9f\x8f\xb3\xef\xb8\x8f\xe2\x80\x8d\xf0\x9f\x8c\x88", base);
156-
std::cout << url.href() << std::endl;
157-
}
158-
```
164+
find_package(tl-expected CONFIG REQUIRED)
165+
find_package(skyr-url CONFIG REQUIRED)
159166
160-
This gives the output: `https://example.org/%F0%9F%8F%B3%EF%B8%8F%E2%80%8D%F0%9F%8C%88`
167+
set(CMAKE_CXX_STANDARD 17)
161168
162-
## Testing and installation
169+
add_executable(url_parts url_parts.cpp)
170+
target_link_libraries(url_test PRIVATE skyr::skyr-url)
171+
```
163172

164-
### Installing with `CMake` and `Ninja`
173+
### Output
174+
175+
The output of this program is:
165176

166177
```bash
167-
> cmake .. \
168-
-G "Ninja" \
169-
-DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/vcpkg/scripts/buildsystems/vcpkg.cmake \
170-
-DCMAKE_INSTALL_PREFIX=$PREFIX
171-
> ninja
172-
> ninja test
173-
> ninja install
178+
Protocol: http:
179+
Domain? true
180+
Domain: sub.example.xn--kgbechtv
181+
Domain: sub.example.إختبار
182+
Port: 8090
183+
Pathname: /π
184+
Search parameters:
185+
key: a, value = 1
186+
key: c, value = 2
187+
key: b, value = ‍🌈
174188
```
175189

176-
Where `$PREFIX` is the location where you want to install the
177-
library. Depending on the location of `$PREFIX`, you may need to run
178-
the install command as an administrator (e.g. on Linux as `sudo`).
179-
180190
## Dependencies
181191

182192
This library uses [expected](https://github.com/TartanLlama/expected).

docs/Doxyfile.in

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -829,13 +829,13 @@ WARN_LOGFILE =
829829
# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
830830
# Note: If this tag is empty the current directory is searched.
831831

832-
INPUT = @PROJECT_SOURCE_DIR@/include/skyr/ \
833-
@PROJECT_SOURCE_DIR@/include/skyr/core/ \
834-
@PROJECT_SOURCE_DIR@/include/skyr/domain/ \
835-
@PROJECT_SOURCE_DIR@/include/skyr/network/ \
836-
@PROJECT_SOURCE_DIR@/include/skyr/percent_encoding/ \
837-
@PROJECT_SOURCE_DIR@/include/skyr/filesystem/ \
838-
@PROJECT_SOURCE_DIR@/include/skyr/json/
832+
INPUT = @PROJECT_SOURCE_DIR@/include/skyr/v1/ \
833+
@PROJECT_SOURCE_DIR@/include/skyr/v1/core/ \
834+
@PROJECT_SOURCE_DIR@/include/skyr/v1/domain/ \
835+
@PROJECT_SOURCE_DIR@/include/skyr/v1/network/ \
836+
@PROJECT_SOURCE_DIR@/include/skyr/v1/percent_encoding/ \
837+
@PROJECT_SOURCE_DIR@/include/skyr/v1/filesystem/ \
838+
@PROJECT_SOURCE_DIR@/include/skyr/v1/json/
839839

840840
# This tag can be used to specify the character encoding of the source files
841841
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses

docs/conf.py.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ project = 'Skyr URL'
2626
copyright = '2018-20, Glyn Matthews'
2727
author = 'Glyn Matthews'
2828

29-
major, minor, patch, sha1 = @skyr-url_VERSION_MAJOR@, @skyr-url_VERSION_MINOR@, @skyr-url_VERSION_PATCH@, @skyr-url_VERSION_SHA1@
29+
major, minor, patch = @skyr-url_VERSION_MAJOR@, @skyr-url_VERSION_MINOR@, @skyr-url_VERSION_PATCH@
3030

3131

3232
# The short X.Y version
3333
version = '{}.{}'.format(major, minor)
3434
# The full version, including alpha/beta/rc tags
35-
release = '{}.{}.{}-{}}'.format(major, minor, patch, sha1)
35+
release = '{}.{}.{}'.format(major, minor, patch)
3636

3737

3838
# -- General configuration ---------------------------------------------------

docs/core.rst

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ Core
44
Description
55
-----------
66

7-
The core of the `skyr` library is a `skyr::url_record` that
8-
contains a URL parts, a `skyr::parse` function that parses an
9-
input string and creates a `skyr::url_record` and a
10-
`skyr::serialize` function that composes a URL string from an
11-
existing `skyr::url_record`.
7+
The core of the ``skyr`` library is a ``skyr::parse`` function
8+
that parses an input string and creates a ``skyr::url_record``
9+
that contains a URL parts, and a ``skyr::serialize`` function
10+
that composes a URL string from an existing ``skyr::url_record``.
1211

1312
Use these functions directly if your needs are simple. Use the
14-
`skyr::url` class for more complex operations, including
13+
``skyr::url`` class for more complex operations, including
1514
Unicode encoding and decoding.
1615

1716
Headers
@@ -38,7 +37,7 @@ Example
3837
auto url = skyr::url_parse("http://example.org/");
3938
std::cout << url << std::endl;
4039
std::cout << "Scheme: " << url.scheme << std::endl;
41-
std::cout << "Hostname: " == url.host.value());
40+
std::cout << "Hostname: " << url.host.value().to_string());
4241
std::cout << "Pathname: ";
4342
for (const auto &path : url.path) {
4443
<< std::cout << "/" << path;
@@ -51,17 +50,29 @@ Example
5150
API
5251
---
5352

54-
`skyr::url_record` class
55-
^^^^^^^^^^^^^^^^^^^^^^^^
53+
``skyr::host`` class
54+
^^^^^^^^^^^^^^^^^^^^
55+
56+
.. doxygenclass:: skyr::v1::host
57+
:members:
58+
59+
``skyr::url_record`` class
60+
^^^^^^^^^^^^^^^^^^^^^^^^^^
5661

5762
.. doxygenclass:: skyr::v1::url_record
5863
:members:
5964

60-
`skyr::url_record` functions
61-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
65+
``skyr::url_record`` functions
66+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6267

6368
.. doxygenfunction:: skyr::swap(url_record&, url_record&)
6469

65-
.. doxygenfunction:: skyr::parse
70+
.. doxygenfunction:: skyr::parse(std::string_view)
71+
72+
.. doxygenfunction:: skyr::parse(std::string_view, bool *)
73+
74+
.. doxygenfunction:: skyr::parse(std::string_view, const url_record&)
75+
76+
.. doxygenfunction:: skyr::parse(std::string_view, const url_record&, bool *)
6677

6778
.. doxygenfunction:: skyr::serialize

docs/domain.rst

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,6 @@ Example
4040
API
4141
---
4242

43-
Punycode
44-
^^^^^^^^
45-
46-
.. doxygenfunction:: skyr::punycode_encode(std::string_view)
47-
48-
.. doxygenfunction:: skyr::punycode_decode(std::string_view)
49-
5043
Domain to ASCII
5144
^^^^^^^^^^^^^^^
5245

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ and standard library.
5858
std::cout << "Protocol: " << url.protocol() << std::endl;
5959

6060
std::cout << "Domain? " << std::boolalpha << url.is_domain() << std::endl;
61-
std::cout << "Domain: " << url.domain().value() << std::endl;
61+
std::cout << "Domain: " << url.hostname() << std::endl;
6262

6363
std::cout << "Pathname: " <<
6464
skyr::percent_decode<std::string>(url.pathname()).value() << std::endl;

docs/network.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Example
2828

2929
auto url = "http://[1080:0:0:0:8:800:200C:417A]:8090/"_url;
3030
assert(url.is_ipv6_address());
31-
std::cout << "IPv6 Host: " << url.ipv6_address().to_string() << std::endl;
31+
std::cout << "IPv6 Host: " << urlhostname() << std::endl;
3232
}
3333

3434
API

docs/url.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ URL
44
Description
55
-----------
66

7-
The `skyr::url` class parses a URL in the constructor and provides
7+
The ``skyr::url`` class parses a URL in the constructor and provides
88
a rich interface to access and process the URL components. The
9-
`skyr::url` constructor throws a `skyr::url_parse_error` on failure.
9+
``skyr::url`` constructor throws a ``skyr::url_parse_error`` on failure.
1010

1111
Headers
1212
-------
@@ -41,31 +41,31 @@ Example
4141
API
4242
---
4343

44-
`skyr::url` class
45-
^^^^^^^^^^^^^^^^^
44+
``skyr::url`` class
45+
^^^^^^^^^^^^^^^^^^^
4646

4747
.. doxygenclass:: skyr::v1::url
4848
:members:
4949

50-
`skyr::url` functions
51-
^^^^^^^^^^^^^^^^^^^^^
50+
``skyr::url`` functions
51+
^^^^^^^^^^^^^^^^^^^^^^^
5252

5353
.. doxygenfunction:: skyr::swap(url&, url&)
5454

5555
.. doxygenfunction:: skyr::make_url(const Source&)
5656

5757
.. doxygenfunction:: skyr::make_url(const Source&, const url&)
5858

59-
`skyr::url` error codes
60-
^^^^^^^^^^^^^^^^^^^^^^^
59+
``skyr::url`` error codes
60+
^^^^^^^^^^^^^^^^^^^^^^^^^
6161

62-
.. doxygenenum:: skyr::url_parse_errc
62+
.. doxygenenum:: skyr::v1::url_parse_errc
6363

6464
.. doxygenclass:: skyr::v1::url_parse_error
6565
:members:
6666

67-
`skyr::url_search_parameters` class
68-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
67+
``skyr::url_search_parameters`` class
68+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6969

7070
.. doxygenclass:: skyr::v1::url_search_parameters
7171
:members:

0 commit comments

Comments
 (0)