2 This file is part of the KDE libraries
4 Copyright (C) 1999 Lars Knoll (knoll@mpi-hd.mpg.de)
5 Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com)
6 Copyright (C) 2006 Apple Computer, Inc.
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version.
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details.
18 You should have received a copy of the GNU Library General Public License
19 along with this library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA.
28 #include "PlatformString.h"
30 #include "TextDecoder.h"
31 #include <wtf/Vector.h>
35 class Decoder : public Shared<Decoder> {
40 EncodingFromXMLHeader,
42 EncodingFromCSSCharset,
43 EncodingFromHTTPHeader,
47 Decoder(const String& mimeType, const TextEncoding& defaultEncoding = TextEncoding());
50 void setEncoding(const TextEncoding&, EncodingSource);
51 const TextEncoding& encoding() const { return m_decoder.encoding(); }
53 String decode(const char* data, size_t length);
57 enum ContentType { PlainText, HTML, XML, CSS }; // PlainText is equivalent to directly using TextDecoder.
58 static ContentType determineContentType(const String& mimeType);
59 static const TextEncoding& defaultEncoding(ContentType, const TextEncoding& defaultEncoding);
61 void checkForBOM(const char*, size_t);
62 bool checkForCSSCharset(const char*, size_t, bool& movedDataToBuffer);
63 bool checkForHeadCharset(const char*, size_t, bool& movedDataToBuffer);
64 void detectJapaneseEncoding(const char*, size_t);
66 ContentType m_contentType;
67 TextDecoder m_decoder;
68 EncodingSource m_source;
69 Vector<char> m_buffer;
71 bool m_checkedForCSSCharset;
72 bool m_checkedForHeadCharset;