23#include "metaenumvariable_p.h"
24#include "safestring.h"
26#include <QtCore/QRegularExpression>
27#include <QtCore/QStringList>
28#include <QtCore/QVariant>
33static QRegularExpression getIsTitleRE()
35 QRegularExpression titleRe(QStringLiteral(
"\\b[a-z]"),
40static QRegularExpression getTitleRE()
42 QRegularExpression titleRe(QStringLiteral(
"\\b(.)"),
49TypeAccessor<Cutelee::SafeString &>::lookUp(
const Cutelee::SafeString &
object,
50 const QString &property)
52 if (property == QStringLiteral(
"capitalize")) {
53 const QString s =
object.get();
57 static const QLatin1String falseString(
"False");
58 static const QLatin1String trueString(
"True");
60 if (property == QStringLiteral(
"isalnum")) {
61 const QString s =
object.get();
64 if (!it->isLetterOrNumber())
70 if (property == QStringLiteral(
"isalpha")) {
71 const QString s =
object.get();
82 if (property == QStringLiteral(
"isdigit")) {
83 const QString s =
object.get();
92 if (property == QStringLiteral(
"islower")) {
93 const QString s =
object.get().
toLower();
94 return (s ==
object.get()) ? trueString : falseString;
96 if (property == QStringLiteral(
"isspace")) {
97 const QString s =
object.get().
trimmed();
98 return (s.
isEmpty()) ? trueString : falseString;
100 if (property == QStringLiteral(
"istitle")) {
101 const QString s =
object.get();
103 static const auto titleRe = getIsTitleRE();
104 return (titleRe.match(s).hasMatch()) ? falseString : trueString;
106 if (property == QStringLiteral(
"isupper")) {
107 const QString s =
object.get().
toUpper();
108 return (s ==
object) ? trueString : falseString;
110 if (property == QStringLiteral(
"lower")) {
111 return object.get().toLower();
113 if (property == QStringLiteral(
"splitlines")) {
114 const auto strings =
object.get().split(QLatin1Char(
'\n'));
116 auto it = strings.constBegin();
117 const auto end = strings.constEnd();
118 for (; it != end; ++it)
122 if (property == QStringLiteral(
"strip")) {
123 return object.get().trimmed();
125 if (property == QStringLiteral(
"swapcase")) {
126 const QString inputString =
object.get();
130 while (it != inputString.
constEnd()) {
133 else if (it->isLower())
141 if (property == QStringLiteral(
"title")) {
142 static const auto titleRe = getTitleRE();
144 const QString s =
object.get();
151 auto it = titleRe.globalMatch(s);
152 while (it.hasNext()) {
153 auto match = it.next();
154 pos = match.capturedStart();
155 output += match.captured().
toUpper();
156 matchedLength = match.capturedLength();
158 match = it.peekNext();
159 nextPos = match.capturedStart();
160 output += s.
mid(pos + matchedLength, nextPos - pos - 1);
162 output += s.
right(s.
length() - (pos + matchedLength));
168 if (property == QStringLiteral(
"upper")) {
169 return object.get().toUpper();
176TypeAccessor<MetaEnumVariable &>::lookUp(
const MetaEnumVariable &
object,
177 const QString &property)
179 if (property == QStringLiteral(
"name"))
180 return QLatin1String(
object.enumerator.name());
181 if (property == QStringLiteral(
"value"))
183 if (property == QStringLiteral(
"key"))
184 return QLatin1String(
object.enumerator.valueToKey(
object.value));
185 if (property == QStringLiteral(
"scope"))
186 return QLatin1String(
object.enumerator.scope());
187 if (property == QStringLiteral(
"keyCount"))
188 return object.enumerator.keyCount();
191 const auto listIndex =
property.toInt(&ok);
193 if (listIndex >=
object.enumerator.keyCount())
196 const MetaEnumVariable mev(
object.enumerator,
197 object.enumerator.value(listIndex));
The Cutelee namespace holds all public Cutelee API.
QChar toUpper() const const
const QChar at(int position) const const
const_iterator constBegin() const const
const_iterator constEnd() const const
bool isEmpty() const const
QString mid(int position, int n) const const
QString right(int n) const const
QString toLower() const const
QString toUpper() const const
QString trimmed() const const
QVariant fromValue(const T &value)