20 #ifndef LIBREPCB_ELEMENTNAME_H 21 #define LIBREPCB_ELEMENTNAME_H 29 #include <type_safe/constrained_type.hpp> 43 QString ret = userInput.trimmed();
44 for (
int i = ret.length() - 1; i >= 0; --i) {
45 if (!ret[i].isPrint()) {
54 template <
typename Value,
typename Predicate>
55 static constexpr
auto verify(Value&& val,
const Predicate& p) ->
56 typename std::decay<Value>::type {
58 ? std::forward<Value>(val)
60 QString(QApplication::translate(
61 "ElementName",
"Invalid name: '%1'"))
63 std::forward<Value>(val));
69 if (value.isEmpty())
return false;
70 if (value.length() > 70)
return false;
71 if (value != value.trimmed())
return false;
72 foreach (
const QChar& c, value) {
73 if (!c.isPrint())
return false;
101 return (*lhs) != rhs;
104 return lhs != (*rhs);
125 Q_UNUSED(fileFormat);
135 stream << QString(
"ElementName('%1'')").arg(*obj);
149 #endif // LIBREPCB_ELEMENTNAME_H static constexpr auto verify(Value &&val, const Predicate &p) -> typename std::decay< Value >::type
Definition: elementname.h:55
The Version class represents a version number in the format "1.42.7".
Definition: version.h:60
QDataStream & operator<<(QDataStream &stream, const AttributeKey &obj)
Definition: attributekey.h:110
SExpression serialize(const HAlign &obj)
Definition: alignment.h:76
Definition: airwiresbuilder.cpp:32
static QString cleanElementName(const QString &userInput) noexcept
Definition: elementname.h:42
HAlign deserialize(const SExpression &sexpr, const Version &fileFormat)
Definition: alignment.h:90
Definition: elementname.h:53
bool operator()(const QString &value) const noexcept
Definition: elementname.h:68
uint qHash(const ElementName &key, uint seed=0) noexcept
Definition: elementname.h:139
static SExpression createString(const QString &string)
Definition: sexpression.cpp:294
Definition: elementname.h:67
The RuntimeError class.
Definition: exceptions.h:216
QString operator%(const CircuitIdentifier &lhs, const QString &rhs) noexcept
Definition: circuitidentifier.h:108
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
const QString & getValue() const
Definition: sexpression.cpp:77
The SExpression class.
Definition: sexpression.h:72
uint qHash(const AttributeKey &key, uint seed=0) noexcept
Definition: attributekey.h:120
type_safe::constrained_type< QString, ElementNameConstraint, ElementNameVerifier > ElementName
Definition: elementname.h:92