Skip to content

Commit f2f44d7

Browse files
committed
Apply codestyle to leftovers sources
1 parent cc58c81 commit f2f44d7

File tree

3 files changed

+101
-110
lines changed

3 files changed

+101
-110
lines changed

src/uri.cpp

Lines changed: 45 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ void uri::initialize(optional<string_type> scheme,
149149
}
150150

151151
if (path) {
152-
uri_parts_.hier_part.path = detail::copy_part(*path, it);
152+
uri_parts_.hier_part.path = detail::copy_part(*path, it);
153153
}
154154

155155
if (query) {
@@ -174,9 +174,10 @@ uri::uri(const uri_builder &builder) {
174174
builder.path_, builder.query_, builder.fragment_);
175175
}
176176

177-
uri::uri(uri &&other) noexcept : uri_(std::move(other.uri_)),
178-
uri_view_(uri_),
179-
uri_parts_(std::move(other.uri_parts_)) {
177+
uri::uri(uri &&other) noexcept
178+
: uri_(std::move(other.uri_)),
179+
uri_view_(uri_),
180+
uri_parts_(std::move(other.uri_parts_)) {
180181
detail::advance_parts(uri_view_, uri_parts_, other.uri_parts_);
181182
other.uri_.clear();
182183
other.uri_view_ = string_view(other.uri_);
@@ -220,9 +221,8 @@ bool uri::has_user_info() const noexcept {
220221
}
221222

222223
uri::string_view uri::user_info() const noexcept {
223-
return has_user_info()
224-
? to_string_view(uri_, *uri_parts_.hier_part.user_info)
225-
: string_view{};
224+
return has_user_info() ? to_string_view(uri_, *uri_parts_.hier_part.user_info)
225+
: string_view{};
226226
}
227227

228228
bool uri::has_host() const noexcept {
@@ -263,50 +263,48 @@ uri::string_view uri::query() const noexcept {
263263
uri::query_iterator::query_iterator() : query_{}, kvp_{} {}
264264

265265
uri::query_iterator::query_iterator(optional<detail::uri_part> query)
266-
: query_(query)
267-
, kvp_{} {
266+
: query_(query), kvp_{} {
268267
if (query_ && query_->empty()) {
269268
query_ = nullopt;
270-
}
271-
else {
269+
} else {
272270
assign_kvp();
273271
}
274272
}
275273

276274
uri::query_iterator::query_iterator(const query_iterator &other)
277-
: query_(other.query_)
278-
, kvp_(other.kvp_) {}
275+
: query_(other.query_), kvp_(other.kvp_) {}
279276

280-
uri::query_iterator &uri::query_iterator::operator = (const query_iterator &other) {
277+
uri::query_iterator &uri::query_iterator::operator=(
278+
const query_iterator &other) {
281279
auto tmp(other);
282280
swap(tmp);
283281
return *this;
284282
}
285283

286-
uri::query_iterator::reference uri::query_iterator::operator ++ () noexcept {
284+
uri::query_iterator::reference uri::query_iterator::operator++() noexcept {
287285
increment();
288286
return kvp_;
289287
}
290288

291-
uri::query_iterator::value_type uri::query_iterator::operator ++ (int) noexcept {
289+
uri::query_iterator::value_type uri::query_iterator::operator++(int) noexcept {
292290
auto original = kvp_;
293291
increment();
294292
return original;
295293
}
296294

297-
uri::query_iterator::reference uri::query_iterator::operator * () const noexcept {
295+
uri::query_iterator::reference uri::query_iterator::operator*() const noexcept {
298296
return kvp_;
299297
}
300298

301-
uri::query_iterator::pointer uri::query_iterator::operator -> () const noexcept {
299+
uri::query_iterator::pointer uri::query_iterator::operator->() const noexcept {
302300
return std::addressof(kvp_);
303301
}
304302

305-
bool uri::query_iterator::operator==(const query_iterator &other) const noexcept {
303+
bool uri::query_iterator::operator==(const query_iterator &other) const
304+
noexcept {
306305
if (!query_ && !other.query_) {
307306
return true;
308-
}
309-
else if (query_ && other.query_) {
307+
} else if (query_ && other.query_) {
310308
// since we're comparing substrings, the address of the first
311309
// element in each iterator must be the same
312310
return std::addressof(kvp_.first) == std::addressof(other.kvp_.first);
@@ -326,7 +324,7 @@ void uri::query_iterator::advance_to_next_kvp() noexcept {
326324
first, last, [](char c) -> bool { return c == '&' || c == ';'; });
327325

328326
if (sep_it != last) {
329-
++sep_it; // skip next separator
327+
++sep_it; // skip next separator
330328
}
331329

332330
// reassign query to the next element
@@ -343,9 +341,10 @@ void uri::query_iterator::assign_kvp() noexcept {
343341

344342
kvp_.first = string_view(std::addressof(*first), std::distance(first, eq_it));
345343
if (eq_it != sep_it) {
346-
++eq_it; // skip '=' symbol
344+
++eq_it; // skip '=' symbol
347345
}
348-
kvp_.second = string_view(std::addressof(*eq_it), std::distance(eq_it, sep_it));
346+
kvp_.second =
347+
string_view(std::addressof(*eq_it), std::distance(eq_it, sep_it));
349348
}
350349

351350
void uri::query_iterator::increment() noexcept {
@@ -362,7 +361,8 @@ void uri::query_iterator::increment() noexcept {
362361
}
363362

364363
uri::query_iterator uri::query_begin() const noexcept {
365-
return has_query()? uri::query_iterator{uri_parts_.query} : uri::query_iterator{};
364+
return has_query() ? uri::query_iterator{uri_parts_.query}
365+
: uri::query_iterator{};
366366
}
367367

368368
uri::query_iterator uri::query_end() const noexcept {
@@ -378,9 +378,7 @@ uri::string_view uri::fragment() const noexcept {
378378
: string_view{};
379379
}
380380

381-
bool uri::has_authority() const noexcept {
382-
return has_host();
383-
}
381+
bool uri::has_authority() const noexcept { return has_host(); }
384382

385383
uri::string_view uri::authority() const noexcept {
386384
if (!has_host()) {
@@ -402,26 +400,22 @@ uri::string_view uri::authority() const noexcept {
402400
auto first = std::begin(host), last = std::end(host);
403401
if (has_user_info() && !user_info.empty()) {
404402
first = std::begin(user_info);
405-
}
406-
else if (host.empty() && has_port() && !port.empty()) {
403+
} else if (host.empty() && has_port() && !port.empty()) {
407404
first = std::begin(port);
408-
--first; // include ':' before port
405+
--first; // include ':' before port
409406
}
410407

411408
if (host.empty()) {
412409
if (has_port() && !port.empty()) {
413410
last = std::end(port);
414-
}
415-
else if (has_user_info() && !user_info.empty()) {
411+
} else if (has_user_info() && !user_info.empty()) {
416412
last = std::end(user_info);
417-
++last; // include '@'
413+
++last; // include '@'
418414
}
419-
}
420-
else if (has_port()) {
415+
} else if (has_port()) {
421416
if (port.empty()) {
422-
++last; // include ':' after host
423-
}
424-
else {
417+
++last; // include ':' after host
418+
} else {
425419
last = std::end(port);
426420
}
427421
}
@@ -443,9 +437,7 @@ std::u32string uri::u32string() const {
443437
return std::u32string(std::begin(*this), std::end(*this));
444438
}
445439

446-
uri::string_view uri::view() const noexcept {
447-
return uri_view_;
448-
}
440+
uri::string_view uri::view() const noexcept { return uri_view_; }
449441

450442
bool uri::empty() const noexcept { return uri_.empty(); }
451443

@@ -473,13 +465,15 @@ uri uri::normalize(uri_comparison_level level) const {
473465

474466
// if (parts.hier_part.host) {
475467
// std::string::iterator first, last;
476-
// std::tie(first, last) = mutable_part(normalized, *parts.hier_part.host);
477-
// std::transform(first, last, first,
478-
// [](char ch) { return std::tolower(ch, std::locale()); });
468+
// std::tie(first, last) = mutable_part(normalized,
469+
// *parts.hier_part.host); std::transform(first, last, first,
470+
// [](char ch) { return std::tolower(ch, std::locale());
471+
// });
479472
// }
480473

481474
// ...except when used in percent encoding
482-
detail::for_each(normalized, detail::percent_encoded_to_upper<std::string>());
475+
detail::for_each(normalized,
476+
detail::percent_encoded_to_upper<std::string>());
483477

484478
// parts are invalidated here
485479
// there's got to be a better way of doing this that doesn't
@@ -490,7 +484,8 @@ uri uri::normalize(uri_comparison_level level) const {
490484
normalized_view = string_view(normalized);
491485

492486
// need to parse the parts again as the underlying string has changed
493-
const_iterator it = std::begin(normalized_view), last = std::end(normalized_view);
487+
const_iterator it = std::begin(normalized_view),
488+
last = std::end(normalized_view);
494489
bool is_valid = detail::parse(it, last, parts);
495490
ignore(is_valid);
496491
assert(is_valid);
@@ -550,9 +545,9 @@ uri uri::make_relative(const uri &other) const {
550545
}
551546

552547
auto path =
553-
detail::normalize_path(this->path(), uri_comparison_level::syntax_based);
554-
auto other_path = detail::normalize_path(other.path(),
555-
uri_comparison_level::syntax_based);
548+
detail::normalize_path(this->path(), uri_comparison_level::syntax_based);
549+
auto other_path =
550+
detail::normalize_path(other.path(), uri_comparison_level::syntax_based);
556551

557552
optional<string_type> query, fragment;
558553
if (other.has_query()) {

src/uri_builder.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void uri_builder::set_scheme(string_type &&scheme) {
4848
// validate scheme is valid and normalize
4949
scheme_ = scheme;
5050
detail::transform(*scheme_, std::begin(*scheme_),
51-
[] (char ch) { return std::tolower(ch, std::locale()); });
51+
[](char ch) { return std::tolower(ch, std::locale()); });
5252
}
5353

5454
void uri_builder::set_user_info(string_type &&user_info) {
@@ -114,24 +114,23 @@ uri_builder &uri_builder::clear_path() {
114114
void uri_builder::append_query_component(string_type &&name) {
115115
if (!query_) {
116116
query_ = string_type();
117-
}
118-
else {
117+
} else {
119118
query_->append("&");
120119
}
121-
network::uri::encode_query_component(
122-
std::begin(name), std::end(name), std::back_inserter(*query_));
120+
network::uri::encode_query_component(std::begin(name), std::end(name),
121+
std::back_inserter(*query_));
123122
}
124123

125-
void uri_builder::append_query_key_value_pair(string_type &&key, string_type &&value) {
124+
void uri_builder::append_query_key_value_pair(string_type &&key,
125+
string_type &&value) {
126126
if (!query_) {
127127
query_ = string_type();
128128
} else {
129129
query_->push_back('&');
130130
}
131-
network::uri::encode_query_key_value_pair(
132-
std::begin(key), std::end(key),
133-
std::begin(value), std::end(value),
134-
std::back_inserter(*query_));
131+
network::uri::encode_query_key_value_pair(std::begin(key), std::end(key),
132+
std::begin(value), std::end(value),
133+
std::back_inserter(*query_));
135134
}
136135

137136
uri_builder &uri_builder::clear_query() {

src/uri_errors.cpp

Lines changed: 47 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -8,65 +8,62 @@
88

99
namespace network {
1010

11-
class uri_category_impl : public std::error_category {
12-
13-
public:
14-
15-
uri_category_impl() = default;
16-
17-
virtual ~uri_category_impl() noexcept;
18-
19-
virtual const char *name() const noexcept;
20-
21-
virtual std::string message(int ev) const;
22-
23-
};
24-
25-
uri_category_impl::~uri_category_impl() noexcept {}
26-
27-
const char *uri_category_impl::name() const noexcept {
28-
static const char name[] = "uri_error";
29-
return name;
30-
}
31-
32-
std::string uri_category_impl::message(int ev) const {
33-
switch (uri_error(ev)) {
34-
case uri_error::invalid_syntax:
35-
return "Unable to parse URI string.";
36-
case uri_error::not_enough_input:
37-
return "Percent decoding: Not enough input.";
38-
case uri_error::non_hex_input:
39-
return "Percent decoding: Non-hex input.";
40-
case uri_error::conversion_failed:
41-
return "Percent decoding: Conversion failed.";
11+
class uri_category_impl : public std::error_category {
12+
public:
13+
uri_category_impl() = default;
14+
15+
virtual ~uri_category_impl() noexcept;
16+
17+
virtual const char *name() const noexcept;
18+
19+
virtual std::string message(int ev) const;
20+
};
21+
22+
uri_category_impl::~uri_category_impl() noexcept {}
23+
24+
const char *uri_category_impl::name() const noexcept {
25+
static const char name[] = "uri_error";
26+
return name;
27+
}
28+
29+
std::string uri_category_impl::message(int ev) const {
30+
switch (uri_error(ev)) {
31+
case uri_error::invalid_syntax:
32+
return "Unable to parse URI string.";
33+
case uri_error::not_enough_input:
34+
return "Percent decoding: Not enough input.";
35+
case uri_error::non_hex_input:
36+
return "Percent decoding: Non-hex input.";
37+
case uri_error::conversion_failed:
38+
return "Percent decoding: Conversion failed.";
4239
default:
43-
break;
44-
}
45-
return "Unknown URI error.";
40+
break;
4641
}
42+
return "Unknown URI error.";
43+
}
4744

48-
const std::error_category &uri_category() {
49-
static uri_category_impl uri_category;
50-
return uri_category;
51-
}
45+
const std::error_category &uri_category() {
46+
static uri_category_impl uri_category;
47+
return uri_category;
48+
}
5249

53-
std::error_code make_error_code(uri_error e) {
54-
return std::error_code(static_cast<int>(e), uri_category());
55-
}
50+
std::error_code make_error_code(uri_error e) {
51+
return std::error_code(static_cast<int>(e), uri_category());
52+
}
5653

57-
uri_syntax_error::uri_syntax_error()
58-
: std::system_error(make_error_code(uri_error::invalid_syntax)) {}
54+
uri_syntax_error::uri_syntax_error()
55+
: std::system_error(make_error_code(uri_error::invalid_syntax)) {}
5956

60-
uri_syntax_error::~uri_syntax_error() noexcept {}
57+
uri_syntax_error::~uri_syntax_error() noexcept {}
6158

62-
uri_builder_error::uri_builder_error()
63-
: std::system_error(make_error_code(uri_error::invalid_uri)) {}
59+
uri_builder_error::uri_builder_error()
60+
: std::system_error(make_error_code(uri_error::invalid_uri)) {}
6461

65-
uri_builder_error::~uri_builder_error() noexcept {}
62+
uri_builder_error::~uri_builder_error() noexcept {}
6663

67-
percent_decoding_error::percent_decoding_error(uri_error error)
68-
: std::system_error(make_error_code(error)) {}
64+
percent_decoding_error::percent_decoding_error(uri_error error)
65+
: std::system_error(make_error_code(error)) {}
6966

70-
percent_decoding_error::~percent_decoding_error() noexcept {}
67+
percent_decoding_error::~percent_decoding_error() noexcept {}
7168

7269
} // namespace network

0 commit comments

Comments
 (0)