TreeFrogFramework  2.8
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 #if QT_VERSION < 0x060000
10 class QTextCodec;
11 #endif
12 
14 public:
15  static QString fromUrlEncoding(const QByteArray &enc);
16  static QByteArray toUrlEncoding(const QString &input, const QByteArray &exclude = "-._");
17  static QList<QPair<QString, QString>> fromFormUrlEncoded(const QByteArray &enc);
18  static QString htmlEscape(const QString &input, Tf::EscapeFlag flag = Tf::Quotes);
19  static QString htmlEscape(int n);
20  static QString htmlEscape(uint n);
21  static QString htmlEscape(long n);
22  static QString htmlEscape(ulong n);
23  static QString htmlEscape(qlonglong n);
24  static QString htmlEscape(qulonglong n);
25  static QString htmlEscape(double n);
26  static QString htmlEscape(const char *input, Tf::EscapeFlag flag = Tf::Quotes);
27  static QString htmlEscape(const QByteArray &input, Tf::EscapeFlag flag = Tf::Quotes);
28  static QString htmlEscape(const QVariant &input, Tf::EscapeFlag flag = Tf::Quotes);
29  static QString jsonEscape(const QString &input);
30  static QString jsonEscape(const char *input);
31  static QString jsonEscape(const QByteArray &input);
32  static QString jsonEscape(const QVariant &input);
33  static QByteArray toMimeEncoded(const QString &input, const QByteArray &encoding = "UTF-8");
34 #if QT_VERSION < 0x060000
35  static QByteArray toMimeEncoded(const QString &input, QTextCodec *codec);
36 #else
37  static QByteArray toMimeEncoded(const QString &input, QStringConverter::Encoding encoding);
38 #endif
39  static QString fromMimeEncoded(const QByteArray &mime);
40  static QByteArray getResponseReasonPhrase(int statusCode);
41  static QString trimmedQuotes(const QString &string);
42  static QByteArray timeZone();
43  static QByteArray toHttpDateTimeString(const QDateTime &dateTime);
44  static QDateTime fromHttpDateTimeString(const QByteArray &localTime);
45  //static QByteArray toHttpDateTimeUTCString(const QDateTime &utc);
46  static QDateTime fromHttpDateTimeUTCString(const QByteArray &utc);
47  static QByteArray getUTCTimeString();
48 
49 private:
50  THttpUtility();
53 };
54 
55 
59 inline QString THttpUtility::htmlEscape(int n)
60 {
61  return QString::number(n);
62 }
63 
67 inline QString THttpUtility::htmlEscape(uint n)
68 {
69  return QString::number(n);
70 }
71 
75 inline QString THttpUtility::htmlEscape(long n)
76 {
77  return QString::number(n);
78 }
79 
83 inline QString THttpUtility::htmlEscape(ulong n)
84 {
85  return QString::number(n);
86 }
87 
91 inline QString THttpUtility::htmlEscape(qlonglong n)
92 {
93  return QString::number(n);
94 }
95 
99 inline QString THttpUtility::htmlEscape(qulonglong n)
100 {
101  return QString::number(n);
102 }
103 
107 inline QString THttpUtility::htmlEscape(double n)
108 {
109  return QString::number(n);
110 }
111 
116 inline QString THttpUtility::trimmedQuotes(const QString &string)
117 {
118  QString s = string.trimmed();
119  if (s.length() > 1) {
120  if ((s.startsWith('"') && s.endsWith('"'))
121  || (s.startsWith('\'') && s.endsWith('\''))) {
122  return s.mid(1, s.length() - 2);
123  }
124  }
125  return s;
126 }
127 
The THttpUtility class contains utility functions.
Definition: thttputility.h:13
static QString trimmedQuotes(const QString &string)
Returns a string that has quotes removed from the start and the end.
Definition: thttputility.h:116
static QString htmlEscape(const QString &input, Tf::EscapeFlag flag=Tf::Quotes)
Returns a converted copy of input.
Definition: thttputility.cpp:140
@ Encoding
Definition: tfnamespace.h:86
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