mirror of
https://bitbucket.org/smil3y/katie.git
synced 2025-02-23 18:32:55 +00:00
QTextCodec rewrite
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
3b2f367497
commit
81cc260944
15 changed files with 1557 additions and 2078 deletions
43
src/3rdparty/javascriptcore/API/JSStringRef.cpp
vendored
43
src/3rdparty/javascriptcore/API/JSStringRef.cpp
vendored
|
@ -30,8 +30,6 @@
|
|||
#include "OpaqueJSString.h"
|
||||
#include <wtf/unicode/UTF8.h>
|
||||
|
||||
#include <QTextCodec>
|
||||
|
||||
using namespace JSC;
|
||||
using namespace WTF::Unicode;
|
||||
|
||||
|
@ -41,22 +39,6 @@ JSStringRef JSStringCreateWithCharacters(const JSChar* chars, size_t numChars)
|
|||
return OpaqueJSString::create(chars, numChars).releaseRef();
|
||||
}
|
||||
|
||||
JSStringRef JSStringCreateWithUTF8CString(const char* string)
|
||||
{
|
||||
initializeThreading();
|
||||
if (string) {
|
||||
QTextCodec *codec = QTextCodec::codecForName("UTF-8");
|
||||
QTextDecoder decoder(codec, QTextCodec::DefaultConversion);
|
||||
QString result = decoder.toUnicode(string, strlen(string));
|
||||
if (!decoder.hasFailure()) {
|
||||
return OpaqueJSString::create(reinterpret_cast<const UChar*>(result.unicode()), result.size()).releaseRef();
|
||||
}
|
||||
}
|
||||
|
||||
// Null string.
|
||||
return OpaqueJSString::create().releaseRef();
|
||||
}
|
||||
|
||||
JSStringRef JSStringRetain(JSStringRef string)
|
||||
{
|
||||
string->ref();
|
||||
|
@ -84,33 +66,8 @@ size_t JSStringGetMaximumUTF8CStringSize(JSStringRef string)
|
|||
return string->length() * 3 + 1; // + 1 for terminating '\0'
|
||||
}
|
||||
|
||||
size_t JSStringGetUTF8CString(JSStringRef string, char* buffer, size_t bufferSize)
|
||||
{
|
||||
if (!bufferSize)
|
||||
return 0;
|
||||
|
||||
QTextCodec *codec = QTextCodec::codecForName("UTF-8");
|
||||
QTextEncoder encoder(codec, QTextCodec::DefaultConversion);
|
||||
QByteArray result = encoder.fromUnicode(reinterpret_cast<const QChar*>(string->characters()), string->length());
|
||||
if (encoder.hasFailure()) {
|
||||
buffer = nullptr;
|
||||
return 0;
|
||||
}
|
||||
buffer = result.data();
|
||||
return result.size();
|
||||
}
|
||||
|
||||
bool JSStringIsEqual(JSStringRef a, JSStringRef b)
|
||||
{
|
||||
unsigned len = a->length();
|
||||
return len == b->length() && 0 == memcmp(a->characters(), b->characters(), len * sizeof(UChar));
|
||||
}
|
||||
|
||||
bool JSStringIsEqualToUTF8CString(JSStringRef a, const char* b)
|
||||
{
|
||||
JSStringRef bBuf = JSStringCreateWithUTF8CString(b);
|
||||
bool result = JSStringIsEqual(a, bBuf);
|
||||
JSStringRelease(bBuf);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
31
src/3rdparty/javascriptcore/API/JSStringRef.h
vendored
31
src/3rdparty/javascriptcore/API/JSStringRef.h
vendored
|
@ -48,13 +48,6 @@ typedef unsigned short JSChar;
|
|||
@result A JSString containing chars. Ownership follows the Create Rule.
|
||||
*/
|
||||
JS_EXPORT JSStringRef JSStringCreateWithCharacters(const JSChar* chars, size_t numChars);
|
||||
/*!
|
||||
@function
|
||||
@abstract Creates a JavaScript string from a null-terminated UTF8 string.
|
||||
@param string The null-terminated UTF8 string to copy into the new JSString.
|
||||
@result A JSString containing string. Ownership follows the Create Rule.
|
||||
*/
|
||||
JS_EXPORT JSStringRef JSStringCreateWithUTF8CString(const char* string);
|
||||
|
||||
/*!
|
||||
@function
|
||||
|
@ -63,6 +56,7 @@ JS_EXPORT JSStringRef JSStringCreateWithUTF8CString(const char* string);
|
|||
@result A JSString that is the same as string.
|
||||
*/
|
||||
JS_EXPORT JSStringRef JSStringRetain(JSStringRef string);
|
||||
|
||||
/*!
|
||||
@function
|
||||
@abstract Releases a JavaScript string.
|
||||
|
@ -77,6 +71,7 @@ JS_EXPORT void JSStringRelease(JSStringRef string);
|
|||
@result The number of Unicode characters stored in string.
|
||||
*/
|
||||
JS_EXPORT size_t JSStringGetLength(JSStringRef string);
|
||||
|
||||
/*!
|
||||
@function
|
||||
@abstract Returns a pointer to the Unicode character buffer that
|
||||
|
@ -98,20 +93,6 @@ JS_EXPORT const JSChar* JSStringGetCharactersPtr(JSStringRef string);
|
|||
up requiring could be less than this, but never more.
|
||||
*/
|
||||
JS_EXPORT size_t JSStringGetMaximumUTF8CStringSize(JSStringRef string);
|
||||
/*!
|
||||
@function
|
||||
@abstract Converts a JavaScript string into a null-terminated UTF8 string,
|
||||
and copies the result into an external byte buffer.
|
||||
@param string The source JSString.
|
||||
@param buffer The destination byte buffer into which to copy a null-terminated
|
||||
UTF8 representation of string. On return, buffer contains a UTF8 string
|
||||
representation of string. If bufferSize is too small, buffer will contain only
|
||||
partial results. If buffer is not at least bufferSize bytes in size,
|
||||
behavior is undefined.
|
||||
@param bufferSize The size of the external buffer in bytes.
|
||||
@result The number of bytes written into buffer (including the null-terminator byte).
|
||||
*/
|
||||
JS_EXPORT size_t JSStringGetUTF8CString(JSStringRef string, char* buffer, size_t bufferSize);
|
||||
|
||||
/*!
|
||||
@function
|
||||
|
@ -121,14 +102,6 @@ JS_EXPORT size_t JSStringGetUTF8CString(JSStringRef string, char* buffer, size_t
|
|||
@result true if the two strings match, otherwise false.
|
||||
*/
|
||||
JS_EXPORT bool JSStringIsEqual(JSStringRef a, JSStringRef b);
|
||||
/*!
|
||||
@function
|
||||
@abstract Tests whether a JavaScript string matches a null-terminated UTF8 string.
|
||||
@param a The JSString to test.
|
||||
@param b The null-terminated UTF8 string to test.
|
||||
@result true if the two strings match, otherwise false.
|
||||
*/
|
||||
JS_EXPORT bool JSStringIsEqualToUTF8CString(JSStringRef a, const char* b);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
14
src/3rdparty/javascriptcore/runtime/UString.cpp
vendored
14
src/3rdparty/javascriptcore/runtime/UString.cpp
vendored
|
@ -127,10 +127,9 @@ UString UString::createFromUTF8(const char* string)
|
|||
if (!string)
|
||||
return null();
|
||||
|
||||
QTextCodec *codec = QTextCodec::codecForName("UTF-8");
|
||||
QTextDecoder decoder(codec, QTextCodec::DefaultConversion);
|
||||
QString result = decoder.toUnicode(string, strlen(string));
|
||||
if (decoder.hasFailure()) {
|
||||
QTextConverter converter("UTF-8");
|
||||
QString result = converter.toUnicode(string, strlen(string));
|
||||
if (converter.hasFailure()) {
|
||||
return null();
|
||||
}
|
||||
|
||||
|
@ -773,10 +772,9 @@ bool equal(const UString::Rep* r, const UString::Rep* b)
|
|||
|
||||
const char* UString::UTF8String() const
|
||||
{
|
||||
QTextCodec *codec = QTextCodec::codecForName("UTF-8");
|
||||
QTextEncoder encoder(codec, QTextCodec::DefaultConversion);
|
||||
QByteArray result = encoder.fromUnicode(reinterpret_cast<const QChar*>(data()), size());
|
||||
if (encoder.hasFailure()) {
|
||||
QTextConverter converter("UTF-8");
|
||||
QByteArray result = converter.fromUnicode(reinterpret_cast<const QChar*>(data()), size());
|
||||
if (converter.hasFailure()) {
|
||||
return nullptr;
|
||||
}
|
||||
return result.constData();
|
||||
|
|
|
@ -99,9 +99,8 @@ include_directories(
|
|||
)
|
||||
|
||||
set(CORE_HEADERS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/codecs/qtextcodec_p.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/codecs/qtextcodec.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/codecs/qicucodec_p.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/codecs/qtextcodec_p.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/global/qendian.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/global/qglobal.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/global/qlibraryinfo.h
|
||||
|
@ -237,7 +236,6 @@ set(CORE_HEADERS
|
|||
|
||||
set(CORE_SOURCES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/codecs/qtextcodec.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/codecs/qicucodec.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/global/qglobal.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/global/qlibraryinfo.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/global/qt_error_string.cpp
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,78 +0,0 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2019 Ivailo Monev
|
||||
**
|
||||
** This file is part of the QtCore module of the Katie Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** This file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QICUCODEC_P_H
|
||||
#define QICUCODEC_P_H
|
||||
|
||||
#include "QtCore/qtextcodec.h"
|
||||
|
||||
//
|
||||
// W A R N I N G
|
||||
// -------------
|
||||
//
|
||||
// This file is not part of the Katie API. It exists purely as an
|
||||
// implementation detail. This header file may change from version to
|
||||
// version without notice, or even be removed.
|
||||
//
|
||||
// We mean it.
|
||||
//
|
||||
|
||||
#include "qtextcodec_p.h"
|
||||
|
||||
#include <unicode/ucnv.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QIcuCodec : public QTextCodec
|
||||
{
|
||||
public:
|
||||
explicit QIcuCodec(const QByteArray &name);
|
||||
explicit QIcuCodec(const int mib);
|
||||
~QIcuCodec();
|
||||
|
||||
QString convertToUnicode(const char *data, int len, ConverterState *state) const;
|
||||
QByteArray convertFromUnicode(const QChar *unicode, int len, ConverterState *state) const;
|
||||
|
||||
#ifndef QT_NO_TEXTCODEC
|
||||
QByteArray name() const;
|
||||
QList<QByteArray> aliases() const;
|
||||
int mibEnum() const;
|
||||
|
||||
static QList<QByteArray> allCodecs();
|
||||
static QList<int> allMibs();
|
||||
static QTextCodec* codecForUtf(const QByteArray &text, QTextCodec *defaultCodec);
|
||||
static QTextCodec* codecForData(const QByteArray &text, QTextCodec *defaultCodec);
|
||||
#endif
|
||||
|
||||
static QString convertTo(const char *data, int len, const char* const codec);
|
||||
static QByteArray convertFrom(const QChar *unicode, int len, const char* const codec);
|
||||
|
||||
void invalidChars(int length) const;
|
||||
|
||||
private:
|
||||
UConverter *getConverter(QTextCodec::ConverterState *state) const;
|
||||
|
||||
QByteArray m_name;
|
||||
mutable QTextCodec::ConverterState *m_callbackstate;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load diff
|
@ -24,18 +24,52 @@
|
|||
|
||||
#include <QtCore/qstring.h>
|
||||
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
#ifndef QT_NO_TEXTCODEC
|
||||
|
||||
class QIODevice;
|
||||
class QTextDecoder;
|
||||
class QTextEncoder;
|
||||
class QTextCodecPrivate;
|
||||
|
||||
class Q_CORE_EXPORT QTextConverter
|
||||
{
|
||||
public:
|
||||
enum ConversionFlag {
|
||||
DefaultConversion,
|
||||
ConvertInvalidToNull = 0x80000000,
|
||||
IgnoreHeader = 0x1
|
||||
};
|
||||
Q_DECLARE_FLAGS(ConversionFlags, ConversionFlag)
|
||||
|
||||
QTextConverter();
|
||||
QTextConverter(const QTextConverter &other);
|
||||
QTextConverter(const QByteArray &name);
|
||||
QTextConverter(const int mib);
|
||||
~QTextConverter();
|
||||
|
||||
ConversionFlags flags() const;
|
||||
void setFlags(const ConversionFlags flags);
|
||||
bool hasFailure() const;
|
||||
void reset();
|
||||
|
||||
QString toUnicode(const char *in, int length) const;
|
||||
inline QString toUnicode(const QByteArray &ba) const
|
||||
{ return toUnicode(ba.constData(), ba.size()); }
|
||||
inline QString toUnicode(const char* chars) const
|
||||
{ return toUnicode(chars, qstrlen(chars)); }
|
||||
|
||||
QByteArray fromUnicode(const QChar *in, int length) const;
|
||||
inline QByteArray fromUnicode(const QString &uc) const
|
||||
{ return fromUnicode(uc.unicode(), uc.size()); }
|
||||
|
||||
QTextConverter& operator=(const QTextConverter &other);
|
||||
|
||||
private:
|
||||
QTextCodecPrivate* d_ptr;
|
||||
};
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(QTextConverter::ConversionFlags)
|
||||
|
||||
class Q_CORE_EXPORT QTextCodec
|
||||
{
|
||||
Q_DISABLE_COPY(QTextCodec)
|
||||
public:
|
||||
static QTextCodec* codecForName(const QByteArray &name);
|
||||
static inline QTextCodec* codecForName(const char *name)
|
||||
|
@ -60,92 +94,36 @@ public:
|
|||
bool canEncode(QChar) const;
|
||||
bool canEncode(const QString&) const;
|
||||
|
||||
QString toUnicode(const QByteArray&) const;
|
||||
QString toUnicode(const char* chars) const;
|
||||
QByteArray fromUnicode(const QString& uc) const;
|
||||
enum ConversionFlag {
|
||||
DefaultConversion,
|
||||
ConvertInvalidToNull = 0x80000000,
|
||||
IgnoreHeader = 0x1
|
||||
};
|
||||
Q_DECLARE_FLAGS(ConversionFlags, ConversionFlag)
|
||||
QString toUnicode(const char *in, int length) const;
|
||||
QByteArray fromUnicode(const QChar *in, int length) const;
|
||||
|
||||
struct Q_CORE_EXPORT ConverterState {
|
||||
ConverterState(ConversionFlags f = DefaultConversion)
|
||||
: flags(f), invalidChars(0), d(nullptr)
|
||||
{
|
||||
}
|
||||
~ConverterState();
|
||||
inline QString toUnicode(const QByteArray &ba) const
|
||||
{ return toUnicode(ba.constData(), ba.size()); }
|
||||
inline QString toUnicode(const char* chars) const
|
||||
{ return toUnicode(chars, qstrlen(chars)); }
|
||||
inline QByteArray fromUnicode(const QString &uc) const
|
||||
{ return fromUnicode(uc.unicode(), uc.size()); }
|
||||
|
||||
ConversionFlags flags;
|
||||
int invalidChars;
|
||||
private:
|
||||
void *d;
|
||||
QByteArray name() const;
|
||||
QList<QByteArray> aliases() const;
|
||||
int mibEnum() const;
|
||||
|
||||
friend class QIcuCodec;
|
||||
friend class QTextStreamPrivate;
|
||||
friend class QTextStream;
|
||||
inline QTextConverter converter() const
|
||||
{ return QTextConverter(name()); }
|
||||
|
||||
ConverterState(const ConverterState &other);
|
||||
ConverterState& operator=(const ConverterState &other);
|
||||
};
|
||||
|
||||
QString toUnicode(const char *in, int length, ConverterState *state = nullptr) const
|
||||
{ return convertToUnicode(in, length, state); }
|
||||
QByteArray fromUnicode(const QChar *in, int length, ConverterState *state = nullptr) const
|
||||
{ return convertFromUnicode(in, length, state); }
|
||||
|
||||
QTextDecoder* makeDecoder(ConversionFlags flags = DefaultConversion) const;
|
||||
QTextEncoder* makeEncoder(ConversionFlags flags = DefaultConversion) const;
|
||||
|
||||
virtual QByteArray name() const = 0;
|
||||
virtual QList<QByteArray> aliases() const;
|
||||
virtual int mibEnum() const = 0;
|
||||
|
||||
protected:
|
||||
virtual QString convertToUnicode(const char *in, int length, ConverterState *state) const = 0;
|
||||
virtual QByteArray convertFromUnicode(const QChar *in, int length, ConverterState *state) const = 0;
|
||||
private:
|
||||
Q_DISABLE_COPY(QTextCodec);
|
||||
|
||||
QTextCodec();
|
||||
virtual ~QTextCodec();
|
||||
~QTextCodec();
|
||||
|
||||
private:
|
||||
friend class QTextCodecCleanup;
|
||||
};
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(QTextCodec::ConversionFlags)
|
||||
|
||||
class Q_CORE_EXPORT QTextEncoder {
|
||||
Q_DISABLE_COPY(QTextEncoder)
|
||||
public:
|
||||
explicit QTextEncoder(const QTextCodec *codec) : c(codec) {}
|
||||
QTextEncoder(const QTextCodec *codec, QTextCodec::ConversionFlags flags);
|
||||
~QTextEncoder();
|
||||
QByteArray fromUnicode(const QString& str);
|
||||
QByteArray fromUnicode(const QChar *uc, int len);
|
||||
bool hasFailure() const;
|
||||
private:
|
||||
const QTextCodec *c;
|
||||
QTextCodec::ConverterState state;
|
||||
};
|
||||
|
||||
class Q_CORE_EXPORT QTextDecoder {
|
||||
Q_DISABLE_COPY(QTextDecoder)
|
||||
public:
|
||||
explicit QTextDecoder(const QTextCodec *codec) : c(codec) {}
|
||||
QTextDecoder(const QTextCodec *codec, QTextCodec::ConversionFlags flags);
|
||||
~QTextDecoder();
|
||||
QString toUnicode(const char* chars, int len);
|
||||
QString toUnicode(const QByteArray &ba);
|
||||
void toUnicode(QString *target, const char *chars, int len);
|
||||
bool hasFailure() const;
|
||||
private:
|
||||
const QTextCodec *c;
|
||||
QTextCodec::ConverterState state;
|
||||
QTextCodecPrivate* d_ptr;
|
||||
};
|
||||
|
||||
#endif // QT_NO_TEXTCODEC
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
|
||||
#endif // QTEXTCODEC_H
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2015 The Qt Company Ltd.
|
||||
** Copyright (C) 2016 Ivailo Monev
|
||||
** Copyright (C) 2019 Ivailo Monev
|
||||
**
|
||||
** This file is part of the QtCore module of the Katie Toolkit.
|
||||
**
|
||||
|
@ -22,6 +21,8 @@
|
|||
#ifndef QTEXTCODEC_P_H
|
||||
#define QTEXTCODEC_P_H
|
||||
|
||||
#include "QtCore/qtextcodec.h"
|
||||
|
||||
//
|
||||
// W A R N I N G
|
||||
// -------------
|
||||
|
@ -35,40 +36,32 @@
|
|||
|
||||
#include "qtextcodec.h"
|
||||
|
||||
#include <unicode/ucnv.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
#ifdef QT_NO_TEXTCODEC
|
||||
|
||||
class QTextCodec
|
||||
class QTextCodecPrivate
|
||||
{
|
||||
public:
|
||||
enum ConversionFlag {
|
||||
DefaultConversion,
|
||||
ConvertInvalidToNull = 0x80000000,
|
||||
IgnoreHeader = 0x1
|
||||
};
|
||||
Q_DECLARE_FLAGS(ConversionFlags, ConversionFlag)
|
||||
QTextCodecPrivate(const QByteArray &name);
|
||||
QTextCodecPrivate(const int mib);
|
||||
~QTextCodecPrivate();
|
||||
|
||||
struct ConverterState {
|
||||
ConverterState(ConversionFlags f = DefaultConversion)
|
||||
: flags(f), invalidChars(0), d(nullptr) { }
|
||||
~ConverterState() { }
|
||||
ConversionFlags flags;
|
||||
int invalidChars;
|
||||
private:
|
||||
void *d;
|
||||
static QList<QByteArray> allCodecs();
|
||||
static QList<int> allMibs();
|
||||
|
||||
friend class QIcuCodec;
|
||||
friend class QTextStreamPrivate;
|
||||
friend class QTextStream;
|
||||
static QString convertTo(const char *data, int len, const char* const codec);
|
||||
static QByteArray convertFrom(const QChar *unicode, int len, const char* const codec);
|
||||
|
||||
ConverterState(const ConverterState &other);
|
||||
ConverterState& operator=(const ConverterState &other);
|
||||
};
|
||||
UConverter* getConverter();
|
||||
void invalidChars(int length) const;
|
||||
|
||||
QByteArray m_name;
|
||||
QTextConverter::ConversionFlags m_flags;
|
||||
UConverter* m_conv;
|
||||
mutable int m_invalidchars;
|
||||
};
|
||||
|
||||
#endif //QT_NO_TEXTCODEC
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif
|
||||
#endif // QTEXTCODEC_P_H
|
||||
|
|
|
@ -299,9 +299,9 @@ public:
|
|||
#ifndef QT_NO_TEXTCODEC
|
||||
// codec
|
||||
QTextCodec *codec;
|
||||
QTextCodec::ConverterState readConverterState;
|
||||
QTextCodec::ConverterState writeConverterState;
|
||||
QTextCodec::ConverterState readConverterSavedState;
|
||||
QTextConverter readConverter;
|
||||
QTextConverter writeConverter;
|
||||
QTextConverter readConverterSaved;
|
||||
bool autoDetectUnicode;
|
||||
#endif
|
||||
|
||||
|
@ -408,10 +408,12 @@ void QTextStreamPrivate::reset()
|
|||
|
||||
#ifndef QT_NO_TEXTCODEC
|
||||
codec = QTextCodec::codecForLocale();
|
||||
readConverterState = QTextCodec::ConverterState();
|
||||
writeConverterState = QTextCodec::ConverterState();
|
||||
readConverterSavedState = QTextCodec::ConverterState();
|
||||
writeConverterState.flags |= QTextCodec::IgnoreHeader;
|
||||
readConverter = codec->converter();
|
||||
readConverter.setFlags(QTextConverter::DefaultConversion);
|
||||
writeConverter = codec->converter();
|
||||
writeConverter.setFlags(QTextConverter::IgnoreHeader);
|
||||
readConverterSaved.reset();
|
||||
readConverterSaved.setFlags(QTextConverter::DefaultConversion);
|
||||
autoDetectUnicode = true;
|
||||
#endif
|
||||
}
|
||||
|
@ -445,7 +447,7 @@ bool QTextStreamPrivate::fillReadBuffer(qint64 maxBytes)
|
|||
codec = QTextCodec::codecForUtfText(buffer, codec);
|
||||
if (!codec) {
|
||||
codec = QTextCodec::codecForLocale();
|
||||
writeConverterState.flags |= QTextCodec::IgnoreHeader;
|
||||
writeConverter.setFlags(writeConverter.flags() | QTextConverter::IgnoreHeader);
|
||||
}
|
||||
}
|
||||
#if defined (QTEXTSTREAM_DEBUG)
|
||||
|
@ -465,7 +467,7 @@ bool QTextStreamPrivate::fillReadBuffer(qint64 maxBytes)
|
|||
int oldReadBufferSize = readBuffer.size();
|
||||
#ifndef QT_NO_TEXTCODEC
|
||||
// convert to unicode
|
||||
readBuffer += codec->toUnicode(buffer.constData(), bytesRead, &readConverterState);
|
||||
readBuffer += readConverter.toUnicode(buffer.constData(), bytesRead);
|
||||
#else
|
||||
readBuffer += QString::fromAscii(buffer.constData());
|
||||
#endif
|
||||
|
@ -543,11 +545,11 @@ void QTextStreamPrivate::flushWriteBuffer()
|
|||
codec = QTextCodec::codecForLocale();
|
||||
#if defined (QTEXTSTREAM_DEBUG)
|
||||
qDebug("QTextStreamPrivate::flushWriteBuffer(), using %s codec (%s generating BOM)",
|
||||
codec->name().constData(), writeConverterState.flags & QTextCodec::IgnoreHeader ? "not" : "");
|
||||
codec->name().constData(), writeConverter.flags() & QTextConverter::IgnoreHeader ? "not" : "");
|
||||
#endif
|
||||
|
||||
// convert from unicode to raw data
|
||||
QByteArray data = codec->fromUnicode(writeBuffer.data(), writeBuffer.size(), &writeConverterState);
|
||||
QByteArray data = writeConverter.fromUnicode(writeBuffer.data(), writeBuffer.size());
|
||||
#else
|
||||
QByteArray data = writeBuffer.toLocal8Bit();
|
||||
#endif
|
||||
|
@ -749,7 +751,7 @@ inline void QTextStreamPrivate::consume(int size)
|
|||
inline void QTextStreamPrivate::saveConverterState(qint64 newPos)
|
||||
{
|
||||
#ifndef QT_NO_TEXTCODEC
|
||||
readConverterSavedState = readConverterState;
|
||||
readConverterSaved = readConverter;
|
||||
#endif
|
||||
|
||||
readBufferStartDevicePos = newPos;
|
||||
|
@ -761,7 +763,7 @@ inline void QTextStreamPrivate::saveConverterState(qint64 newPos)
|
|||
inline void QTextStreamPrivate::restoreToSavedConverterState()
|
||||
{
|
||||
#ifndef QT_NO_TEXTCODEC
|
||||
readConverterState = readConverterSavedState;
|
||||
readConverter = readConverterSaved;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -1050,10 +1052,12 @@ bool QTextStream::seek(qint64 pos)
|
|||
|
||||
#ifndef QT_NO_TEXTCODEC
|
||||
// Reset the codec converter states.
|
||||
d->readConverterState = QTextCodec::ConverterState();
|
||||
d->writeConverterState = QTextCodec::ConverterState();
|
||||
d->readConverterSavedState = QTextCodec::ConverterState();
|
||||
d->writeConverterState.flags |= QTextCodec::IgnoreHeader;
|
||||
d->readConverter.reset();
|
||||
d->readConverter.setFlags(QTextConverter::DefaultConversion);
|
||||
d->writeConverter.reset();
|
||||
d->writeConverter.setFlags(QTextConverter::IgnoreHeader);
|
||||
d->readConverterSaved.reset();
|
||||
d->readConverterSaved.setFlags(QTextConverter::DefaultConversion);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
@ -2827,6 +2831,8 @@ void QTextStream::setCodec(QTextCodec *codec)
|
|||
}
|
||||
}
|
||||
d->codec = codec;
|
||||
d->readConverter = codec->converter();
|
||||
d->writeConverter = codec->converter();
|
||||
if (seekPos >=0 && !d->readBuffer.isEmpty())
|
||||
seek(seekPos);
|
||||
}
|
||||
|
@ -2903,9 +2909,9 @@ void QTextStream::setGenerateByteOrderMark(bool generate)
|
|||
Q_D(QTextStream);
|
||||
if (d->writeBuffer.isEmpty()) {
|
||||
if (generate)
|
||||
d->writeConverterState.flags &= ~QTextCodec::IgnoreHeader;
|
||||
d->writeConverter.setFlags(d->writeConverter.flags() & ~QTextConverter::IgnoreHeader);
|
||||
else
|
||||
d->writeConverterState.flags |= QTextCodec::IgnoreHeader;
|
||||
d->writeConverter.setFlags(d->writeConverter.flags() | QTextConverter::IgnoreHeader);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2919,7 +2925,7 @@ void QTextStream::setGenerateByteOrderMark(bool generate)
|
|||
bool QTextStream::generateByteOrderMark() const
|
||||
{
|
||||
Q_D(const QTextStream);
|
||||
return (d->writeConverterState.flags & QTextCodec::IgnoreHeader) == 0;
|
||||
return (d->writeConverter.flags() & QTextConverter::IgnoreHeader) == 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
#include "qstringlist.h"
|
||||
#include "qregexp.h"
|
||||
#include "qicucodec_p.h"
|
||||
#include "qtextcodec_p.h"
|
||||
#include "qdatastream.h"
|
||||
#include "qlist.h"
|
||||
#include "qlocale.h"
|
||||
|
@ -3176,7 +3176,7 @@ QByteArray QString::toLatin1() const
|
|||
*/
|
||||
QByteArray QString::toAscii() const
|
||||
{
|
||||
return QIcuCodec::convertFrom(constData(), length(), "US-ASCII");
|
||||
return QTextCodecPrivate::convertFrom(constData(), length(), "US-ASCII");
|
||||
}
|
||||
|
||||
static QByteArray toLocal8Bit_helper(const QChar *data, int length)
|
||||
|
@ -3233,7 +3233,7 @@ QByteArray QString::toUtf8() const
|
|||
if (isNull())
|
||||
return QByteArray();
|
||||
|
||||
return QIcuCodec::convertFrom(constData(), length(), "UTF-8");
|
||||
return QTextCodecPrivate::convertFrom(constData(), length(), "UTF-8");
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -3317,7 +3317,7 @@ QString QString::fromLatin1(const char *str, int size)
|
|||
if (size < 0) {
|
||||
size = qstrlen(str);
|
||||
}
|
||||
return QIcuCodec::convertTo(str, size, "latin1");
|
||||
return QTextCodecPrivate::convertTo(str, size, "latin1");
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -3363,7 +3363,7 @@ QString QString::fromAscii(const char *str, int size)
|
|||
if (size < 0) {
|
||||
size = qstrlen(str);
|
||||
}
|
||||
return QIcuCodec::convertTo(str, size, "US-ASCII");
|
||||
return QTextCodecPrivate::convertTo(str, size, "US-ASCII");
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -3395,7 +3395,7 @@ QString QString::fromUtf8(const char *str, int size)
|
|||
if (size < 0) {
|
||||
size = qstrlen(str);
|
||||
}
|
||||
return QIcuCodec::convertTo(str, size, "UTF-8");
|
||||
return QTextCodecPrivate::convertTo(str, size, "UTF-8");
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -3426,7 +3426,7 @@ QString QString::fromUtf16(const ushort *unicode, int size)
|
|||
++size;
|
||||
}
|
||||
}
|
||||
return QIcuCodec::convertTo((const char *)unicode, size, "UTF-16");
|
||||
return QTextCodecPrivate::convertTo((const char *)unicode, size, "UTF-16");
|
||||
}
|
||||
|
||||
|
||||
|
@ -3452,7 +3452,7 @@ QString QString::fromUcs4(const uint *unicode, int size)
|
|||
++size;
|
||||
}
|
||||
}
|
||||
return QIcuCodec::convertTo((const char *)unicode, size, "UTF-32");
|
||||
return QTextCodecPrivate::convertTo((const char *)unicode, size, "UTF-32");
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -8125,7 +8125,7 @@ QByteArray QStringRef::toLatin1() const
|
|||
*/
|
||||
QByteArray QStringRef::toAscii() const
|
||||
{
|
||||
return QIcuCodec::convertFrom(constData(), length(), "US-ASCII");
|
||||
return QTextCodecPrivate::convertFrom(constData(), length(), "US-ASCII");
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -8176,7 +8176,7 @@ QByteArray QStringRef::toUtf8() const
|
|||
{
|
||||
if (isNull())
|
||||
return QByteArray();
|
||||
return QIcuCodec::convertFrom(constData(), length(), "UTF-8");
|
||||
return QTextCodecPrivate::convertFrom(constData(), length(), "UTF-8");
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
@ -37,7 +37,6 @@ set(BOOTSTRAP_DEFINITIONS
|
|||
-DQT_NO_COMPRESS
|
||||
-DQT_NO_EXCEPTIONS
|
||||
-DQT_NO_REGEXP
|
||||
-DQT_NO_TEXTCODEC
|
||||
)
|
||||
|
||||
if(WITH_EXECINFO AND EXECINFO_FOUND)
|
||||
|
@ -48,7 +47,7 @@ if(WITH_EXECINFO AND EXECINFO_FOUND)
|
|||
endif()
|
||||
|
||||
set(BOOTSTRAP_SOURCES
|
||||
${CMAKE_SOURCE_DIR}/src/core/codecs/qicucodec.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/core/codecs/qtextcodec.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/core/global/qglobal.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/core/global/qt_error_string.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/core/io/qabstractfileengine.cpp
|
||||
|
|
|
@ -369,7 +369,7 @@ QXmlStreamReader::QXmlStreamReader(const QString &data)
|
|||
d->dataBuffer = data.toLatin1();
|
||||
#else
|
||||
d->dataBuffer = d->codec->fromUnicode(data);
|
||||
d->decoder = d->codec->makeDecoder();
|
||||
d->decoder = new QTextConverter(d->codec->name());
|
||||
#endif
|
||||
d->lockEncoding = true;
|
||||
|
||||
|
@ -1358,10 +1358,10 @@ ushort QXmlStreamReaderPrivate::getChar_helper()
|
|||
QTextCodec *fallback = QTextCodec::codecForName("UTF-8");
|
||||
codec = QTextCodec::codecForUtfText(rawReadBuffer, fallback);
|
||||
Q_ASSERT(codec);
|
||||
decoder = codec->makeDecoder();
|
||||
decoder = new QTextConverter(codec->name());
|
||||
}
|
||||
|
||||
decoder->toUnicode(&readBuffer, rawReadBuffer.constData(), nbytesread);
|
||||
readBuffer = decoder->toUnicode(rawReadBuffer.constData(), nbytesread);
|
||||
|
||||
if(lockEncoding && decoder->hasFailure()) {
|
||||
raiseWellFormedError(QXmlStream::tr("Encountered incorrectly encoded content."));
|
||||
|
@ -1649,8 +1649,8 @@ void QXmlStreamReaderPrivate::startDocument()
|
|||
else if (newCodec != codec && !lockEncoding) {
|
||||
codec = newCodec;
|
||||
delete decoder;
|
||||
decoder = codec->makeDecoder();
|
||||
decoder->toUnicode(&readBuffer, rawReadBuffer.data(), nbytesread);
|
||||
decoder = new QTextConverter(codec->name());
|
||||
readBuffer = decoder->toUnicode(rawReadBuffer.data(), nbytesread);
|
||||
}
|
||||
#endif // QT_NO_TEXTCODEC
|
||||
}
|
||||
|
@ -2814,7 +2814,7 @@ public:
|
|||
|
||||
#ifndef QT_NO_TEXTCODEC
|
||||
QTextCodec *codec;
|
||||
QTextEncoder *encoder;
|
||||
QTextConverter *encoder;
|
||||
#endif
|
||||
void checkIfASCIICompatibleCodec();
|
||||
|
||||
|
@ -2835,7 +2835,8 @@ QXmlStreamWriterPrivate::QXmlStreamWriterPrivate()
|
|||
deleteDevice = false;
|
||||
#ifndef QT_NO_TEXTCODEC
|
||||
codec = QTextCodec::codecForMib(106); // utf8
|
||||
encoder = codec->makeEncoder(QTextCodec::IgnoreHeader); // no byte order mark for utf8
|
||||
encoder = new QTextConverter(codec->name());
|
||||
encoder->setFlags(QTextConverter::IgnoreHeader); // no byte order mark for utf8
|
||||
#endif
|
||||
checkIfASCIICompatibleCodec();
|
||||
inStartElement = inEmptyElement = false;
|
||||
|
@ -3122,7 +3123,8 @@ void QXmlStreamWriter::setCodec(QTextCodec *codec)
|
|||
if (codec) {
|
||||
d->codec = codec;
|
||||
delete d->encoder;
|
||||
d->encoder = codec->makeEncoder(QTextCodec::IgnoreHeader); // no byte order mark for utf8
|
||||
d->encoder = new QTextConverter(codec->name());
|
||||
d->encoder->setFlags(QTextConverter::IgnoreHeader); // no byte order mark for utf8
|
||||
d->checkIfASCIICompatibleCodec();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -753,7 +753,7 @@ public:
|
|||
bool deleteDevice;
|
||||
#ifndef QT_NO_TEXTCODEC
|
||||
QTextCodec *codec;
|
||||
QTextDecoder *decoder;
|
||||
QTextConverter *decoder;
|
||||
#endif
|
||||
bool atEnd;
|
||||
|
||||
|
|
|
@ -209,7 +209,7 @@ public:
|
|||
int length;
|
||||
bool nextReturnedEndOfData;
|
||||
#ifndef QT_NO_TEXTCODEC
|
||||
QTextDecoder *encMapper;
|
||||
QTextConverter *encMapper;
|
||||
#endif
|
||||
|
||||
QByteArray encodingDeclBytes;
|
||||
|
@ -1303,7 +1303,7 @@ QString QXmlInputSource::fromRawData(const QByteArray &data, bool beginning)
|
|||
Q_ASSERT(codec);
|
||||
mib = codec->mibEnum();
|
||||
|
||||
d->encMapper = codec->makeDecoder();
|
||||
d->encMapper = new QTextConverter(codec->name());
|
||||
}
|
||||
|
||||
QString input = d->encMapper->toUnicode(data.constData(), data.size());
|
||||
|
@ -1319,7 +1319,7 @@ QString QXmlInputSource::fromRawData(const QByteArray &data, bool beginning)
|
|||
/* If the encoding is the same, we don't have to do toUnicode() all over again. */
|
||||
if(codec->mibEnum() != mib) {
|
||||
delete d->encMapper;
|
||||
d->encMapper = codec->makeDecoder();
|
||||
d->encMapper = new QTextConverter(codec->name());
|
||||
|
||||
/* The variable input can potentially be large, so we deallocate
|
||||
* it before calling toUnicode() in order to avoid having two
|
||||
|
|
Loading…
Add table
Reference in a new issue