From 8c10255e377c38a8655c733dc527674b1f5cb3da Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 23 Jan 2019 16:31:35 +0100 Subject: Add conversion to and from long and ulong This implements conversion parity with QString, which can convert to and from long and unsigned long. The implementation simply forwards to existing long long overloads or uses the existing helpers, so just as for the conversion to/from int or short, no additional test cases were added. Change-Id: I37ef06d9ce4d80d98bd72720353996bac723e09c Fixes: QTBUG-782 Reviewed-by: Volker Hilsheimer (cherry picked from commit 783953f09dcfe9c58dc991394535ba07dabe2560) Reviewed-by: Edward Welbourne --- src/corelib/tools/qlocale.cpp | 126 +++++++++++++++++++++++++++++++++++++++++ src/corelib/tools/qlocale.h | 12 ++++ src/corelib/tools/qlocale.qdoc | 24 ++++++++ 3 files changed, 162 insertions(+) (limited to 'src/corelib') diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index b3fb079342..ebb6c97975 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -1332,6 +1332,48 @@ uint QLocale::toUInt(const QString &s, bool *ok) const return toIntegral_helper(d, s, ok); } +/*! + Returns the long int represented by the localized string \a s. + + If the conversion fails the function returns 0. + + If \a ok is not \c nullptr, failure is reported by setting *\a{ok} + to \c false, and success by setting *\a{ok} to \c true. + + This function ignores leading and trailing whitespace. + + \sa toInt(), toULong(), toDouble(), toString() + + \since 5.13 + */ + + +long QLocale::toLong(const QString &s, bool *ok) const +{ + return toIntegral_helper(d, s, ok); +} + +/*! + Returns the unsigned long int represented by the localized + string \a s. + + If the conversion fails the function returns 0. + + If \a ok is not \c nullptr, failure is reported by setting *\a{ok} + to \c false, and success by setting *\a{ok} to \c true. + + This function ignores leading and trailing whitespace. + + \sa toLong(), toInt(), toDouble(), toString() + + \since 5.13 +*/ + +ulong QLocale::toULong(const QString &s, bool *ok) const +{ + return toIntegral_helper(d, s, ok); +} + /*! Returns the long long int represented by the localized string \a s. @@ -1499,6 +1541,48 @@ uint QLocale::toUInt(const QStringRef &s, bool *ok) const return toIntegral_helper(d, s, ok); } +/*! + Returns the long int represented by the localized string \a s. + + If the conversion fails the function returns 0. + + If \a ok is not \c nullptr, failure is reported by setting *\a{ok} + to \c false, and success by setting *\a{ok} to \c true. + + This function ignores leading and trailing whitespace. + + \sa toInt(), toULong(), toDouble(), toString() + + \since 5.13 + */ + + +long QLocale::toLong(const QStringRef &s, bool *ok) const +{ + return toIntegral_helper(d, s, ok); +} + +/*! + Returns the unsigned long int represented by the localized + string \a s. + + If the conversion fails the function returns 0. + + If \a ok is not \c nullptr, failure is reported by setting *\a{ok} + to \c false, and success by setting *\a{ok} to \c true. + + This function ignores leading and trailing whitespace. + + \sa toLong(), toInt(), toDouble(), toString() + + \since 5.13 + */ + +ulong QLocale::toULong(const QStringRef &s, bool *ok) const +{ + return toIntegral_helper(d, s, ok); +} + /*! Returns the long long int represented by the localized string \a s. @@ -1675,6 +1759,48 @@ uint QLocale::toUInt(QStringView s, bool *ok) const return toIntegral_helper(d, s, ok); } +/*! + Returns the long int represented by the localized string \a s. + + If the conversion fails the function returns 0. + + If \a ok is not \c nullptr, failure is reported by setting *\a{ok} + to \c false, and success by setting *\a{ok} to \c true. + + This function ignores leading and trailing whitespace. + + \sa toInt(), toULong(), toDouble(), toString() + + \since 5.13 + */ + + +long QLocale::toLong(QStringView s, bool *ok) const +{ + return toIntegral_helper(d, s, ok); +} + +/*! + Returns the unsigned long int represented by the localized + string \a s. + + If the conversion fails the function returns 0. + + If \a ok is not \c nullptr, failure is reported by setting *\a{ok} + to \c false, and success by setting *\a{ok} to \c true. + + This function ignores leading and trailing whitespace. + + \sa toLong(), toInt(), toDouble(), toString() + + \since 5.13 + */ + +ulong QLocale::toULong(QStringView s, bool *ok) const +{ + return toIntegral_helper(d, s, ok); +} + /*! Returns the long long int represented by the localized string \a s. diff --git a/src/corelib/tools/qlocale.h b/src/corelib/tools/qlocale.h index 1fbd96c6d5..2b4f131552 100644 --- a/src/corelib/tools/qlocale.h +++ b/src/corelib/tools/qlocale.h @@ -961,6 +961,8 @@ public: ushort toUShort(const QString &s, bool *ok = nullptr) const; int toInt(const QString &s, bool *ok = nullptr) const; uint toUInt(const QString &s, bool *ok = nullptr) const; + long toLong(const QString &s, bool *ok = nullptr) const; + ulong toULong(const QString &s, bool *ok = nullptr) const; qlonglong toLongLong(const QString &s, bool *ok = nullptr) const; qulonglong toULongLong(const QString &s, bool *ok = nullptr) const; float toFloat(const QString &s, bool *ok = nullptr) const; @@ -970,6 +972,8 @@ public: ushort toUShort(const QStringRef &s, bool *ok = nullptr) const; int toInt(const QStringRef &s, bool *ok = nullptr) const; uint toUInt(const QStringRef &s, bool *ok = nullptr) const; + long toLong(const QStringRef &s, bool *ok = nullptr) const; + ulong toULong(const QStringRef &s, bool *ok = nullptr) const; qlonglong toLongLong(const QStringRef &s, bool *ok = nullptr) const; qulonglong toULongLong(const QStringRef &s, bool *ok = nullptr) const; float toFloat(const QStringRef &s, bool *ok = nullptr) const; @@ -980,6 +984,8 @@ public: ushort toUShort(QStringView s, bool *ok = nullptr) const; int toInt(QStringView s, bool *ok = nullptr) const; uint toUInt(QStringView s, bool *ok = nullptr) const; + long toLong(QStringView s, bool *ok = nullptr) const; + ulong toULong(QStringView s, bool *ok = nullptr) const; qlonglong toLongLong(QStringView s, bool *ok = nullptr) const; qulonglong toULongLong(QStringView s, bool *ok = nullptr) const; float toFloat(QStringView s, bool *ok = nullptr) const; @@ -987,6 +993,8 @@ public: QString toString(qlonglong i) const; QString toString(qulonglong i) const; + inline QString toString(long i) const; + inline QString toString(ulong i) const; inline QString toString(short i) const; inline QString toString(ushort i) const; inline QString toString(int i) const; @@ -1107,6 +1115,10 @@ private: Q_DECLARE_SHARED(QLocale) Q_DECLARE_OPERATORS_FOR_FLAGS(QLocale::NumberOptions) +inline QString QLocale::toString(long i) const + { return toString(qlonglong(i)); } +inline QString QLocale::toString(ulong i) const + { return toString(qulonglong(i)); } inline QString QLocale::toString(short i) const { return toString(qlonglong(i)); } inline QString QLocale::toString(ushort i) const diff --git a/src/corelib/tools/qlocale.qdoc b/src/corelib/tools/qlocale.qdoc index b852c10b8d..91b0ab6442 100644 --- a/src/corelib/tools/qlocale.qdoc +++ b/src/corelib/tools/qlocale.qdoc @@ -1163,6 +1163,30 @@ currency string. */ +/*! +\fn QString QLocale::toString(long i) const + +\overload + +\sa toLong() +*/ + +/*! +\fn QString QLocale::toString(ulong i) const + +\overload + +\sa toULong() +*/ + +/*! +\fn QString QLocale::toString(ushort i) const + +\overload + +\sa toUShort() +*/ + /*! \fn QString QLocale::toString(short i) const -- cgit v1.2.3 From a2b31cd5db6410144a613142a7b60f0cd2ba2b1d Mon Sep 17 00:00:00 2001 From: Kirill Burtsev Date: Tue, 19 Feb 2019 15:21:58 +0100 Subject: Fix build for size with gcc Fixes the error: variable 'isDifferent' set but not used Change-Id: Ibd60b17126057da64a41d325b7ef548316f27c4b Reviewed-by: Edward Welbourne Reviewed-by: Thiago Macieira --- src/corelib/tools/qstring.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/corelib') diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index 63d44eb39c..d8bfb69a8b 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -1047,6 +1047,7 @@ static int ucstrncmp(const QChar *a, const uchar *c, size_t l) __m128i nullmask = _mm_setzero_si128(); qptrdiff offset = 0; +# if !defined(__OPTIMIZE_SIZE__) // Using the PMOVMSKB instruction, we get two bits for each character // we compare. int retval; @@ -1059,6 +1060,7 @@ static int ucstrncmp(const QChar *a, const uchar *c, size_t l) retval = uc[offset + idx / 2] - c[offset + idx / 2]; return true; }; +# endif // we're going to read uc[offset..offset+15] (32 bytes) // and c[offset..offset+15] (16 bytes) -- cgit v1.2.3 From b56cfce73288263624f490c06215fad1026297b4 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 14 Feb 2019 11:03:17 -0800 Subject: Make the qfloat16tables.cpp depend on the executable, not the command qtPrepareTool could return a more complex command-line in the variable, for some reason. So declare the dependency on the actual executable only. Change-Id: Id061f35c088044b69a15fffd1583504f25936a7a Reviewed-by: Oswald Buddenhagen Reviewed-by: Joerg Bornemann --- src/corelib/global/global.pri | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/corelib') diff --git a/src/corelib/global/global.pri b/src/corelib/global/global.pri index a4d132a4f4..029357ff43 100644 --- a/src/corelib/global/global.pri +++ b/src/corelib/global/global.pri @@ -131,7 +131,7 @@ qtPrepareTool(QMAKE_QFLOAT16_TABLES, qfloat16-tables) qfloat16_tables.commands = $$QMAKE_QFLOAT16_TABLES ${QMAKE_FILE_OUT} qfloat16_tables.output = global/qfloat16tables.cpp -qfloat16_tables.depends = $$QMAKE_QFLOAT16_TABLES +qfloat16_tables.depends = $$QMAKE_QFLOAT16_TABLES_EXE qfloat16_tables.input = QMAKE_QFLOAT16_TABLES_GENERATE qfloat16_tables.variable_out = SOURCES QMAKE_EXTRA_COMPILERS += qfloat16_tables -- cgit v1.2.3 From 85b0ce8ca36d52db71b519ee8d2a1ce369c53a81 Mon Sep 17 00:00:00 2001 From: Robert Loehning Date: Mon, 25 Feb 2019 13:54:26 +0100 Subject: Fix can not -> cannot Change-Id: Ie9992f67ca59aff662a4be046ace08640e7c2714 Reviewed-by: Paul Wicking --- src/corelib/Qt5CoreMacros.cmake | 2 +- src/corelib/global/qlogging.cpp | 2 +- src/corelib/io/qiodevice.cpp | 2 +- src/corelib/itemmodels/qabstractitemmodel.cpp | 4 ++-- src/corelib/itemmodels/qidentityproxymodel.cpp | 2 +- src/corelib/kernel/qcore_mac_objc.mm | 2 +- src/corelib/kernel/qeventdispatcher_unix.cpp | 2 +- src/corelib/kernel/qobject.cpp | 2 +- src/corelib/tools/qarraydata.cpp | 2 +- src/corelib/tools/qsharedpointer.cpp | 2 +- 10 files changed, 11 insertions(+), 11 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/Qt5CoreMacros.cmake b/src/corelib/Qt5CoreMacros.cmake index 620795d2cf..a7b579165c 100644 --- a/src/corelib/Qt5CoreMacros.cmake +++ b/src/corelib/Qt5CoreMacros.cmake @@ -370,7 +370,7 @@ if (NOT CMAKE_VERSION VERSION_LESS 2.8.9) if (NOT Qt5${_module}_FOUND) find_package(Qt5${_module} PATHS "${_Qt5_COMPONENT_PATH}" NO_DEFAULT_PATH) if (NOT Qt5${_module}_FOUND) - message(FATAL_ERROR "Can not use \"${_module}\" module which has not yet been found.") + message(FATAL_ERROR "Cannot use \"${_module}\" module which has not yet been found.") endif() endif() target_link_libraries(${_target} ${_qt5_link_type} ${Qt5${_module}_LIBRARIES}) diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp index 168934c202..b2093101fa 100644 --- a/src/corelib/global/qlogging.cpp +++ b/src/corelib/global/qlogging.cpp @@ -239,7 +239,7 @@ static bool systemHasStderr() \note Qt Creator does not implement a pseudo TTY, nor does it launch apps with the override environment variable set, but it will read stderr and print it to - the user, so in effect this function can not be used to conclude that stderr + the user, so in effect this function cannot be used to conclude that stderr output will _not_ be visible to the user, as even if this function returns false, the output might still end up visible to the user. For this reason, we don't guard the stderr output in the default message handler with stderrHasConsoleAttached(). diff --git a/src/corelib/io/qiodevice.cpp b/src/corelib/io/qiodevice.cpp index 86e21f0a66..74df0f71ef 100644 --- a/src/corelib/io/qiodevice.cpp +++ b/src/corelib/io/qiodevice.cpp @@ -194,7 +194,7 @@ QIODevicePrivate::~QIODevicePrivate() QIODevice provides both a common implementation and an abstract interface for devices that support reading and writing of blocks of data, such as QFile, QBuffer and QTcpSocket. QIODevice is - abstract and can not be instantiated, but it is common to use the + abstract and cannot be instantiated, but it is common to use the interface it defines to provide device-independent I/O features. For example, Qt's XML classes operate on a QIODevice pointer, allowing them to be used with various devices (such as files and diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp index 75e13ff994..abd86f2b49 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.cpp +++ b/src/corelib/itemmodels/qabstractitemmodel.cpp @@ -2329,7 +2329,7 @@ QModelIndex QAbstractItemModel::buddy(const QModelIndex &index) const The way the search is performed is defined by the \a flags given. The list that is returned may be empty. Note also that the order of results in the list may not correspond to the order in the model, if for example a proxy - model is used. The order of the results can not be relied upon. + model is used. The order of the results cannot be relied upon. The search begins from the \a start index, and continues until the number of matching data items equals \a hits, the search reaches the last row, or @@ -2903,7 +2903,7 @@ bool QAbstractItemModelPrivate::allowMove(const QModelIndex &srcParent, int star Note that other rows may be displaced accordingly. Note also that when moving items within the same parent you should not attempt invalid or no-op moves. In - the above example, item 2 is at row 2 before the move, so it can not be moved + the above example, item 2 is at row 2 before the move, so it cannot be moved to row 2 (where it is already) or row 3 (no-op as row 3 means above row 3, where it is already) diff --git a/src/corelib/itemmodels/qidentityproxymodel.cpp b/src/corelib/itemmodels/qidentityproxymodel.cpp index bb92857786..39992eccd3 100644 --- a/src/corelib/itemmodels/qidentityproxymodel.cpp +++ b/src/corelib/itemmodels/qidentityproxymodel.cpp @@ -95,7 +95,7 @@ class QIdentityProxyModelPrivate : public QAbstractProxyModelPrivate need to implement all data handling in the same class that creates the structure of the model, and can also be used to create re-usable components. - This also provides a way to change the data in the case where a source model is supplied by a third party which can not be modified. + This also provides a way to change the data in the case where a source model is supplied by a third party which cannot be modified. \snippet code/src_gui_itemviews_qidentityproxymodel.cpp 0 diff --git a/src/corelib/kernel/qcore_mac_objc.mm b/src/corelib/kernel/qcore_mac_objc.mm index 4550891e2a..6687eb88a5 100644 --- a/src/corelib/kernel/qcore_mac_objc.mm +++ b/src/corelib/kernel/qcore_mac_objc.mm @@ -501,7 +501,7 @@ void qt_apple_check_os_version() if (!applicationName) applicationName = NSProcessInfo.processInfo.processName; - fprintf(stderr, "Sorry, \"%s\" can not be run on this version of %s. " + fprintf(stderr, "Sorry, \"%s\" cannot be run on this version of %s. " "Qt requires %s %ld.%ld.%ld or later, you have %s %ld.%ld.%ld.\n", applicationName.UTF8String, os, os, long(required.majorVersion), long(required.minorVersion), long(required.patchVersion), diff --git a/src/corelib/kernel/qeventdispatcher_unix.cpp b/src/corelib/kernel/qeventdispatcher_unix.cpp index 535f86fefe..df0cac0239 100644 --- a/src/corelib/kernel/qeventdispatcher_unix.cpp +++ b/src/corelib/kernel/qeventdispatcher_unix.cpp @@ -225,7 +225,7 @@ int QThreadPipe::check(const pollfd &pfd) QEventDispatcherUNIXPrivate::QEventDispatcherUNIXPrivate() { if (Q_UNLIKELY(threadPipe.init() == false)) - qFatal("QEventDispatcherUNIXPrivate(): Can not continue without a thread pipe"); + qFatal("QEventDispatcherUNIXPrivate(): Cannot continue without a thread pipe"); } QEventDispatcherUNIXPrivate::~QEventDispatcherUNIXPrivate() diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index 77f507ff3f..e67b2306c2 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -2152,7 +2152,7 @@ void QObject::removeEventFilter(QObject *obj) This signal is emitted immediately before the object \a obj is destroyed, after any instances of QPointer have been notified, - and can not be blocked. + and cannot be blocked. All the objects's children are destroyed immediately after this signal is emitted. diff --git a/src/corelib/tools/qarraydata.cpp b/src/corelib/tools/qarraydata.cpp index a04536b18b..a91d833e3b 100644 --- a/src/corelib/tools/qarraydata.cpp +++ b/src/corelib/tools/qarraydata.cpp @@ -163,7 +163,7 @@ void QArrayData::deallocate(QArrayData *data, size_t objectSize, #endif Q_ASSERT_X(data == 0 || !data->ref.isStatic(), "QArrayData::deallocate", - "Static data can not be deleted"); + "Static data cannot be deleted"); ::free(data); } diff --git a/src/corelib/tools/qsharedpointer.cpp b/src/corelib/tools/qsharedpointer.cpp index ce0a1ad9cb..8bc0dc8a74 100644 --- a/src/corelib/tools/qsharedpointer.cpp +++ b/src/corelib/tools/qsharedpointer.cpp @@ -379,7 +379,7 @@ You can inherit this class when you need to create a QSharedPointer from any instance of a class; for instance, from within the object itself. The key point is that the technique of - just returning QSharedPointer(this) can not be used, because + just returning QSharedPointer(this) cannot be used, because this winds up creating multiple distinct QSharedPointer objects with separate reference counts. For this reason you must never create more than one QSharedPointer from the same raw pointer. -- cgit v1.2.3