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 <optional/tl/optional.hpp> 31 #include <type_safe/constrained_type.hpp> 45 template <
typename Value,
typename Predicate>
46 static constexpr
auto verify(Value&& val,
const Predicate& p) ->
47 typename std::decay<Value>::type {
49 ? std::forward<Value>(val)
51 QString(QCoreApplication::translate(
52 "ElementName",
"Invalid name: '%1'"))
54 std::forward<Value>(val));
60 if (value.isEmpty())
return false;
61 if (value.length() > 70)
return false;
62 if (value != value.trimmed())
return false;
63 foreach (
const QChar& c, value) {
64 if (!c.isPrint())
return false;
125 const QString str = node.
getValue();
126 return str.isEmpty() ? tl::nullopt
136 stream << QString(
"ElementName('%1')").arg(*obj);
145 QString ret = userInput.trimmed();
146 for (
int i = ret.length() - 1; i >= 0; --i) {
147 if (!ret[i].isPrint()) {
156 const char* textNoTr) noexcept {
157 Q_ASSERT(ElementNameConstraint()(textNoTr));
158 const QString textTr =
160 if (ElementNameConstraint()(textTr)) {
static constexpr auto verify(Value &&val, const Predicate &p) -> typename std::decay< Value >::type
Definition: elementname.h:46
QDataStream & operator<<(QDataStream &stream, const AttributeKey &obj)
Definition: attributekey.h:108
QString operator%(const ComponentPrefix &lhs, const QString &rhs) noexcept
Definition: componentprefix.h:96
Definition: occmodel.cpp:76
static QString cleanElementName(const QString &userInput) noexcept
Definition: elementname.h:144
Definition: elementname.h:44
bool operator()(const QString &value) const noexcept
Definition: elementname.h:59
uint qHash(const ElementName &key, uint seed=0) noexcept
Definition: elementname.h:140
static SExpression createString(const QString &string)
Definition: sexpression.cpp:380
static ElementName elementNameFromTr(const char *context, const char *textNoTr) noexcept
Definition: elementname.h:155
Definition: elementname.h:58
The RuntimeError class.
Definition: exceptions.h:216
AttributeKey deserialize(const SExpression &node)
Definition: attributekey.h:104
bool operator==(const AttributeKey &lhs, const QString &rhs) noexcept
Definition: attributekey.h:85
bool operator!=(const AttributeKey &lhs, const QString &rhs) noexcept
Definition: attributekey.h:91
SExpression serialize(const AttributeKey &obj)
Definition: attributekey.h:99
const QString & getValue() const
Definition: sexpression.cpp:71
The SExpression class.
Definition: sexpression.h:66
uint qHash(const AttributeKey &key, uint seed=0) noexcept
Definition: attributekey.h:118
type_safe::constrained_type< QString, ElementNameConstraint, ElementNameVerifier > ElementName
Definition: elementname.h:83