FOSSredder 0.5.0
Loading...
Searching...
No Matches
AnalysisType.cpp
Go to the documentation of this file.
1
5
7
8#include <algorithm>
9#include <cctype>
10#include <utility>
11
12namespace core::domain {
13
14namespace {
15
16constexpr std::size_t kMaxLength = 64;
17
18} // namespace
19
21 : value_(normalize(std::move(value))) {}
22
23const std::string& AnalysisType::value() const noexcept { return value_; }
24
25constexpr std::size_t AnalysisType::maxLength() noexcept {
26 return kMaxLength;
27}
28
29std::string AnalysisType::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
42bool AnalysisType::isValid(const std::string& value) {
43 const auto normalized = normalize(value);
44 return !normalized.empty() && normalized.size() <= maxLength();
45}
46
47bool AnalysisType::empty() const noexcept {
48 return value_.empty();
49}
50
51} // namespace core::domain
Value object for analysis type labels.
static constexpr std::size_t maxLength() noexcept
Returns the maximum supported analysis type length.
static std::string normalize(std::string value)
Trims leading and trailing whitespace from an analysis type.
bool empty() const noexcept
Checks whether the stored value is empty.
const std::string & value() const noexcept
static bool isValid(const std::string &value)
Checks whether a raw analysis type is valid.