20#ifndef LIBREPCB_CORE_ELEMENTNAME_H
21#define LIBREPCB_CORE_ELEMENTNAME_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)
52 QString(QCoreApplication::translate(
53 "ElementName",
"Invalid name: '%1'"))
55 std::forward<Value>(val));
61 if (value.isEmpty())
return false;
62 if (value.length() > 70)
return false;
63 if (value != value.trimmed())
return false;
64 foreach (
const QChar& c, value) {
65 if (!c.isPrint())
return false;
121 const std::optional<ElementName>& obj) {
127 const QString str = node.
getValue();
128 return str.isEmpty() ? std::nullopt
138 stream << QString(
"ElementName('%1')").arg(*obj);
143 std::size_t seed = 0) noexcept {
144 return ::qHash(*key, seed);
148 QString ret = userInput.trimmed();
149 for (
int i = ret.length() - 1; i >= 0; --i) {
150 if (!ret[i].isPrint()) {
159 const char* textNoTr)
noexcept {
161 const QString textTr =
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:76
std::size_t qHash(const AttributeKey &key, std::size_t seed=0) noexcept
Definition attributekey.h:118
static QString cleanElementName(const QString &userInput) noexcept
Definition elementname.h:147
bool operator==(const AttributeKey &lhs, const QString &rhs) noexcept
Definition attributekey.h:85
std::unique_ptr< SExpression > serialize(const AttributeKey &obj)
Definition attributekey.h:99
bool operator!=(const AttributeKey &lhs, const QString &rhs) noexcept
Definition attributekey.h:91
static ElementName elementNameFromTr(const char *context, const char *textNoTr) noexcept
Definition elementname.h:158
AttributeKey deserialize(const SExpression &node)
Definition attributekey.h:104
QDataStream & operator<<(QDataStream &stream, const AttributeKey &obj)
Definition attributekey.h:108
QString operator%(const ComponentPrefix &lhs, const QString &rhs) noexcept
Definition componentprefix.h:102
type_safe::constrained_type< QString, ElementNameConstraint, ElementNameVerifier > ElementName
Definition elementname.h:84
Definition elementname.h:59
bool operator()(const QString &value) const noexcept
Definition elementname.h:60
Definition elementname.h:45
static constexpr auto verify(Value &&val, const Predicate &p) -> typename std::decay< Value >::type
Definition elementname.h:47