20#ifndef LIBREPCB_CORE_FILEPROOFNAME_H
21#define LIBREPCB_CORE_FILEPROOFNAME_H
26#include "../exceptions.h"
27#include "../serialization/sexpression.h"
28#include "../utils/toolbox.h"
30#include <type_safe/constrained_type.hpp>
46 template <
typename Value,
typename Predicate>
47 static constexpr auto verify(Value&& val,
const Predicate& p) ->
48 typename std::decay<Value>::type {
49 return p(val) ? std::forward<Value>(val)
52 QString(QCoreApplication::translate(
53 "FileProofName",
"Invalid name: '%1'"))
55 std::forward<Value>(val));
60 static const constexpr std::size_t
MAX_LEN = 20;
62 static QRegularExpression
regex() noexcept {
67 return QRegularExpression(
"\\A(?!\\.+\\z)[-a-zA-Z0-9_+().]{1,20}\\z");
72 .match(value, 0, QRegularExpression::PartialPreferCompleteMatch)
102 return lhs != (*rhs);
105 const QString& rhs)
noexcept {
133 stream << QString(
"FileProofName('%1')").arg(*obj);
138 std::size_t seed = 0) noexcept {
139 return ::qHash(*key, seed);
144 userInput, QRegularExpression(
"[^-a-zA-Z0-9_+().]"),
true,
false,
false,
153 const QString& name)
noexcept {
155 : std::optional<FileProofName>();
The RuntimeError class.
Definition exceptions.h:218
The SExpression class.
Definition sexpression.h:69
static std::unique_ptr< SExpression > createString(const QString &string)
Definition sexpression.cpp:407
const QString & getValue() const
Definition sexpression.cpp:71
Definition occmodel.cpp:77
std::size_t qHash(const AttributeKey &key, std::size_t seed=0) noexcept
Definition attributekey.h:113
bool operator==(const AttributeKey &lhs, const QString &rhs) noexcept
Definition attributekey.h:80
static QString cleanFileProofName(const QString &userInput) noexcept
Definition fileproofname.h:142
std::unique_ptr< SExpression > serialize(const AttributeKey &obj)
Definition attributekey.h:94
bool operator!=(const AttributeKey &lhs, const QString &rhs) noexcept
Definition attributekey.h:86
type_safe::constrained_type< QString, FileProofNameConstraint, FileProofNameVerifier > FileProofName
Definition fileproofname.h:90
static std::optional< FileProofName > parseFileProofName(const QString &name) noexcept
Definition fileproofname.h:152
AttributeKey deserialize(const SExpression &node)
Definition attributekey.h:99
QDataStream & operator<<(QDataStream &stream, const AttributeKey &obj)
Definition attributekey.h:103
QString operator%(const ComponentPrefix &lhs, const QString &rhs) noexcept
Definition componentprefix.h:99
Definition fileproofname.h:59
bool operator()(const QString &value) const noexcept
Definition fileproofname.h:70
static QRegularExpression regex() noexcept
Definition fileproofname.h:62
static const constexpr std::size_t MAX_LEN
Definition fileproofname.h:60
Definition fileproofname.h:45
static constexpr auto verify(Value &&val, const Predicate &p) -> typename std::decay< Value >::type
Definition fileproofname.h:47