FOSSredder 0.5.0
Loading...
Searching...
No Matches
FilterSpec.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 = 1024;
17
18} // namespace
19
21 : value_(normalize(std::move(value))) {}
22
23const std::string& FilterSpec::value() const noexcept { return value_; }
24
25constexpr std::size_t FilterSpec::maxLength() noexcept {
26 return kMaxLength;
27}
28
29std::string FilterSpec::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 FilterSpec::isValid(const std::string& value) {
43 const auto normalized = normalize(value);
44 return !normalized.empty() && normalized.size() <= maxLength();
45}
46
47bool FilterSpec::empty() const noexcept {
48 return value_.empty();
49}
50
51} // namespace core::domain
Value object for analysis filter specifications.
const std::string & value() const noexcept
bool empty() const noexcept
Checks whether the stored value is empty.
static std::string normalize(std::string value)
Trims leading and trailing whitespace from a filter specification.
static bool isValid(const std::string &value)
Checks whether a raw filter specification is valid.
static constexpr std::size_t maxLength() noexcept
Returns the maximum supported filter specification length.