KDECore
kencodingdetector.h
Go to the documentation of this file.
00001 /* 00002 This file is part of the KDE libraries 00003 00004 Copyright (C) 1999 Lars Knoll (knoll@mpi-hd.mpg.de) 00005 Copyright (C) 2007 Nick Shaforostoff (shafff@ukr.net) 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Library General Public 00009 License as published by the Free Software Foundation; either 00010 version 2 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Library General Public License for more details. 00016 00017 You should have received a copy of the GNU Library General Public License 00018 along with this library; see the file COPYING.LIB. If not, write to 00019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00020 Boston, MA 02110-1301, USA. 00021 00022 */ 00023 #ifndef KENCODINGDETECTOR_H 00024 #define KENCODINGDETECTOR_H 00025 00026 #include <kdecore_export.h> 00027 #include <QtCore/QString> 00028 00029 class QTextCodec; 00030 class QTextDecoder; 00031 class KEncodingDetectorPrivate; 00032 00058 class KDECORE_EXPORT KEncodingDetector 00059 { 00060 public: 00061 enum EncodingChoiceSource 00062 { 00063 DefaultEncoding, 00064 AutoDetectedEncoding, 00065 BOM, 00066 EncodingFromXMLHeader, 00067 EncodingFromMetaTag, 00068 EncodingFromHTTPHeader, 00069 UserChosenEncoding 00070 }; 00071 00072 enum AutoDetectScript 00073 { 00074 None, 00075 SemiautomaticDetection, 00076 Arabic, 00077 Baltic, 00078 CentralEuropean, 00079 ChineseSimplified, 00080 ChineseTraditional, 00081 Cyrillic, 00082 Greek, 00083 Hebrew, 00084 Japanese, 00085 Korean, 00086 NorthernSaami, 00087 SouthEasternEurope, 00088 Thai, 00089 Turkish, 00090 Unicode, 00091 WesternEuropean 00092 }; 00093 00097 KEncodingDetector(); 00098 00102 KEncodingDetector(QTextCodec* codec, EncodingChoiceSource source, AutoDetectScript script=None); 00103 ~KEncodingDetector(); 00104 00105 //const QTextCodec* codec() const; 00106 00110 bool setEncoding(const char *encoding, EncodingChoiceSource type); 00111 00116 const char* encoding() const; 00117 00118 bool visuallyOrdered() const; 00119 00120 // void setAutoDetectLanguage( const QString& ); 00121 // const QString& autoDetectLanguage() const; 00122 00123 void setAutoDetectLanguage( AutoDetectScript ); 00124 AutoDetectScript autoDetectLanguage() const; 00125 00126 EncodingChoiceSource encodingChoiceSource() const; 00127 00135 QString decode(const char *data, int len); 00136 QString decode(const QByteArray &data); 00137 00138 //* You don't need to call analyze() if you use this method. 00148 QString decodeWithBuffering(const char *data, int len); 00149 00162 bool decodedInvalidCharacters() const; 00163 00173 void resetDecoder(); 00174 00179 QString flush(); 00180 00184 static AutoDetectScript scriptForName(const QString& lang); 00185 static QString nameForScript(AutoDetectScript); 00186 static bool hasAutoDetectionForScript(AutoDetectScript); 00187 00188 protected: 00193 bool processNull(char* data,int length); 00194 00202 bool errorsIfUtf8 (const char* data, int length); 00203 00208 bool analyze (const char *data, int len); 00209 00213 QTextDecoder* decoder(); 00214 00215 private: 00216 KEncodingDetectorPrivate* const d; 00217 }; 00218 00219 #endif
KDE 4.6 API Reference