File indexing completed on 2025-02-09 04:28:41
0001 /* 0002 This file is part of the KTextTemplate library 0003 0004 SPDX-FileCopyrightText: 2009, 2010 Stephen Kelly <steveire@gmail.com> 0005 0006 SPDX-License-Identifier: LGPL-2.1-or-later 0007 0008 */ 0009 0010 #ifndef KTEXTTEMPLATE_UTIL_P_H 0011 #define KTEXTTEMPLATE_UTIL_P_H 0012 0013 #include "context.h" 0014 #include "ktexttemplate_export.h" 0015 #include "safestring.h" 0016 0017 #include <QVariant> 0018 0019 /// @file util.h Utility functions used throughout %KTextTemplate. 0020 /// @headerfile util.h <KTextTemplate/Util> 0021 0022 namespace KTextTemplate 0023 { 0024 0025 /** 0026 Returns whether the @p variant is evaluated to true. 0027 0028 @see @ref truthiness 0029 */ 0030 KTEXTTEMPLATE_EXPORT bool variantIsTrue(const QVariant &variant); 0031 0032 /** 0033 Converts the @p input into its unescaped form. 0034 0035 Double slashes are converted to single slashes, \\" is converted to " 0036 etc. 0037 */ 0038 KTEXTTEMPLATE_EXPORT QString unescapeStringLiteral(const QString &input); 0039 0040 /** 0041 Marks the @p input as safe. 0042 */ 0043 KTEXTTEMPLATE_EXPORT KTextTemplate::SafeString markSafe(const KTextTemplate::SafeString &input); 0044 0045 /** 0046 Marks the @p input as requiring escaping. 0047 */ 0048 KTEXTTEMPLATE_EXPORT KTextTemplate::SafeString markForEscaping(const KTextTemplate::SafeString &input); 0049 0050 /** 0051 Retrieves and returns a SafeString from the @p input. 0052 */ 0053 KTEXTTEMPLATE_EXPORT KTextTemplate::SafeString getSafeString(const QVariant &input); 0054 0055 /** 0056 Returns whether @p input contains a SafeString. 0057 */ 0058 KTEXTTEMPLATE_EXPORT bool isSafeString(const QVariant &input); 0059 0060 /** 0061 Returns true if the type of @p input can be inserted into a rendered template 0062 directly. 0063 0064 Note that lists, hashes and QObject*s can not be. 0065 */ 0066 KTEXTTEMPLATE_EXPORT bool supportedOutputType(const QVariant &input); 0067 0068 /** 0069 Compares @p lhs and @p rhs for equality. SafeStrings are compared as raw 0070 QStrings. Their safeness is not part of the comparison. 0071 0072 @see QVariant::operator== 0073 */ 0074 KTEXTTEMPLATE_EXPORT bool equals(const QVariant &lhs, const QVariant &rhs); 0075 0076 /** 0077 Converts @p size into the nearest file size unit like MB or MiB, based on the 0078 @p unitSystem value. Use @c 2 for the @p unitSystem to get binary units, use 0079 @c 10 to get decimal units - by default, decimal units will be returned. The 0080 @p multiplier can be used if the input @p size is not in pure bytes. If @p 0081 size is for example given in @a KiB, use a multiplier of @a 1024. The returned 0082 pair will have the converted size as @a first and the unit as @a second. 0083 */ 0084 KTEXTTEMPLATE_EXPORT std::pair<qreal, QString> calcFileSize(qreal size, int unitSystem = 10, qreal multiplier = 1.0); 0085 0086 #ifndef K_DOXYGEN 0087 /** 0088 @internal 0089 Returns the @p list as a formatted string. This is for debugging purposes 0090 only. 0091 */ 0092 KTEXTTEMPLATE_EXPORT KTextTemplate::SafeString toString(const QVariantList &list); 0093 #endif 0094 } 0095 0096 #endif