12#include "metaenumvariable_p.h"
13#include "safestring.h"
15#include <QRegularExpression>
22static QRegularExpression getIsTitleRE()
28static QRegularExpression getTitleRE()
35QVariant TypeAccessor<KTextTemplate::SafeString &>::lookUp(
const KTextTemplate::SafeString &
object,
const QString &property)
37 if (property == QStringLiteral(
"capitalize")) {
38 const QString &s =
object.get();
42 static const QLatin1String falseString(
"False");
43 static const QLatin1String trueString(
"True");
45 if (property == QStringLiteral(
"isalnum")) {
46 const QString &s =
object.get();
49 if (!it->isLetterOrNumber())
55 if (property == QStringLiteral(
"isalpha")) {
56 const QString &s =
object.get();
67 if (property == QStringLiteral(
"isdigit")) {
68 const QString &s =
object.get();
77 if (property == QStringLiteral(
"islower")) {
78 const QString s =
object.get().
toLower();
79 return (s ==
object.
get()) ? trueString : falseString;
81 if (property == QStringLiteral(
"isspace")) {
82 const QString s =
object.get().
trimmed();
83 return (s.
isEmpty()) ? trueString : falseString;
85 if (property == QStringLiteral(
"istitle")) {
86 const QString &s =
object.get();
88 static const auto titleRe = getIsTitleRE();
89 return (titleRe.match(s).hasMatch()) ? falseString : trueString;
91 if (property == QStringLiteral(
"isupper")) {
92 const QString s =
object.get().
toUpper();
93 return (s ==
object) ? trueString : falseString;
95 if (property == QStringLiteral(
"lower")) {
96 return object.get().toLower();
98 if (property == QStringLiteral(
"splitlines")) {
99 const auto strings =
object.get().split(QLatin1Char(
'\n'));
102 const auto end = strings.constEnd();
103 for (; it !=
end; ++it)
107 if (property == QStringLiteral(
"strip")) {
108 return object.get().trimmed();
110 if (property == QStringLiteral(
"swapcase")) {
111 const QString &inputString =
object.get();
115 while (it != inputString.
constEnd()) {
118 else if (it->isLower())
126 if (property == QStringLiteral(
"title")) {
127 static const auto titleRe = getTitleRE();
129 const QString &s =
object.get();
136 auto it = titleRe.globalMatch(s);
137 while (it.hasNext()) {
138 auto match = it.next();
139 pos =
match.capturedStart();
140 output +=
match.captured().toUpper();
141 matchedLength =
match.capturedLength();
143 match = it.peekNext();
144 nextPos =
match.capturedStart();
145 output += s.
mid(pos + matchedLength, nextPos - pos - 1);
147 output += s.
right(s.
length() - (pos + matchedLength));
153 if (property == QStringLiteral(
"upper")) {
154 return object.get().toUpper();
160QVariant TypeAccessor<MetaEnumVariable &>::lookUp(
const MetaEnumVariable &
object,
const QString &property)
162 if (property == QStringLiteral(
"name"))
163 return QLatin1String(
object.enumerator.name());
164 if (property == QStringLiteral(
"value"))
166 if (property == QStringLiteral(
"key"))
167 return QLatin1String(
object.enumerator.valueToKey(
object.value));
168 if (property == QStringLiteral(
"scope"))
169 return QLatin1String(
object.enumerator.scope());
170 if (property == QStringLiteral(
"keyCount"))
171 return object.enumerator.keyCount();
174 const auto listIndex =
property.toInt(&ok);
176 if (listIndex >=
object.enumerator.keyCount())
179 const MetaEnumVariable mev(
object.enumerator,
object.enumerator.value(listIndex));
KCOREADDONS_EXPORT Result match(QStringView pattern, QStringView str)
KIOCORE_EXPORT TransferJob * get(const QUrl &url, LoadType reload=NoReload, JobFlags flags=DefaultFlags)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
const QList< QKeySequence > & end()
The KTextTemplate namespace holds all public KTextTemplate API.
char32_t toUpper(char32_t ucs4)
const_iterator constBegin() const const
const QChar at(qsizetype position) const const
const_iterator constBegin() const const
const_iterator constEnd() const const
bool isEmpty() const const
qsizetype length() const const
QString mid(qsizetype position, qsizetype n) const const
void reserve(qsizetype size)
QString right(qsizetype n) const const
qsizetype size() const const
QString toLower() const const
QString toUpper() const const
QString trimmed() const const
QVariant fromValue(T &&value)