diff options
author | Alan Alpert <alan.alpert@nokia.com> | 2010-03-17 12:19:10 (GMT) |
---|---|---|
committer | Alan Alpert <alan.alpert@nokia.com> | 2010-03-17 12:19:10 (GMT) |
commit | 63520c42a85cc4b3d7e5da6f14b6e12774274fef (patch) | |
tree | 7229b0e3bdf624f3d07906027d40085075c1aec6 /src/corelib | |
parent | 8a5cd17c49888e5b6cb230516e1722af9adba251 (diff) | |
parent | ed08d67fea713e550da0fd0542672cc4443806e2 (diff) | |
download | Qt-63520c42a85cc4b3d7e5da6f14b6e12774274fef.zip Qt-63520c42a85cc4b3d7e5da6f14b6e12774274fef.tar.gz Qt-63520c42a85cc4b3d7e5da6f14b6e12774274fef.tar.bz2 |
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt into 4.7
Conflicts:
configure.exe
src/declarative/util/qdeclarativelistmodel.cpp
tools/qml/qml.pro
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/arch/qatomic_arm.h | 4 | ||||
-rw-r--r-- | src/corelib/codecs/qtextcodec.cpp | 30 | ||||
-rw-r--r-- | src/corelib/io/qfileinfo.cpp | 51 | ||||
-rw-r--r-- | src/corelib/io/qfileinfo_p.h | 7 | ||||
-rw-r--r-- | src/corelib/io/qfsfileengine.cpp | 4 | ||||
-rw-r--r-- | src/corelib/io/qfsfileengine_p.h | 4 | ||||
-rw-r--r-- | src/corelib/io/qfsfileengine_unix.cpp | 68 | ||||
-rw-r--r-- | src/corelib/io/qfsfileengine_win.cpp | 66 | ||||
-rw-r--r-- | src/corelib/tools/qbytedata_p.h | 7 | ||||
-rw-r--r-- | src/corelib/tools/qlist.h | 64 | ||||
-rw-r--r-- | src/corelib/tools/qlocale.cpp | 2 | ||||
-rw-r--r-- | src/corelib/tools/qstring.cpp | 100 | ||||
-rw-r--r-- | src/corelib/tools/qstring.h | 6 |
13 files changed, 151 insertions, 262 deletions
diff --git a/src/corelib/arch/qatomic_arm.h b/src/corelib/arch/qatomic_arm.h index 9d7e9c6..9df02a2 100644 --- a/src/corelib/arch/qatomic_arm.h +++ b/src/corelib/arch/qatomic_arm.h @@ -108,8 +108,8 @@ Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isFetchAndAddWaitFree() // kernel places a restartable cmpxchg implementation at a fixed address extern "C" typedef int (qt_atomic_eabi_cmpxchg_int_t)(int oldval, int newval, volatile int *ptr); extern "C" typedef int (qt_atomic_eabi_cmpxchg_ptr_t)(void *oldval, void *newval, volatile void *ptr); -#define qt_atomic_eabi_cmpxchg_int (*(qt_atomic_eabi_cmpxchg_int_t *)0xffff0fc0) -#define qt_atomic_eabi_cmpxchg_ptr (*(qt_atomic_eabi_cmpxchg_ptr_t *)0xffff0fc0) +#define qt_atomic_eabi_cmpxchg_int (*reinterpret_cast<qt_atomic_eabi_cmpxchg_int_t *>(0xffff0fc0)) +#define qt_atomic_eabi_cmpxchg_ptr (*reinterpret_cast<qt_atomic_eabi_cmpxchg_ptr_t *>(0xffff0fc0)) #else diff --git a/src/corelib/codecs/qtextcodec.cpp b/src/corelib/codecs/qtextcodec.cpp index 4034218..72b0128 100644 --- a/src/corelib/codecs/qtextcodec.cpp +++ b/src/corelib/codecs/qtextcodec.cpp @@ -399,9 +399,35 @@ QString QWindowsLocalCodec::convertToUnicodeCharByChar(const char *chars, int le return s; } -QByteArray QWindowsLocalCodec::convertFromUnicode(const QChar *uc, int len, ConverterState *) const +QByteArray QWindowsLocalCodec::convertFromUnicode(const QChar *ch, int uclen, ConverterState *) const { - return qt_winQString2MB(uc, len); + if (!ch) + return QByteArray(); + if (uclen == 0) + return QByteArray(""); + BOOL used_def; + QByteArray mb(4096, 0); + int len; + while (!(len=WideCharToMultiByte(CP_ACP, 0, (const wchar_t*)ch, uclen, + mb.data(), mb.size()-1, 0, &used_def))) + { + int r = GetLastError(); + if (r == ERROR_INSUFFICIENT_BUFFER) { + mb.resize(1+WideCharToMultiByte(CP_ACP, 0, + (const wchar_t*)ch, uclen, + 0, 0, 0, &used_def)); + // and try again... + } else { +#ifndef QT_NO_DEBUG + // Fail. + qWarning("WideCharToMultiByte: Cannot convert multibyte text (error %d): %s (UTF-8)", + r, QString(ch, uclen).toLocal8Bit().data()); +#endif + break; + } + } + mb.resize(len); + return mb; } diff --git a/src/corelib/io/qfileinfo.cpp b/src/corelib/io/qfileinfo.cpp index 625098e..37591c5 100644 --- a/src/corelib/io/qfileinfo.cpp +++ b/src/corelib/io/qfileinfo.cpp @@ -41,7 +41,6 @@ #include "qplatformdefs.h" #include "qfileinfo.h" -#include "qfsfileengine_p.h" #include "qglobal.h" #include "qdir.h" #include "qfileinfo_p.h" @@ -75,50 +74,6 @@ void QFileInfoPrivate::initFileEngine(const QString &file) data->fileName = file; } -bool QFileInfoPrivate::hasAccess(Access access) const -{ - if (!(getFileFlags(QAbstractFileEngine::PermsMask - | QAbstractFileEngine::LocalDiskFlag) & QAbstractFileEngine::LocalDiskFlag)) { - switch (access) { - case ReadAccess: - return getFileFlags(QAbstractFileEngine::ReadUserPerm); - case WriteAccess: - return getFileFlags(QAbstractFileEngine::WriteUserPerm); - case ExecuteAccess: - return getFileFlags(QAbstractFileEngine::ExeUserPerm); - default: - return false; - } - } - - int mode = 0; - switch (access) { - case ReadAccess: - mode = R_OK; - break; - case WriteAccess: - mode = W_OK; - break; - case ExecuteAccess: - mode = X_OK; - break; - }; -#ifdef Q_OS_UNIX - return QT_ACCESS(QFile::encodeName(data->fileName).data(), mode) == 0; -#endif -#ifdef Q_OS_WIN - if ((access == ReadAccess && !getFileFlags(QAbstractFileEngine::ReadUserPerm)) - || (access == WriteAccess && !getFileFlags(QAbstractFileEngine::WriteUserPerm))) { - return false; - } - if (access == ExecuteAccess) - return getFileFlags(QAbstractFileEngine::ExeUserPerm); - - return ::_waccess((wchar_t*)QFSFileEnginePrivate::longFileName(data->fileName).utf16(), mode) == 0; -#endif - return false; -} - void QFileInfoPrivate::detach() { qAtomicDetach(data); @@ -893,7 +848,7 @@ bool QFileInfo::isReadable() const Q_D(const QFileInfo); if (!d->data->fileEngine) return false; - return d->hasAccess(QFileInfoPrivate::ReadAccess); + return d->getFileFlags(QAbstractFileEngine::ReadUserPerm); } /*! @@ -906,7 +861,7 @@ bool QFileInfo::isWritable() const Q_D(const QFileInfo); if (!d->data->fileEngine) return false; - return d->hasAccess(QFileInfoPrivate::WriteAccess); + return d->getFileFlags(QAbstractFileEngine::WriteUserPerm); } /*! @@ -919,7 +874,7 @@ bool QFileInfo::isExecutable() const Q_D(const QFileInfo); if (!d->data->fileEngine) return false; - return d->hasAccess(QFileInfoPrivate::ExecuteAccess); + return d->getFileFlags(QAbstractFileEngine::ExeUserPerm); } /*! diff --git a/src/corelib/io/qfileinfo_p.h b/src/corelib/io/qfileinfo_p.h index d97a0cf..306ffe1 100644 --- a/src/corelib/io/qfileinfo_p.h +++ b/src/corelib/io/qfileinfo_p.h @@ -68,13 +68,6 @@ public: void initFileEngine(const QString &); - enum Access { - ReadAccess, - WriteAccess, - ExecuteAccess - }; - bool hasAccess(Access access) const; - uint getFileFlags(QAbstractFileEngine::FileFlags) const; QDateTime &getFileTime(QAbstractFileEngine::FileTime) const; QString getFileName(QAbstractFileEngine::FileName) const; diff --git a/src/corelib/io/qfsfileengine.cpp b/src/corelib/io/qfsfileengine.cpp index 070edb4..5e14804 100644 --- a/src/corelib/io/qfsfileengine.cpp +++ b/src/corelib/io/qfsfileengine.cpp @@ -1033,6 +1033,10 @@ bool QFSFileEngine::supportsExtension(Extension extension) const to store temporary files). */ +/*! \fn QAbstractFileEngine::FileFlags QFSFileEnginePrivate::getPermissions(QAbstractFileEngine::FileFlags type) const + \internal +*/ + QT_END_NAMESPACE #endif // QT_NO_FSFILEENGINE diff --git a/src/corelib/io/qfsfileengine_p.h b/src/corelib/io/qfsfileengine_p.h index 0f63eb8..d07c3a0 100644 --- a/src/corelib/io/qfsfileengine_p.h +++ b/src/corelib/io/qfsfileengine_p.h @@ -156,9 +156,7 @@ protected: void init(); -#if defined(Q_OS_WIN32) || defined(Q_OS_WINCE) - QAbstractFileEngine::FileFlags getPermissions() const; -#endif + QAbstractFileEngine::FileFlags getPermissions(QAbstractFileEngine::FileFlags type) const; }; QT_END_NAMESPACE diff --git a/src/corelib/io/qfsfileengine_unix.cpp b/src/corelib/io/qfsfileengine_unix.cpp index 1331f54..6df00d6 100644 --- a/src/corelib/io/qfsfileengine_unix.cpp +++ b/src/corelib/io/qfsfileengine_unix.cpp @@ -736,6 +736,46 @@ static bool _q_isMacHidden(const QString &path) } #endif +QAbstractFileEngine::FileFlags QFSFileEnginePrivate::getPermissions(QAbstractFileEngine::FileFlags type) const +{ + QAbstractFileEngine::FileFlags ret = 0; + + if (st.st_mode & S_IRUSR) + ret |= QAbstractFileEngine::ReadOwnerPerm; + if (st.st_mode & S_IWUSR) + ret |= QAbstractFileEngine::WriteOwnerPerm; + if (st.st_mode & S_IXUSR) + ret |= QAbstractFileEngine::ExeOwnerPerm; + if (st.st_mode & S_IRGRP) + ret |= QAbstractFileEngine::ReadGroupPerm; + if (st.st_mode & S_IWGRP) + ret |= QAbstractFileEngine::WriteGroupPerm; + if (st.st_mode & S_IXGRP) + ret |= QAbstractFileEngine::ExeGroupPerm; + if (st.st_mode & S_IROTH) + ret |= QAbstractFileEngine::ReadOtherPerm; + if (st.st_mode & S_IWOTH) + ret |= QAbstractFileEngine::WriteOtherPerm; + if (st.st_mode & S_IXOTH) + ret |= QAbstractFileEngine::ExeOtherPerm; + + // calculate user permissions + if (type & QAbstractFileEngine::ReadUserPerm) { + if (QT_ACCESS(nativeFilePath.constData(), R_OK) == 0) + ret |= QAbstractFileEngine::ReadUserPerm; + } + if (type & QAbstractFileEngine::WriteUserPerm) { + if (QT_ACCESS(nativeFilePath.constData(), W_OK) == 0) + ret |= QAbstractFileEngine::WriteUserPerm; + } + if (type & QAbstractFileEngine::ExeUserPerm) { + if (QT_ACCESS(nativeFilePath.constData(), X_OK) == 0) + ret |= QAbstractFileEngine::ExeUserPerm; + } + + return ret; +} + /*! \reimp */ @@ -755,32 +795,8 @@ QAbstractFileEngine::FileFlags QFSFileEngine::fileFlags(FileFlags type) const if (!exists && !d->isSymlink()) return ret; - if (exists && (type & PermsMask)) { - if (d->st.st_mode & S_IRUSR) - ret |= ReadOwnerPerm; - if (d->st.st_mode & S_IWUSR) - ret |= WriteOwnerPerm; - if (d->st.st_mode & S_IXUSR) - ret |= ExeOwnerPerm; - if (d->st.st_mode & S_IRUSR) - ret |= ReadUserPerm; - if (d->st.st_mode & S_IWUSR) - ret |= WriteUserPerm; - if (d->st.st_mode & S_IXUSR) - ret |= ExeUserPerm; - if (d->st.st_mode & S_IRGRP) - ret |= ReadGroupPerm; - if (d->st.st_mode & S_IWGRP) - ret |= WriteGroupPerm; - if (d->st.st_mode & S_IXGRP) - ret |= ExeGroupPerm; - if (d->st.st_mode & S_IROTH) - ret |= ReadOtherPerm; - if (d->st.st_mode & S_IWOTH) - ret |= WriteOtherPerm; - if (d->st.st_mode & S_IXOTH) - ret |= ExeOtherPerm; - } + if (exists && (type & PermsMask)) + ret |= d->getPermissions(type); if (type & TypesMask) { #if !defined(QWS) && defined(Q_OS_MAC) bool foundAlias = false; diff --git a/src/corelib/io/qfsfileengine_win.cpp b/src/corelib/io/qfsfileengine_win.cpp index d8b1c03..8d34486 100644 --- a/src/corelib/io/qfsfileengine_win.cpp +++ b/src/corelib/io/qfsfileengine_win.cpp @@ -1405,10 +1405,7 @@ bool QFSFileEngine::link(const QString &newName) #endif // Q_OS_WINCE } -/*! - \internal -*/ -QAbstractFileEngine::FileFlags QFSFileEnginePrivate::getPermissions() const +QAbstractFileEngine::FileFlags QFSFileEnginePrivate::getPermissions(QAbstractFileEngine::FileFlags type) const { QAbstractFileEngine::FileFlags ret = 0; @@ -1429,7 +1426,7 @@ QAbstractFileEngine::FileFlags QFSFileEnginePrivate::getPermissions() const if(res == ERROR_SUCCESS) { ACCESS_MASK access_mask; TRUSTEE_W trustee; - { //user + if (type & 0x0700) { // user if(ptrGetEffectiveRightsFromAclW(pDacl, ¤tUserTrusteeW, &access_mask) != ERROR_SUCCESS) access_mask = (ACCESS_MASK)-1; if(access_mask & ReadMask) @@ -1439,7 +1436,7 @@ QAbstractFileEngine::FileFlags QFSFileEnginePrivate::getPermissions() const if(access_mask & ExecMask) ret |= QAbstractFileEngine::ExeUserPerm; } - { //owner + if (type & 0x7000) { // owner ptrBuildTrusteeWithSidW(&trustee, pOwner); if(ptrGetEffectiveRightsFromAclW(pDacl, &trustee, &access_mask) != ERROR_SUCCESS) access_mask = (ACCESS_MASK)-1; @@ -1450,7 +1447,7 @@ QAbstractFileEngine::FileFlags QFSFileEnginePrivate::getPermissions() const if(access_mask & ExecMask) ret |= QAbstractFileEngine::ExeOwnerPerm; } - { //group + if (type & 0x0070) { // group ptrBuildTrusteeWithSidW(&trustee, pGroup); if(ptrGetEffectiveRightsFromAclW(pDacl, &trustee, &access_mask) != ERROR_SUCCESS) access_mask = (ACCESS_MASK)-1; @@ -1461,7 +1458,7 @@ QAbstractFileEngine::FileFlags QFSFileEnginePrivate::getPermissions() const if(access_mask & ExecMask) ret |= QAbstractFileEngine::ExeGroupPerm; } - { //other (world) + if (type & 0x0007) { // other (world) if(ptrGetEffectiveRightsFromAclW(pDacl, &worldTrusteeW, &access_mask) != ERROR_SUCCESS) access_mask = (ACCESS_MASK)-1; // ### if(access_mask & ReadMask) @@ -1476,29 +1473,35 @@ QAbstractFileEngine::FileFlags QFSFileEnginePrivate::getPermissions() const } } else #endif - { + { //### what to do with permissions if we don't use NTFS // for now just add all permissions and what about exe missions ?? // also qt_ntfs_permission_lookup is now not set by default ... should it ? - ret |= QAbstractFileEngine::ReadOtherPerm | QAbstractFileEngine::ReadGroupPerm - | QAbstractFileEngine::ReadOwnerPerm | QAbstractFileEngine::ReadUserPerm - | QAbstractFileEngine::WriteUserPerm | QAbstractFileEngine::WriteOwnerPerm - | QAbstractFileEngine::WriteGroupPerm | QAbstractFileEngine::WriteOtherPerm; - - if (doStat()) { - if (ret & (QAbstractFileEngine::WriteOwnerPerm | QAbstractFileEngine::WriteUserPerm | - QAbstractFileEngine::WriteGroupPerm | QAbstractFileEngine::WriteOtherPerm)) { - if (fileAttrib & FILE_ATTRIBUTE_READONLY) - ret &= ~(QAbstractFileEngine::WriteOwnerPerm | QAbstractFileEngine::WriteUserPerm | - QAbstractFileEngine::WriteGroupPerm | QAbstractFileEngine::WriteOtherPerm); - } + ret |= QAbstractFileEngine::ReadOwnerPerm | QAbstractFileEngine::ReadGroupPerm + | QAbstractFileEngine::ReadOtherPerm; - QString fname = filePath.endsWith(QLatin1String(".lnk")) ? readLink(filePath) : filePath; - QString ext = fname.right(4).toLower(); - if (ext == QLatin1String(".exe") || ext == QLatin1String(".com") || ext == QLatin1String(".bat") || - ext == QLatin1String(".pif") || ext == QLatin1String(".cmd") || (fileAttrib & FILE_ATTRIBUTE_DIRECTORY)) - ret |= QAbstractFileEngine::ExeOwnerPerm | QAbstractFileEngine::ExeGroupPerm | - QAbstractFileEngine::ExeOtherPerm | QAbstractFileEngine::ExeUserPerm; + if (!(fileAttrib & FILE_ATTRIBUTE_READONLY)) { + ret |= QAbstractFileEngine::WriteOwnerPerm | QAbstractFileEngine::WriteGroupPerm + | QAbstractFileEngine::WriteOtherPerm; + } + + QString fname = filePath.endsWith(QLatin1String(".lnk")) ? readLink(filePath) : filePath; + QString ext = fname.right(4).toLower(); + if ((fileAttrib & FILE_ATTRIBUTE_DIRECTORY) || + ext == QLatin1String(".exe") || ext == QLatin1String(".com") || ext == QLatin1String(".bat") || + ext == QLatin1String(".pif") || ext == QLatin1String(".cmd")) { + ret |= QAbstractFileEngine::ExeOwnerPerm | QAbstractFileEngine::ExeGroupPerm + | QAbstractFileEngine::ExeOtherPerm | QAbstractFileEngine::ExeUserPerm; + } + + // calculate user permissions + if (type & QAbstractFileEngine::ReadUserPerm) { + if (::_waccess((wchar_t*)longFileName(fname).utf16(), R_OK) == 0) + ret |= QAbstractFileEngine::ReadUserPerm; + } + if (type & QAbstractFileEngine::WriteUserPerm) { + if (::_waccess((wchar_t*)longFileName(fname).utf16(), W_OK) == 0) + ret |= QAbstractFileEngine::WriteUserPerm; } } return ret; @@ -1555,13 +1558,10 @@ QAbstractFileEngine::FileFlags QFSFileEngine::fileFlags(QAbstractFileEngine::Fil } if (type & PermsMask) { - ret |= d->getPermissions(); - // ### Workaround pascals ### above. Since we always set all properties to true - // we need to disable read and exec access if the file does not exists - if (d->doStat()) + if (d->doStat()) { ret |= ExistsFlag; - else - ret &= 0x2222; + ret |= d->getPermissions(type); + } } if (type & TypesMask) { if (d->filePath.endsWith(QLatin1String(".lnk"))) { diff --git a/src/corelib/tools/qbytedata_p.h b/src/corelib/tools/qbytedata_p.h index 9aad6a9..c48bb33 100644 --- a/src/corelib/tools/qbytedata_p.h +++ b/src/corelib/tools/qbytedata_p.h @@ -206,6 +206,13 @@ public: { return buffers[i]; } + + inline bool canReadLine() const { + for (int i = 0; i < buffers.length(); i++) + if (buffers.at(i).contains('\n')) + return true; + return false; + } }; QT_END_NAMESPACE diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index c6dd106..67f63f3 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -98,25 +98,6 @@ struct Q_CORE_EXPORT QListData { inline void **end() const { return d->array + d->end; } }; -////////////////////////////////////////////////////////////////////////////////// -// -// QtPodForSize and QtPodForType are internal and may change or go away any time. -// We mean it. -// -////////////////////////////////////////////////////////////////////////////////// -template <int N> struct QtPodForSize { - // This base type is rather obviously broken and cannot be made - // working due to alignment constraints. - // This doesn't matter as far as QList is concerned, as we are - // using this type only for QTypeInfo<T>::isLarge == false. - typedef struct { } Type; -}; -template <> struct QtPodForSize<1> { typedef quint8 Type; }; -template <> struct QtPodForSize<2> { typedef quint16 Type; }; -template <> struct QtPodForSize<4> { typedef quint32 Type; }; -template <> struct QtPodForSize<8> { typedef quint64 Type; }; -template <class T> struct QtPodForType : QtPodForSize<sizeof(T)> { }; - template <typename T> class QList { @@ -377,7 +358,15 @@ Q_INLINE_TEMPLATE void QList<T>::node_construct(Node *n, const T &t) { if (QTypeInfo<T>::isLarge || QTypeInfo<T>::isStatic) n->v = new T(t); else if (QTypeInfo<T>::isComplex) new (n) T(t); +#if (defined(__GNUC__) || defined(__INTEL_COMPILER) || defined(__IBMCPP__)) && !defined(__OPTIMIZE__) + // This violates pointer aliasing rules, but it is known to be safe (and silent) + // in unoptimized GCC builds (-fno-strict-aliasing). The other compilers which + // set the same define are assumed to be safe. else *reinterpret_cast<T*>(n) = t; +#else + // This is always safe, but penaltizes unoptimized builds a lot. + else ::memcpy(n, &t, sizeof(T)); +#endif } template <typename T> @@ -521,16 +510,15 @@ Q_OUTOFLINE_TEMPLATE void QList<T>::append(const T &t) QT_RETHROW; } } else { - typedef typename QtPodForType<T>::Type PodNode; - PodNode cpy = *reinterpret_cast<const PodNode *>(&t); - Node *n = reinterpret_cast<Node *>(p.append()); + Node *n, copy; + node_construct(©, t); // t might be a reference to an object in the array QT_TRY { - void *ptr = &cpy; - node_construct(n, *reinterpret_cast<T *>(ptr)); + n = reinterpret_cast<Node *>(p.append());; } QT_CATCH(...) { - --d->end; + node_destruct(©); QT_RETHROW; } + *n = copy; } } } @@ -556,16 +544,15 @@ inline void QList<T>::prepend(const T &t) QT_RETHROW; } } else { - typedef typename QtPodForType<T>::Type PodNode; - PodNode cpy = *reinterpret_cast<const PodNode *>(&t); - Node *n = reinterpret_cast<Node *>(p.prepend()); + Node *n, copy; + node_construct(©, t); // t might be a reference to an object in the array QT_TRY { - void *ptr = &cpy; - node_construct(n, *reinterpret_cast<T *>(ptr)); + n = reinterpret_cast<Node *>(p.prepend());; } QT_CATCH(...) { - ++d->begin; + node_destruct(©); QT_RETHROW; } + *n = copy; } } } @@ -591,16 +578,15 @@ inline void QList<T>::insert(int i, const T &t) QT_RETHROW; } } else { - typedef typename QtPodForType<T>::Type PodNode; - PodNode cpy = *reinterpret_cast<const PodNode *>(&t); - Node *n = reinterpret_cast<Node *>(p.insert(i)); + Node *n, copy; + node_construct(©, t); // t might be a reference to an object in the array QT_TRY { - void *ptr = &cpy; - node_construct(n, *reinterpret_cast<T *>(ptr)); + n = reinterpret_cast<Node *>(p.insert(i));; } QT_CATCH(...) { - p.remove(i); + node_destruct(©); QT_RETHROW; } + *n = copy; } } } @@ -636,12 +622,10 @@ inline void QList<T>::move(int from, int to) template<typename T> Q_OUTOFLINE_TEMPLATE QList<T> QList<T>::mid(int pos, int alength) const { - if (alength < 0) + if (alength < 0 || pos + alength > size()) alength = size() - pos; if (pos == 0 && alength == size()) return *this; - if (pos + alength > size()) - alength = size() - pos; QList<T> cpy; cpy.reserve(alength); cpy.d->end = alength; diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index 84bc154..1966a79 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -3147,7 +3147,7 @@ QString QLocale::toString(double i, char f, int prec) const On Windows and Mac, this locale will use the decimal/grouping characters and date/time formats specified in the system configuration panel. - \sa QTextCodec::locale() c() + \sa c() */ QLocale QLocale::system() diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index b54315c..464e77b 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -3827,100 +3827,6 @@ const char *QString::latin1_helper() const #endif -QT_END_NAMESPACE - -#if defined(Q_OS_WIN32) || defined(Q_OS_WINCE) -#include "qt_windows.h" - -QT_BEGIN_NAMESPACE - -QByteArray qt_winQString2MB(const QString& s, int uclen) -{ - if (uclen < 0) - uclen = s.length(); - if (s.isNull()) - return QByteArray(); - if (uclen == 0) - return QByteArray(""); - return qt_winQString2MB(s.constData(), uclen); -} - -QByteArray qt_winQString2MB(const QChar *ch, int uclen) -{ - if (!ch) - return QByteArray(); - if (uclen == 0) - return QByteArray(""); - BOOL used_def; - QByteArray mb(4096, 0); - int len; - while (!(len=WideCharToMultiByte(CP_ACP, 0, (const wchar_t*)ch, uclen, - mb.data(), mb.size()-1, 0, &used_def))) - { - int r = GetLastError(); - if (r == ERROR_INSUFFICIENT_BUFFER) { - mb.resize(1+WideCharToMultiByte(CP_ACP, 0, - (const wchar_t*)ch, uclen, - 0, 0, 0, &used_def)); - // and try again... - } else { -#ifndef QT_NO_DEBUG - // Fail. - qWarning("WideCharToMultiByte: Cannot convert multibyte text (error %d): %s (UTF-8)", - r, QString(ch, uclen).toLocal8Bit().data()); -#endif - break; - } - } - mb.resize(len); - return mb; -} - -QString qt_winMB2QString(const char *mb, int mblen) -{ - if (!mb || !mblen) - return QString(); - const int wclen_auto = 4096; - wchar_t wc_auto[wclen_auto]; - int wclen = wclen_auto; - wchar_t *wc = wc_auto; - int len; - while (!(len=MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, - mb, mblen, wc, wclen))) - { - int r = GetLastError(); - if (r == ERROR_INSUFFICIENT_BUFFER) { - if (wc != wc_auto) { - qWarning("MultiByteToWideChar: Size changed"); - break; - } else { - wclen = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, - mb, mblen, 0, 0); - wc = new wchar_t[wclen]; - // and try again... - } - } else { - // Fail. - qWarning("MultiByteToWideChar: Cannot convert multibyte text"); - break; - } - } - if (len <= 0) - return QString(); - if (wc[len-1] == 0) // len - 1: we don't want terminator - --len; - QString s((QChar*)wc, len); - if (wc != wc_auto) - delete [] wc; - return s; -} - -QT_END_NAMESPACE - -#endif // Q_OS_WIN32 - -QT_BEGIN_NAMESPACE - /*! Returns a QString initialized with the first \a size characters of the 8-bit string \a str. @@ -4815,6 +4721,12 @@ int QString::localeAwareCompare(const QString &other) const return localeAwareCompare_helper(constData(), length(), other.constData(), other.length()); } +#if defined(Q_OS_WIN32) || defined(Q_OS_WINCE) +QT_END_NAMESPACE +#include "qt_windows.h" +QT_BEGIN_NAMESPACE +#endif + /*! \internal \since 4.5 diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index a59c0bd..ea12c2f 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -1096,12 +1096,6 @@ Q_DECLARE_TYPEINFO(QString, Q_MOVABLE_TYPE); Q_DECLARE_SHARED(QString) Q_DECLARE_OPERATORS_FOR_FLAGS(QString::SectionFlags) -#if defined(Q_OS_WIN32) || defined(Q_OS_WINCE) -extern Q_CORE_EXPORT QByteArray qt_winQString2MB(const QString& s, int len=-1); -extern Q_CORE_EXPORT QByteArray qt_winQString2MB(const QChar *ch, int len); -extern Q_CORE_EXPORT QString qt_winMB2QString(const char* mb, int len=-1); -#endif - class Q_CORE_EXPORT QStringRef { const QString *m_string; |