Skip to content

Commit e02053d

Browse files
committed
fix minor review findings in title
1 parent 538745b commit e02053d

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/domain/title.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ expected<std::string_view> check_charset(std::string_view text);
1919
title::title(std::string_view text) : text{text} {}
2020

2121
expected<title> title::create(std::string_view text) {
22+
auto const make_title = [](auto text) { return title{text}; };
2223
// clang-format off
2324
return check_trimmed(text)
2425
.and_then(check_length)
2526
.and_then(check_charset)
26-
.map([](auto text){ return title{text}; });
27+
.map(make_title);
2728
// clang-format on
2829
}
2930

@@ -33,8 +34,10 @@ std::string title::to_string() const {
3334

3435
namespace {
3536
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)) {
3841
return unexpected(domain_error::TITLE_NOT_TRIMMED);
3942
}
4043
return text;

0 commit comments

Comments
 (0)