FOSSredder
0.5.0
Loading...
Searching...
No Matches
BookingDate.cpp
Go to the documentation of this file.
1
5
6
#include "
core/domain/values/BookingDate.h
"
7
8
#include <algorithm>
9
#include <cctype>
10
#include <utility>
11
12
namespace
core::domain
{
13
14
namespace
{
15
16
constexpr
std::size_t kMaxLength = 32;
17
18
}
// namespace
19
20
BookingDate::BookingDate
(std::string
value
)
21
: value_(
normalize
(std::move(
value
))) {}
22
23
const
std::string&
BookingDate::value
() const noexcept {
return
value_; }
24
25
constexpr
std::size_t
BookingDate::maxLength
() noexcept {
26
return
kMaxLength;
27
}
28
29
std::string
BookingDate::normalize
(std::string
value
) {
30
const
auto
begin = std::find_if_not(
value
.begin(),
value
.end(), [](
unsigned
char
c) {
31
return std::isspace(c) != 0;
32
});
33
const
auto
end = std::find_if_not(
value
.rbegin(),
value
.rend(), [](
unsigned
char
c) {
34
return std::isspace(c) != 0;
35
}).base();
36
if
(begin >= end) {
37
return
{};
38
}
39
return
std::string(begin, end);
40
}
41
42
bool
BookingDate::isValid
(
const
std::string&
value
) {
43
const
auto
normalized =
normalize
(
value
);
44
return
!normalized.empty() && normalized.size() <=
maxLength
();
45
}
46
47
bool
BookingDate::empty
() const noexcept {
48
return
value_.empty();
49
}
50
51
}
// namespace core::domain
BookingDate.h
Value object for normalized booking dates.
core::domain::BookingDate::value
const std::string & value() const noexcept
Definition
BookingDate.cpp:23
core::domain::BookingDate::BookingDate
BookingDate()=default
core::domain::BookingDate::normalize
static std::string normalize(std::string value)
Definition
BookingDate.cpp:29
core::domain::BookingDate::empty
bool empty() const noexcept
Definition
BookingDate.cpp:47
core::domain::BookingDate::isValid
static bool isValid(const std::string &value)
Definition
BookingDate.cpp:42
core::domain::BookingDate::maxLength
static constexpr std::size_t maxLength() noexcept
Definition
BookingDate.cpp:25
core::domain
Definition
application/import/ImportResult.h:16
core
src
domain
values
BookingDate.cpp
Generated by
1.14.0