00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
#ifndef __KMIME_UTIL_H__
00017
#define __KMIME_UTIL_H__
00018
00019
#include "qdatetime.h"
00020
#include "qstring.h"
00021
#include "qcstring.h"
00022
#include "qvaluelist.h"
00023
#include "time.h"
00024
00025
typedef QValueList<QCString> QCStringList;
00026
00027
namespace KMime {
00028
00031
extern const char* cachedCharset(
const QCString &name);
00032
00035
extern const char* cachedLanguage(
const QCString &name);
00036
00038
extern bool isUsAscii(
const QString &s);
00039
00040
inline bool isOfSet(
const uchar map[16],
unsigned char ch) {
00041 Q_ASSERT( ch < 128 );
00042
return ( map[ ch/8 ] & 0x80 >> ch%8 );
00043 }
00044
00045
extern const uchar specialsMap[16];
00046
extern const uchar tSpecialsMap[16];
00047
extern const uchar aTextMap[16];
00048
extern const uchar tTextMap[16];
00049
extern const uchar eTextMap[16];
00050
00051
inline bool isSpecial(
char ch) {
00052
return isOfSet( specialsMap, ch );
00053 }
00054
inline bool isTSpecial(
char ch) {
00055
return isOfSet( tSpecialsMap, ch );
00056 }
00057
inline bool isAText(
char ch) {
00058
return isOfSet( aTextMap, ch );
00059 }
00060
inline bool isTText(
char ch) {
00061
return isOfSet( tTextMap, ch );
00062 }
00063
inline bool isEText(
char ch) {
00064
return isOfSet( eTextMap, ch );
00065 }
00066
00076
extern QString decodeRFC2047String(
const QCString &src,
const char **usedCS,
00077
const QCString &defaultCS,
bool forceCS);
00078
00089
extern QCString encodeRFC2047String(
const QString &src,
const char *charset,
00090
bool addressHeader=
false,
bool allow8bitHeaders=
false);
00091
00098
extern QCString uniqueString();
00099
00106
extern QCString multiPartBoundary();
00107
00115
extern QCString extractHeader(
const QCString &src,
const char *name);
00125
extern QCString CRLFtoLF(
const QCString &s);
00135
extern QCString CRLFtoLF(
const char *s);
00147
extern QCString LFtoCRLF(
const QCString &s);
00148
00154
extern void removeQuots(
QCString &str);
00160
extern void removeQuots(
QString &str);
00167
extern void addQuotes(
QCString &str,
bool forceQuotes);
00168
00169
00186 class DateFormatter {
00187
public:
00188
enum FormatType {
00189 CTime,
00190 Localized,
00191 Fancy,
00192 Iso,
00193 Custom
00194 };
00195
00200
DateFormatter(FormatType fType = DateFormatter::Fancy);
00201
00202 ~
DateFormatter();
00203
00207 FormatType
getFormat()
const;
00211
void setFormat(FormatType t);
00212
00221
QString dateString(time_t otime,
const QString& lang = QString::null,
00222
bool shortFormat =
true,
bool includeSecs=
false)
const;
00226
QString dateString(
const QDateTime& dtime,
const QString& lang = QString::null,
00227
bool shortFormat =
true,
bool includeSecs=
false)
const;
00228
00229
00239
void setCustomFormat(
const QString& format);
00240
QString getCustomFormat()
const;
00241
00246
QCString rfc2822(time_t otime)
const;
00250
void reset();
00251
00252
00261
static QString formatDate( DateFormatter::FormatType t, time_t time,
00262
const QString& data = QString::null,
00263
bool shortFormat =
true,
bool includeSecs=
false);
00264
00273
static QString formatCurrentDate( DateFormatter::FormatType t,
00274
const QString& data = QString::null,
00275
bool shortFormat =
true,
bool includeSecs=
false);
00276
00278
static QCString rfc2822FormatDate( time_t time );
00279
static bool isDaylight();
00280
protected:
00286
QString fancy(time_t otime)
const ;
00295
QString localized(time_t otime,
bool shortFormat =
true,
bool includeSecs =
false,
00296
const QString& localeLanguage=QString::null )
const;
00301
QString cTime(time_t otime)
const;
00306
QString isoDate(time_t otime)
const;
00307
00314
QString custom(time_t t)
const;
00319
QCString zone(time_t otime)
const;
00320
00321 time_t qdateToTimeT(
const QDateTime& dt)
const;
00322
private:
00323 FormatType mFormat;
00324
mutable time_t mCurrentTime;
00325
mutable QDateTime mDate;
00326
QString mCustomFormat;
00327
static int mDaylight;
00328 };
00329
00330 }
00331
00332
#endif