File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -19,11 +19,12 @@ expected<std::string_view> check_charset(std::string_view text);
19
19
title::title (std::string_view text) : text{text} {}
20
20
21
21
expected<title> title::create (std::string_view text) {
22
+ auto const make_title = [](auto text) { return title{text}; };
22
23
// clang-format off
23
24
return check_trimmed (text)
24
25
.and_then (check_length)
25
26
.and_then (check_charset)
26
- .map ([]( auto text){ return title{text}; } );
27
+ .map (make_title );
27
28
// clang-format on
28
29
}
29
30
@@ -33,8 +34,10 @@ std::string title::to_string() const {
33
34
34
35
namespace {
35
36
expected<std::string_view> check_trimmed (std::string_view text) {
36
- const auto trimmed_length = ranges::size (text | ranges::views::trim ([](char c) { return isspace (c); }));
37
- if (trimmed_length != text.length ()) {
37
+ if (text.empty ()) {
38
+ return text;
39
+ }
40
+ if ((std::isspace (text.front ()) != 0 ) || (std::isspace (text.back ()) != 0 )) {
38
41
return unexpected (domain_error::TITLE_NOT_TRIMMED);
39
42
}
40
43
return text;
You can’t perform that action at this time.
0 commit comments