TreeFrogFramework  1.18
thttputility.h
Go to the documentation of this file.
1 #ifndef THTTPUTILITY_H
2 #define THTTPUTILITY_H
3 
4 #include <QByteArray>
5 #include <QStringList>
6 #include <QDateTime>
7 #include <QVariant>
8 #include <TGlobal>
9 
10 class QTextCodec;
11 
12 
14 {
15 public:
16  static QString fromUrlEncoding(const QByteArray &enc);
17  static QByteArray toUrlEncoding(const QString &input, const QByteArray &exclude = "-._");
18  static QString htmlEscape(const QString &input, Tf::EscapeFlag flag = Tf::Quotes);
19  static QString htmlEscape(int n);
20  static QString htmlEscape(long n);
21  static QString htmlEscape(ulong n);
22  static QString htmlEscape(qlonglong n);
23  static QString htmlEscape(qulonglong n);
24  static QString htmlEscape(double n);
25  static QString htmlEscape(const char *input, Tf::EscapeFlag flag = Tf::Quotes);
26  static QString htmlEscape(const QByteArray &input, Tf::EscapeFlag flag = Tf::Quotes);
27  static QString htmlEscape(const QVariant &input, Tf::EscapeFlag flag = Tf::Quotes);
28  static QString jsonEscape(const QString &input);
29  static QString jsonEscape(const char *input);
30  static QString jsonEscape(const QByteArray &input);
31  static QString jsonEscape(const QVariant &input);
32  static QByteArray toMimeEncoded(const QString &input, const QByteArray &encoding = "UTF-8");
33  static QByteArray toMimeEncoded(const QString &input, QTextCodec *codec);
34  static QString fromMimeEncoded(const QByteArray &mime);
35  static QByteArray getResponseReasonPhrase(int statusCode);
36  static QString trimmedQuotes(const QString &string);
37  static QByteArray timeZone();
38  static QByteArray toHttpDateTimeString(const QDateTime &dateTime);
39  static QDateTime fromHttpDateTimeString(const QByteArray &localTime);
40  //static QByteArray toHttpDateTimeUTCString(const QDateTime &utc);
41  static QDateTime fromHttpDateTimeUTCString(const QByteArray &utc);
42  static QByteArray getUTCTimeString();
43 
44 private:
45  THttpUtility();
48 };
49 
50 
54 inline QString THttpUtility::htmlEscape(int n)
55 {
56  return QString::number(n);
57 }
58 
62 inline QString THttpUtility::htmlEscape(long n)
63 {
64  return QString::number(n);
65 }
66 
70 inline QString THttpUtility::htmlEscape(ulong n)
71 {
72  return QString::number(n);
73 }
74 
78 inline QString THttpUtility::htmlEscape(qlonglong n)
79 {
80  return QString::number(n);
81 }
82 
86 inline QString THttpUtility::htmlEscape(qulonglong n)
87 {
88  return QString::number(n);
89 }
90 
94 inline QString THttpUtility::htmlEscape(double n)
95 {
96  return QString::number(n);
97 }
98 
103 inline QString THttpUtility::trimmedQuotes(const QString &string)
104 {
105  QString s = string.trimmed();
106  if (s.length() > 1) {
107  if ((s.startsWith('"') && s.endsWith('"'))
108  || (s.startsWith('\'') && s.endsWith('\''))) {
109  return s.mid(1, s.length() - 2);
110  }
111  }
112  return s;
113 }
114 
115 #endif // THTTPUTILITY_H
#define T_CORE_EXPORT
Definition: tglobal.h:81
The THttpUtility class contains utility functions.
Definition: thttputility.h:13
#define T_DISABLE_COPY(Class)
Definition: tglobal.h:137
#define T_DISABLE_MOVE(Class)
Definition: tglobal.h:141
EscapeFlag
Definition: tfnamespace.h:129
Definition: tfnamespace.h:131
static QString htmlEscape(const QString &input, Tf::EscapeFlag flag=Tf::Quotes)
Returns a converted copy of input.
Definition: thttputility.cpp:116
static QString trimmedQuotes(const QString &string)
Returns a string that has quotes removed from the start and the end.
Definition: thttputility.h:103