20#ifndef LIBREPCB_CORE_TAG_H
21#define LIBREPCB_CORE_TAG_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 {
50 ? std::forward<Value>(val)
53 QString(QCoreApplication::translate(
"Tag",
"Invalid tag: '%1'"))
55 std::forward<Value>(val));
63 return QRegularExpression(
"\\A[-a-z0-9.]{1,32}\\z")
64 .match(value, 0, QRegularExpression::PartialPreferCompleteMatch)
82using Tag = type_safe::constrained_type<QString, TagConstraint, TagVerifier>;
96inline QString
operator%(
const Tag& lhs,
const QString& rhs)
noexcept {
99inline QString
operator%(
const QString& lhs,
const Tag& rhs)
noexcept {
103 return (*lhs) % (*rhs);
122 stream << QString(
"Tag('%1')").arg(*obj);
126inline std::size_t
qHash(
const Tag& key, std::size_t seed = 0) noexcept {
127 return ::qHash(*key, seed);
130inline static QString
cleanTag(
const QString& userInput)
noexcept {
132 userInput, QRegularExpression(
"[^-a-z0-9.]"),
true,
true,
false,
"-",
136inline static std::optional<Tag>
parseTag(
const QString& tag)
noexcept {
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
static QString cleanTag(const QString &userInput) noexcept
Definition tag.h:130
bool operator==(const AttributeKey &lhs, const QString &rhs) noexcept
Definition attributekey.h:80
type_safe::constrained_type< QString, TagConstraint, TagVerifier > Tag
Definition tag.h:82
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
static std::optional< Tag > parseTag(const QString &tag) noexcept
Definition tag.h:136
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
bool operator()(const QString &value) const noexcept
Definition tag.h:62
static const constexpr int MAX_LENGTH
Definition tag.h:60
static constexpr auto verify(Value &&val, const Predicate &p) -> typename std::decay< Value >::type
Definition tag.h:47