#ifndef TextCodecICU_h
#define TextCodecICU_h
#include "TextCodec.h"
#include <unicode/utypes.h>
typedef struct UConverter UConverter;
namespace WebCore {
class TextCodecICU : public TextCodec {
public:
static std::unique_ptr<TextCodec> create(const TextEncoding&, const void* additionalData);
TextCodecICU(const char* encoding, const char* canonicalConverterName);
static void registerEncodingNames(EncodingNameRegistrar);
static void registerCodecs(TextCodecRegistrar);
virtual ~TextCodecICU();
private:
virtual String decode(const char*, size_t length, bool flush, bool stopOnError, bool& sawError);
virtual CString encode(const UChar*, size_t length, UnencodableHandling);
void createICUConverter() const;
void releaseICUConverter() const;
bool needsGBKFallbacks() const { return m_needsGBKFallbacks; }
void setNeedsGBKFallbacks(bool needsFallbacks) { m_needsGBKFallbacks = needsFallbacks; }
int decodeToBuffer(UChar* buffer, UChar* bufferLimit, const char*& source,
const char* sourceLimit, int32_t* offsets, bool flush, UErrorCode& err);
const char* const m_encodingName;
const char* const m_canonicalConverterName;
mutable UConverter* m_converterICU;
mutable bool m_needsGBKFallbacks;
};
struct ICUConverterWrapper {
WTF_MAKE_NONCOPYABLE(ICUConverterWrapper); WTF_MAKE_FAST_ALLOCATED;
public:
ICUConverterWrapper() : converter(0) { }
~ICUConverterWrapper();
UConverter* converter;
};
}
#endif // TextCodecICU_h