KTextTemplate

util.h
Go to the documentation of this file.
1/*
2 This file is part of the KTextTemplate library
3
4 SPDX-FileCopyrightText: 2009, 2010 Stephen Kelly <steveire@gmail.com>
5
6 SPDX-License-Identifier: LGPL-2.1-or-later
7
8*/
9
10#ifndef KTEXTTEMPLATE_UTIL_P_H
11#define KTEXTTEMPLATE_UTIL_P_H
12
13#include "context.h"
14#include "ktexttemplate_export.h"
15#include "safestring.h"
16
17#include <QVariant>
18
19/// @file util.h Utility functions used throughout %KTextTemplate.
20/// @headerfile util.h <KTextTemplate/Util>
21
22namespace KTextTemplate
23{
24
25/**
26 Returns whether the @p variant is evaluated to true.
27
28 @see @ref truthiness
29*/
30KTEXTTEMPLATE_EXPORT bool variantIsTrue(const QVariant &variant);
31
32/**
33 Converts the @p input into its unescaped form.
34
35 Double slashes are converted to single slashes, \\&quot is converted to &quot
36 etc.
37*/
38KTEXTTEMPLATE_EXPORT QString unescapeStringLiteral(const QString &input);
39
40/**
41 Marks the @p input as safe.
42*/
43KTEXTTEMPLATE_EXPORT KTextTemplate::SafeString markSafe(const KTextTemplate::SafeString &input);
44
45/**
46 Marks the @p input as requiring escaping.
47*/
49
50/**
51 Retrieves and returns a SafeString from the @p input.
52*/
53KTEXTTEMPLATE_EXPORT KTextTemplate::SafeString getSafeString(const QVariant &input);
54
55/**
56 Returns whether @p input contains a SafeString.
57*/
58KTEXTTEMPLATE_EXPORT bool isSafeString(const QVariant &input);
59
60/**
61 Returns true if the type of @p input can be inserted into a rendered template
62 directly.
63
64 Note that lists, hashes and QObject*s can not be.
65*/
66KTEXTTEMPLATE_EXPORT bool supportedOutputType(const QVariant &input);
67
68/**
69 Compares @p lhs and @p rhs for equality. SafeStrings are compared as raw
70 QStrings. Their safeness is not part of the comparison.
71
72 @see QVariant::operator==
73*/
74KTEXTTEMPLATE_EXPORT bool equals(const QVariant &lhs, const QVariant &rhs);
75
76/**
77 Converts @p size into the nearest file size unit like MB or MiB, based on the
78 @p unitSystem value. Use @c 2 for the @p unitSystem to get binary units, use
79 @c 10 to get decimal units - by default, decimal units will be returned. The
80 @p multiplier can be used if the input @p size is not in pure bytes. If @p
81 size is for example given in @a KiB, use a multiplier of @a 1024. The returned
82 pair will have the converted size as @a first and the unit as @a second.
83*/
84KTEXTTEMPLATE_EXPORT std::pair<qreal, QString> calcFileSize(qreal size, int unitSystem = 10, qreal multiplier = 1.0);
85
86#ifndef K_DOXYGEN
87/**
88 @internal
89 Returns the @p list as a formatted string. This is for debugging purposes
90 only.
91*/
92KTEXTTEMPLATE_EXPORT KTextTemplate::SafeString toString(const QVariantList &list);
93#endif
94}
95
96#endif
A QString wrapper class for containing whether a string is safe or needs to be escaped.
Definition safestring.h:81
char * toString(const EngineQuery &query)
The KTextTemplate namespace holds all public KTextTemplate API.
Definition Mainpage.dox:8
std::pair< qreal, QString > calcFileSize(qreal size, int unitSystem=10, qreal multiplier=1.0)
Converts size into the nearest file size unit like MB or MiB, based on the unitSystem value.
Definition util.cpp:150
KTextTemplate::SafeString markForEscaping(const KTextTemplate::SafeString &input)
Marks the input as requiring escaping.
Definition util.cpp:81
KTextTemplate::SafeString getSafeString(const QVariant &input)
Retrieves and returns a SafeString from the input.
Definition util.cpp:91
bool isSafeString(const QVariant &input)
Returns whether input contains a SafeString.
Definition util.cpp:99
bool variantIsTrue(const QVariant &variant)
Returns whether the variant is evaluated to true.
Definition util.cpp:24
QString unescapeStringLiteral(const QString &input)
Converts the input into its unescaped form.
Definition util.cpp:16
KTextTemplate::SafeString markSafe(const KTextTemplate::SafeString &input)
Marks the input as safe.
Definition util.cpp:74
bool equals(const QVariant &lhs, const QVariant &rhs)
Compares lhs and rhs for equality.
Definition util.cpp:119
bool supportedOutputType(const QVariant &input)
Returns true if the type of input can be inserted into a rendered template directly.
Definition util.cpp:113
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Apr 27 2024 22:14:09 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.