TreeFrogFramework 2.10
Loading...
Searching...
No Matches
thttputility.h
Go to the documentation of this file.
1#pragma once
2#include <QByteArray>
3#include <QDateTime>
4#include <QPair>
5#include <QStringList>
6#include <QVariant>
7#include <TGlobal>
8
9
11public:
12 static QString fromUrlEncoding(const QByteArray &enc);
13 static QByteArray toUrlEncoding(const QString &input, const QByteArray &exclude = "-._");
14 static QList<QPair<QString, QString>> fromFormUrlEncoded(const QByteArray &enc);
15 static QString htmlEscape(const QString &input, Tf::EscapeFlag flag = Tf::Quotes);
16 static QString htmlEscape(int n);
17 static QString htmlEscape(uint n);
18 static QString htmlEscape(long n);
19 static QString htmlEscape(ulong n);
20 static QString htmlEscape(qlonglong n);
21 static QString htmlEscape(qulonglong n);
22 static QString htmlEscape(double n);
23 static QString htmlEscape(const char *input, Tf::EscapeFlag flag = Tf::Quotes);
24 static QString htmlEscape(const QByteArray &input, Tf::EscapeFlag flag = Tf::Quotes);
25 static QString htmlEscape(const QVariant &input, Tf::EscapeFlag flag = Tf::Quotes);
26 static QString jsonEscape(const QString &input);
27 static QString jsonEscape(const char *input);
28 static QString jsonEscape(const QByteArray &input);
29 static QString jsonEscape(const QVariant &input);
30 static QByteArray toMimeEncoded(const QString &input, const QByteArray &encoding = "UTF-8");
31 static QByteArray toMimeEncoded(const QString &input, QStringConverter::Encoding encoding);
32 static QString fromMimeEncoded(const QByteArray &mime);
33 static QByteArray getResponseReasonPhrase(int statusCode);
34 static QString trimmedQuotes(const QString &string);
35 static QByteArray timeZone();
36 static QByteArray toHttpDateTimeString(const QDateTime &dateTime);
37 static QDateTime fromHttpDateTimeString(const QByteArray &localTime);
38 //static QByteArray toHttpDateTimeUTCString(const QDateTime &utc);
39 static QDateTime fromHttpDateTimeUTCString(const QByteArray &utc);
40 static QByteArray getUTCTimeString();
41
42private:
46};
47
48
52inline QString THttpUtility::htmlEscape(int n)
53{
54 return QString::number(n);
55}
56
60inline QString THttpUtility::htmlEscape(uint n)
61{
62 return QString::number(n);
63}
64
68inline QString THttpUtility::htmlEscape(long n)
69{
70 return QString::number(n);
71}
72
76inline QString THttpUtility::htmlEscape(ulong n)
77{
78 return QString::number(n);
79}
80
84inline QString THttpUtility::htmlEscape(qlonglong n)
85{
86 return QString::number(n);
87}
88
92inline QString THttpUtility::htmlEscape(qulonglong n)
93{
94 return QString::number(n);
95}
96
100inline QString THttpUtility::htmlEscape(double n)
101{
102 return QString::number(n);
103}
104
109inline QString THttpUtility::trimmedQuotes(const QString &string)
110{
111 QString s = string.trimmed();
112 if (s.length() > 1) {
113 if ((s.startsWith('"') && s.endsWith('"'))
114 || (s.startsWith('\'') && s.endsWith('\''))) {
115 return s.mid(1, s.length() - 2);
116 }
117 }
118 return s;
119}
120
The THttpUtility class contains utility functions.
Definition thttputility.h:10
static QString trimmedQuotes(const QString &string)
Returns a string that has quotes removed from the start and the end.
Definition thttputility.h:109
static QString htmlEscape(const QString &input, Tf::EscapeFlag flag=Tf::Quotes)
Returns a converted copy of input.
Definition thttputility.cpp:129
EscapeFlag
Definition tfnamespace.h:127
@ Quotes
Definition tfnamespace.h:129
#define T_CORE_EXPORT
Definition tdeclexport.h:28
#define T_DISABLE_COPY(Class)
Definition tdeclexport.h:37
#define T_DISABLE_MOVE(Class)
Definition tdeclexport.h:41