20#ifndef LIBREPCB_CORE_ELEMENTNAME_H
21#define LIBREPCB_CORE_ELEMENTNAME_H
26#include "../exceptions.h"
27#include "../qtcompat.h"
28#include "../serialization/sexpression.h"
29#include "../utils/toolbox.h"
31#include <optional/tl/optional.hpp>
32#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 tl::optional<ElementName>& obj) {
127 const QString str = node.
getValue();
128 return str.isEmpty() ? tl::nullopt
138 stream << QString(
"ElementName('%1')").arg(*obj);
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 =
uint Hash
Return type of Qt's qHash() function.
Definition: qtcompat.h:58
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
static QString cleanElementName(const QString &userInput) noexcept
Definition: elementname.h:147
bool operator==(const AttributeKey &lhs, const QString &rhs) noexcept
Definition: attributekey.h:86
QtCompat::Hash qHash(const AttributeKey &key, QtCompat::Hash seed=0) noexcept
Definition: attributekey.h:119
std::unique_ptr< SExpression > serialize(const AttributeKey &obj)
Definition: attributekey.h:100
bool operator!=(const AttributeKey &lhs, const QString &rhs) noexcept
Definition: attributekey.h:92
QtCompat::Hash qHash(const ElementName &key, QtCompat::Hash seed=0) noexcept
Definition: elementname.h:142
static ElementName elementNameFromTr(const char *context, const char *textNoTr) noexcept
Definition: elementname.h:158
AttributeKey deserialize(const SExpression &node)
Definition: attributekey.h:105
QDataStream & operator<<(QDataStream &stream, const AttributeKey &obj)
Definition: attributekey.h:109
QString operator%(const ComponentPrefix &lhs, const QString &rhs) noexcept
Definition: componentprefix.h:103
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