Skip to content

Commit 4b045b0

Browse files
authored
Merge pull request #5 from glynos/filesystem_path
Filesystem path
2 parents 5471730 + 055285f commit 4b045b0

10 files changed

+193
-25
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.idea
22
.vs
3+
CMakeSettings.json
34
cmake-build-*
45
_build

.travis.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,21 @@ matrix:
3434
apt:
3535
sources: ['ubuntu-toolchain-r-test']
3636
packages: ['g++-7']
37-
env: COMPILER='g++-7'
37+
env: [COMPILER='g++-7', BUILD_FILESYSTEM_PATH_FUNCTION='OFF']
3838

3939
- os: linux
4040
compiler: gcc
4141
addons: &gcc8
4242
apt:
4343
sources: ['ubuntu-toolchain-r-test']
4444
packages: ['g++-8']
45-
env: COMPILER='g++-8'
45+
env: [COMPILER='g++-8', BUILD_FILESYSTEM_PATH_FUNCTION='ON']
4646

4747
# 3/ OSX Clang Builds
4848
- os: osx
4949
osx_image: xcode10
5050
compiler: clang
51+
env: [BUILD_FILESYSTEM_PATH_FUNCTION='OFF']
5152

5253
install:
5354
- DEPS_DIR="${TRAVIS_BUILD_DIR}/deps_"
@@ -68,7 +69,7 @@ before_script:
6869
script:
6970
- mkdir _build
7071
- cd _build
71-
- cmake -DSkyr_BUILD_TESTS=ON -DSkyr_BUILD_DOCS=OFF -DSkyr_BUILD_EXAMPLES=OFF ..
72+
- cmake -DSkyr_BUILD_TESTS=ON -DSkyr_BUILD_DOCS=OFF -DSkyr_BUILD_EXAMPLES=OFF -DSkyr_BUILD_FILESYSTEM_PATH_FUNCTIONS=$BUILD_FILESYSTEM_PATH_FUNCTIONS ..
7273
- make -j 8
7374
- make test
7475

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ option(Skyr_BUILD_EXAMPLES "Build the URL examples." OFF)
1313
option(Skyr_FULL_WARNINGS "Build the library with all warnings turned on." ON)
1414
option(Skyr_WARNINGS_AS_ERRORS "Treat warnings as errors." ON)
1515
option(Skyr_USE_STATIC_CRT "Use static C Runtime library (/MT or MTd)." ON)
16+
option(Skyr_BUILD_FILESYSTEM_PATH_FUNCTIONS "Build the filesystem path functions" ON)
1617

1718
find_package(Threads REQUIRED)
1819

README.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,22 @@ This library provides:
2727
This project requires the availability of a C++17 compliant compiler
2828
and standard library.
2929

30-
### Building with `CMake` and `Make`
30+
### Building with `CMake` and `Ninja`
3131

3232
From a terminal, execute the following sequence of commands:
3333

3434
```bash
3535
> mkdir _build
3636
> cd _build
37-
> cmake ..
38-
> make -j4
37+
> cmake .. -G "Ninja"
38+
> ninja
3939
```
4040

41-
To run the tests, run `ctest` from the terminal while in the
41+
To run the tests, run `ninja test` from the terminal while in the
4242
`_build` directory:
4343

4444
```bash
45-
> ctest
45+
> ninja test
4646
```
4747

4848
### Building with `CMake` and `Visual Studio 2017`
@@ -63,7 +63,7 @@ These examples are based on the
6363
To build the examples, run `cmake` as follows:
6464

6565
```bash
66-
> cmake .. -DSkyr_BUILD_EXAMPLES=ON
66+
> cmake .. -G "Ninja" -DSkyr_BUILD_EXAMPLES=ON
6767
```
6868

6969
### Creating a URL without a base URL
@@ -125,13 +125,13 @@ This gives the output: `https://example.org/%F0%9F%8F%B3%EF%B8%8F%E2%80%8D%F0%9F
125125
126126
## Installation
127127
128-
### Installing with `CMake` and `Make`
128+
### Installing with `CMake` and `Ninja`
129129
130130
```bash
131-
> cmake .. DCMAKE_INSTALL_PREFIX=$PREFIX
132-
> make -j4
133-
> make test # optional
134-
> make install
131+
> cmake .. -G "Ninja" -DCMAKE_INSTALL_PREFIX=$PREFIX
132+
> ninja
133+
> ninja test # optional
134+
> ninja install
135135
```
136136

137137
Where `$PREFIX` is the location where you want to install the

include/skyr/filesystem.hpp

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2018 Glyn Matthews.
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// (See accompanying file LICENSE_1_0.txt or copy at
4+
// http://www.boost.org/LICENSE_1_0.txt)
5+
6+
#ifndef SKYR_FILESYSTEM_PATH_HPP
7+
#define SKYR_FILESYSTEM_PATH_HPP
8+
9+
#include <system_error>
10+
#include <filesystem>
11+
#include <skyr/expected.hpp>
12+
#include <skyr/url.hpp>
13+
14+
namespace skyr {
15+
namespace filesystem {
16+
enum class path_errc {
17+
invalid_path=1,
18+
percent_decoding_error=2,
19+
};
20+
21+
std::error_code make_error_code(path_errc error);
22+
23+
expected<url, std::error_code> from_path(const std::filesystem::path &path);
24+
25+
expected<std::filesystem::path, std::error_code> to_path(const url &input);
26+
} // namespace filesystem
27+
} // namespace skyr
28+
29+
#endif // SKYR_FILESYSTEM_PATH_HPP

include/skyr/url.hpp

+40-11
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class url {
137137
/// \returns The underlying URL string
138138
string_type href() const;
139139

140-
///
140+
/// @{
141141
/// \tparam Source The input string type
142142
/// \param input The input string
143143
/// \returns An error on failure to parse the new URL
@@ -155,6 +155,9 @@ class url {
155155
return set_href(std::move(bytes.value()));
156156
}
157157

158+
expected<void, std::error_code> set_href(string_type &&href);
159+
/// @}
160+
158161
/// The URL string
159162
///
160163
/// Equivalent to `skyr::serialize(url_).value()`
@@ -168,6 +171,7 @@ class url {
168171
/// \returns The [URL protocol](https://url.spec.whatwg.org/#dom-url-protocol)
169172
string_type protocol() const;
170173

174+
/// @{
171175
/// Sets the [URL protocol](https://url.spec.whatwg.org/#dom-url-protocol)
172176
///
173177
/// \param protocol The new URL protocol
@@ -186,9 +190,13 @@ class url {
186190
return set_protocol(std::move(bytes.value()));
187191
}
188192

193+
expected<void, std::error_code> set_protocol(string_type &&protocol);
194+
/// @}
195+
189196
/// \returns The [URL username](https://url.spec.whatwg.org/#dom-url-username)
190197
string_type username() const;
191198

199+
/// @{
192200
/// Sets the [URL username](https://url.spec.whatwg.org/#dom-url-username)
193201
///
194202
/// \param username The new username
@@ -207,13 +215,17 @@ class url {
207215
return set_username(std::move(bytes.value()));
208216
}
209217

218+
expected<void, std::error_code> set_username(string_type &&username);
219+
/// @}
220+
210221
/// The [URL password](https://url.spec.whatwg.org/#dom-url-password)
211222
///
212223
/// Equivalent to: `url_.password? url_.password.value() : string_type()`
213224
///
214225
/// \returns The URL password
215226
string_type password() const;
216227

228+
/// @{
217229
/// Sets the [URL password](https://url.spec.whatwg.org/#dom-url-password)
218230
///
219231
/// \param password The new password
@@ -231,10 +243,14 @@ class url {
231243
}
232244
return set_password(std::move(bytes.value()));
233245
}
246+
247+
expected<void, std::error_code> set_password(string_type &&password);
248+
/// @}
234249

235250
/// \returns The [URL host](https://url.spec.whatwg.org/#dom-url-host)
236251
string_type host() const;
237252

253+
/// @{
238254
/// Sets the [URL host](https://url.spec.whatwg.org/#dom-url-host)
239255
///
240256
/// \param host The new URL host
@@ -253,9 +269,13 @@ class url {
253269
return set_host(std::move(bytes.value()));
254270
}
255271

272+
expected<void, std::error_code> set_host(string_type &&host);
273+
/// @}
274+
256275
/// \returns The [URL hostname](https://url.spec.whatwg.org/#dom-url-hostname)
257276
string_type hostname() const;
258277

278+
/// @{
259279
/// Sets the [URL hostname](https://url.spec.whatwg.org/#dom-url-hostname)
260280
///
261281
/// \param hostname The new URL host name
@@ -274,6 +294,9 @@ class url {
274294
return set_hostname(std::move(bytes.value()));
275295
}
276296

297+
expected<void, std::error_code> set_hostname(string_type &&hostname);
298+
/// @}
299+
277300
/// \returns The [URL port](https://url.spec.whatwg.org/#dom-url-port)
278301
string_type port() const;
279302

@@ -287,6 +310,7 @@ class url {
287310
std::strtoul(port_first, &port_last, 10));
288311
}
289312

313+
/// @{
290314
/// Sets the [URL port](https://url.spec.whatwg.org/#dom-url-port)
291315
///
292316
/// \param port The new port
@@ -296,11 +320,15 @@ class url {
296320
return set_port_impl(port);
297321
}
298322

323+
expected<void, std::error_code> set_port(string_type &&port);
324+
/// @}
325+
299326
/// Returns the [URL pathname](https://url.spec.whatwg.org/#dom-url-pathname)
300327
///
301328
/// \returns The URL pathname
302329
string_type pathname() const;
303330

331+
/// @{
304332
/// Sets the [URL pathname](https://url.spec.whatwg.org/#dom-url-pathname)
305333
///
306334
/// \param pathname The new pathname
@@ -319,11 +347,15 @@ class url {
319347
return set_pathname(std::move(bytes.value()));
320348
}
321349

350+
expected<void, std::error_code> set_pathname(string_type &&pathname);
351+
/// @}
352+
322353
/// Returns the [URL search string](https://url.spec.whatwg.org/#dom-url-search)
323354
///
324355
/// \returns The URL search string
325356
string_type search() const;
326357

358+
/// @{
327359
/// Sets the [URL search string](https://url.spec.whatwg.org/#dom-url-search)
328360
///
329361
/// \param search The new search string
@@ -342,6 +374,9 @@ class url {
342374
return set_search(std::move(bytes.value()));
343375
}
344376

377+
expected<void, std::error_code> set_search(string_type &&search);
378+
/// @}
379+
345380
/// \returns A reference to the search parameters
346381
url_search_parameters &search_parameters();
347382

@@ -350,6 +385,7 @@ class url {
350385
/// \returns The URL hash string
351386
string_type hash() const;
352387

388+
/// @{
353389
/// Sets the [URL hash string](https://url.spec.whatwg.org/#dom-url-hash)
354390
///
355391
/// \param hash The new hash string
@@ -368,6 +404,9 @@ class url {
368404
return set_hash(std::move(bytes.value()));
369405
}
370406

407+
expected<void, std::error_code> set_hash(string_type &&hash);
408+
/// @}
409+
371410
/// \returns A copy to the underlying `url_record` implementation.
372411
url_record record() const;
373412

@@ -441,16 +480,6 @@ class url {
441480
string_type &&input,
442481
optional<url_record> base = nullopt);
443482
void update_record(url_record &&record);
444-
expected<void, std::error_code> set_href(string_type &&href);
445-
expected<void, std::error_code> set_protocol(string_type &&protocol);
446-
expected<void, std::error_code> set_username(string_type &&username);
447-
expected<void, std::error_code> set_password(string_type &&password);
448-
expected<void, std::error_code> set_host(string_type &&host);
449-
expected<void, std::error_code> set_hostname(string_type &&hostname);
450-
expected<void, std::error_code> set_port(string_type &&port);
451-
expected<void, std::error_code> set_pathname(string_type &&pathname);
452-
expected<void, std::error_code> set_search(string_type &&search);
453-
expected<void, std::error_code> set_hash(string_type &&hash);
454483

455484
template <class Source>
456485
expected<void, std::error_code> set_port_impl(

src/CMakeLists.txt

+11
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ set(Skyr_SRCS
4444
${CMAKE_SOURCE_DIR}/include/skyr/url_error.hpp
4545
${CMAKE_SOURCE_DIR}/include/skyr/url_search_parameters.hpp)
4646

47+
if (Skyr_BUILD_FILESYSTEM_PATH_FUNCTIONS)
48+
LIST(APPEND Skyr_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/filesystem.cpp)
49+
LIST(APPEND Skyr_SRCS ${CMAKE_SOURCE_DIR}/include/skyr/filesystem.hpp)
50+
endif()
51+
4752
add_library(skyr-url ${Skyr_SRCS})
4853
target_link_libraries(skyr-url)
4954
if(${CMAKE_CXX_COMPILER_ID} MATCHES Clang)
@@ -52,6 +57,12 @@ if(${CMAKE_CXX_COMPILER_ID} MATCHES Clang)
5257
endif()
5358
endif()
5459

60+
if(${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
61+
if (Skyr_BUILD_FILESYSTEM_PATH_FUNCTIONS)
62+
target_link_libraries(skyr-url "stdc++fs")
63+
endif()
64+
endif()
65+
5566
if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU OR
5667
${CMAKE_CXX_COMPILER_ID} MATCHES Clang)
5768
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wmissing-declarations")

0 commit comments

Comments
 (0)