TextCodecMac.h 2.66 KB
Newer Older
ap's avatar
ap committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/*
 * Copyright (C) 2004, 2006 Apple Computer, Inc.  All rights reserved.
 * Copyright (C) 2006 Alexey Proskuryakov <ap@nypop.com>
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 */

darin's avatar
darin committed
27 28
#ifndef TextCodecMac_h
#define TextCodecMac_h
ap's avatar
ap committed
29

darin's avatar
darin committed
30
#include "TextCodec.h"
darin's avatar
darin committed
31
#include <CoreServices/CoreServices.h>
ap's avatar
ap committed
32 33 34

namespace WebCore {

darin's avatar
darin committed
35 36 37 38
    typedef ::TextEncoding TECTextEncodingID;
    const TECTextEncodingID invalidEncoding = kCFStringEncodingInvalidId;

    class TextCodecMac : public TextCodec {
ap's avatar
ap committed
39
    public:
darin's avatar
darin committed
40 41
        static void registerEncodingNames(EncodingNameRegistrar);
        static void registerCodecs(TextCodecRegistrar);
ap's avatar
ap committed
42

darin's avatar
darin committed
43 44
        explicit TextCodecMac(TECTextEncodingID);
        virtual ~TextCodecMac();
ap's avatar
ap committed
45

darin's avatar
darin committed
46 47
        virtual String decode(const char*, size_t length, bool flush = false);
        virtual CString encode(const UChar*, size_t length, bool allowEntities = false);
ap's avatar
ap committed
48 49

    private:
darin's avatar
darin committed
50 51
        OSStatus decode(const unsigned char* inputBuffer, int inputBufferLength, int& inputLength,
            void* outputBuffer, int outputBufferLength, int& outputLength);
ap's avatar
ap committed
52

darin's avatar
darin committed
53 54
        OSStatus createTECConverter() const;
        void releaseTECConverter() const;
ap's avatar
ap committed
55

darin's avatar
darin committed
56 57
        TECTextEncodingID m_encoding;
        UChar m_backslashAsCurrencySymbol;
ap's avatar
ap committed
58 59 60
        bool m_error;
        unsigned m_numBufferedBytes;
        unsigned char m_bufferedBytes[16]; // bigger than any single multi-byte character
darin's avatar
darin committed
61
        mutable TECObjectRef m_converterTEC;
ap's avatar
ap committed
62
    };
darin's avatar
darin committed
63

ap's avatar
ap committed
64 65
} // namespace WebCore

darin's avatar
darin committed
66
#endif // TextCodecMac_h