summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools/qstring
Commit message (Collapse)AuthorAgeFilesLines
* The C locale should omit group separators by defaultLars Knoll2015-10-191-1/+2
| | | | | | | | | | | | | Numbers formatted in the C locale should not use group separators by default. [ChangeLog][QtCore][QLocale] The C locale does not use group separators when formatting numbers any more. Task-number: QTBUG-4044 Task-number: QTBUG-3068 Change-Id: Ia647a72efc11fecd66d22f9253562b1d4ef58168 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Merge remote-tracking branch 'origin/5.5' into 5.6Liang Qi2015-10-021-0/+16
|\ | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: qmake/doc/src/qmake-manual.qdoc src/corelib/tools/qstring.h src/gui/image/qimagereader.cpp src/network/access/qnetworkaccessmanager.cpp src/tools/qdoc/doc/examples/examples.qdoc src/widgets/accessible/qaccessiblewidgetfactory_p.h src/widgets/doc/qtwidgets.qdocconf Change-Id: I8fae62283aebefe24e5ca4b4abd97386560c0fcb
| * Fix comparisons between QByteArray and QString.Christian Kandeler2015-09-281-0/+16
| | | | | | | | | | | | | | | | QByteArray::operator< and friends had their logic reversed. Task-number: QTBUG-48350 Change-Id: I625209cc922b47e78dfb8de9fe100411f285a628 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | QString: add {const_,reverse_iterator}, {c,}r{begin,end}()Marc Mutz2015-07-071-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | Had to mark {,c,const}{begin,end}() inline, since they are, and mingw complains about inconsistent dllimport attributes. [ChangeLog][QtCore][QString] Added rbegin(), crbegin(), rend(), crend(), and reverse_iterator and const_reverse_iterator typedefs. Task-number: QTBUG-25919 Change-Id: I1d48729c76e510c1e49c0e5dc41691aa662fdf21 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | Merge remote-tracking branch 'origin/5.5' into devLiang Qi2015-07-011-1/+1
|\| | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: src/corelib/global/qglobal.cpp src/corelib/global/qglobal.h src/corelib/global/qsysinfo.h src/corelib/global/qsystemdetection.h src/corelib/kernel/qobjectdefs.h src/plugins/plugins.pro tests/auto/widgets/itemviews/qlistview/qlistview.pro Change-Id: Ib55aa79d707c4c1453fb9d697f6cf92211ed665c
| * Replace MAC OS X with OS XNico Vertriest2015-06-301-1/+1
| | | | | | | | | | | | Task-number: QTBUG-46374 Change-Id: I7bc633ab551740bd328a24b0ccae1d534af47138 Reviewed-by: Martin Smith <martin.smith@digia.com>
* | Add shared implementation of a NSAutoreleasePool wrapper to qglobalTor Arne Vestbø2015-05-271-6/+2
| | | | | | | | | | | | | | | | | | | | | | We have at least 5 different (but equal) implementations of a wrapper in Qt, and some code uses explicit NSAutoreleasePools. Having a shared implementation lets us clean up things a bit and makes it easier to reason about which pools are actually needed. Change-Id: I2fd8eefc3ae7308595ef9899b7820206268362a5 Reviewed-by: Tim Blechmann <tim@klingt.org> Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
* | Add missing QString::prepend(QStringRef)/(const QChar*,int) overloadsMarc Mutz2015-04-021-0/+4
| | | | | | | | | | | | | | | | | | | | | | QString::append(QStringRef) exists, and so should prepend(). QString::append(const QChar *,int) exists, and so should prepend(). [ChangeLog][QtCore][QString] Added prepend(QStringRef) and prepent(const QChar *, int) overloads. Change-Id: I3eca41045f7c481be473507e23e92690f3ed7ba3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@theqtcompany.com>
* | Add QString::insert() overloads for QStringRef, const char*, QByteArrayMarc Mutz2015-04-021-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | The corresponding QString::append() overloads exists, and so should insert(). [ChangeLog][QtCore][QString] Added insert(int, QStringRef), insert(int, const char*) and insert(int, QByteArray). Change-Id: I1cf43fe8908319e2a57415945718b72e69ca0fb3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@theqtcompany.com>
* | tst_QString: refactor the op+= testsMarc Mutz2015-04-021-4/+29
| | | | | | | | | | | | | | ... using the framework developed for testing QString::append. Change-Id: I29011eba6438bf9b3daad354cbec4b8e2b98ed81 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | tst_QString: refactor the insert testsMarc Mutz2015-04-021-2/+112
| | | | | | | | | | | | | | | | | | | | | | | | | | | | It is tedious to test all the overloads of QString::insert, so get the help of the compiler to do it. The framework was originally developed for testing append. This change showed that the insert(int, QStringRef), insert(int, const char*) and insert(int, QByteArray) overloads were missing. They will be added in a separate commit. Change-Id: I609b8a05203f8a1ea12827d1798313ace5b719f2 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | tst_QString: refactor the prepend testsMarc Mutz2015-04-021-10/+82
| | | | | | | | | | | | | | | | | | | | | | | | | | It is tedious to test all the overloads of QString::prepend, so get the help of the compiler to do it. The framework was originally developed for testing append. This change showed that prepend(QStringRef) and prepend(const QChar*, int) overloads were missing. They will be added in a separate commit. Change-Id: Ic3d6ad011bedc6ee7d5024094d7c3529b1b9d669 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | tst_QString: refactor the append testsMarc Mutz2015-04-021-12/+203
| | | | | | | | | | | | | | | | | | | | It is tedious to test all the overloads of QString::append(), so get the help of the compiler to do it. The framework developed for this will be used in subsequent commits for prepend and insert, too. Change-Id: I89df581b6d037a5af80b34dd6b5d37ac7484c774 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | QString: preserve embedded NULs when converting from QByteArrayMarc Mutz2015-04-021-37/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Unearthed an off-by-one error in a QByteArray::fromRawData() call in tst_qtextdocumentfragment. Fixed by porting to QStringLiteral. [ChangeLog][Important Behavior Changes] All conversions from QByteArray to QString now preserve embedded NULs. This is done in order to provide a faster conversion from QByteArray to QString that does not involve a call to strlen. If you need the old behavior, convert from QByteArray::constData() instead. If you are porting from Qt 4, we suggest to make your source compile with QT_NO_CAST_FROM_BYTEARRAY before porting to Qt 5. Change-Id: Ibca40f503920fee6f3a5f0d74a04b38b8849796f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | QString::from{Utf8,Latin1,Local8Bit}(QByteArray): preserve nullness of argumentMarc Mutz2015-04-021-0/+30
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently, calling these functions with a null QByteArray will return a non-null QString because QByteArray::data() never returns nullptr. This behavior leads to inconsistencies between QString::append overloads, in particular the QByteArray vs. all others (null + null test always returns a null QString, except for the QByteArray overload before this change). It also is inconsistent with the const char* overloads of these methods, which explicitly preserve nullness (as verified by test cases). Fixed by an explicit check for nullness and return of null QString. Alternative would have been to check for nullness and pass nullptr instead of ba.data() to the _helper() functions, which do the correct thing in that case. But since we'd have the check anyway and with the chosen strategy we can avoid a call to a non-inline method, I opted against that. [ChangeLog][QtCore][QString] fromLatin1(), fromAscii(), fromUtf8() and fromLocal8Bit() now return a null QString when called with a null QByteArray. Change-Id: I5f2c0bad27fb73c7d535085af0271823bf6ed1da Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Track modifications of white space in QString::simplified().Friedemann Kleint2015-03-121-0/+2
| | | | | | | | | | The existing check fails to detect the case where white space characters other than the space character are replaced by space characters without the length actually changing and returns the original string. Task-number: QTBUG-44936 Change-Id: Ice6faa975f8b41f185c76f6d0d4ff81603e25eb3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QStringAlgorithms::simplified_helper: add missing check for detachedThiago Macieira2015-03-071-0/+9
| | | | | | | | Otherwise, we modify shared strings that happened to be rvalues. Task-number: QTBUG-44706 Change-Id: Ia0aac2f09e9245339951ffff13c85bfc912f03d1 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
* Fixed license headersJani Heikkinen2015-02-171-1/+1
| | | | | Change-Id: Ibebe1318d1c2de97601aa07269705c87737083ee Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
* Update copyright headersJani Heikkinen2015-02-113-36/+28
| | | | | | | | | | | | | | | | | | Qt copyrights are now in The Qt Company, so we could update the source code headers accordingly. In the same go we should also fix the links to point to qt.io. Outdated header.LGPL removed (use header.LGPL21 instead) Old header.LGPL3 renamed to header.LGPL3-COMM to match actual licensing combination. New header.LGPL-COMM taken in the use file which were using old header.LGPL3 (src/plugins/platforms/android/extract.cpp) Added new header.LGPL3 containing Commercial + LGPLv3 + GPLv2 license combination Change-Id: I6f49b819a8a20cc4f88b794a8f6726d975e8ffbe Reviewed-by: Matti Paaso <matti.paaso@theqtcompany.com>
* Merge remote-tracking branch 'origin/5.4' into devFrederik Gladhorn2015-02-101-2/+8
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: src/3rdparty/harfbuzz-ng/harfbuzz-ng.pro src/gui/image/qimage_conversions.cpp src/gui/opengl/qopenglextensions_p.h src/gui/text/qtextengine.cpp src/network/ssl/qsslsocket_openssl.cpp src/plugins/platforms/eglfs/qeglfshooks_stub.cpp src/plugins/platforms/eglfs/qeglfsscreen.cpp src/plugins/platforms/eglfs/qeglfswindow.cpp src/plugins/platforms/windows/qwindowsfontdatabase.cpp src/plugins/platforms/windows/qwindowsfontdatabase_ft.cpp src/plugins/platforms/windows/qwindowsnativeinterface.cpp src/plugins/platforms/windows/qwindowsscreen.cpp src/plugins/platforms/windows/qwindowswindow.cpp src/plugins/platforms/windows/qwindowswindow.h src/plugins/platforms/xcb/qxcbdrag.h src/widgets/itemviews/qabstractitemview.cpp src/widgets/kernel/qwidget.cpp src/widgets/util/qsystemtrayicon_p.h tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp Thanks to Friedemann Kleint for resolving the qwindowsfontdatabase.cpp conflicts. Change-Id: I937232c30523d5121c195d947d92aec6f129b03e
| * tst_qstring_mac: Correct memory management.Morten Johan Sørvig2015-01-201-2/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The NSStrings return by QString::toNSString are autoreleased; manually releasing them is not correct. The test still works (no leaks or double deletes) since there is no autorelease pool in place when running it. We don't want to encourage incorrect usage: remove the release call an add an autorelease pool. Change-Id: Ic566fd3a8efd6cbc0eb6db850248a68bfc8fed0b Reviewed-by: Timur Pocheptsov <Timur.Pocheptsov@digia.com> Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@theqtcompany.com> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com> Reviewed-by: Jake Petroules <jake.petroules@petroules.com>
* | Remove support for QT_QLOCALE_USES_FCVT.Erik Verbruggen2015-01-281-2/+0
| | | | | | | | | | | | | | We expect floating-point math to be IEEE754 compliant. Change-Id: I2b257177f2ef5fce38ac4d8fd76f746dc7b9fc15 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* | Add conversion functions for C++11 u16string and u32stringAllan Sandfeld Jensen2015-01-242-0/+24
| | | | | | | | | | | | | | | | | | | | | | The patch adds convenience functions for working on C++11's new char width specific unicode strings u16string and u32string. [ChangeLog][QtCore][QString] Added methods for convenient conversion to and from std::u16string and std::u32string. Change-Id: I67c082e4755c592d61daaaaa70c8867ef0b23dcb Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
* | Remove duplicated NAN/INF logic from tst_qstringAllan Sandfeld Jensen2015-01-211-72/+3
| | | | | | | | | | | | | | | | | | | | Qt already has solutions for cross platform isnan and isinf logic. We should use that instead of duplicating it. This should also fix compiling tst_qstring on MinGW with C++11. Change-Id: I7b691fd47701a8f07e1a1fe08a95a0aca43ccca1 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
* | Use the new warning enabling/disabling macros in qtbaseThiago Macieira2014-12-031-7/+3
| | | | | | | | | | | | Change-Id: I91ff06644e8047c2ca483f9768b46c1372eb6171 Reviewed-by: Martin Smith <martin.smith@digia.com> Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@theqtcompany.com>
* | Merge remote-tracking branch 'origin/5.4' into devFrederik Gladhorn2014-11-241-0/+22
|\| | | | | | | | | | | | | | | | | | | | | | | Conflicts: src/corelib/io/qiodevice.cpp src/plugins/bearer/linux_common/qofonoservice_linux.cpp src/plugins/bearer/linux_common/qofonoservice_linux_p.h src/plugins/platforms/android/qandroidplatformtheme.cpp src/tools/bootstrap/bootstrap.pro src/widgets/styles/qmacstyle_mac.mm Change-Id: Ia02aab6c4598ce74e9c30bb4666d5e2ef000f99b
| * Fix QString::section() behavior on negative and out-of-range indexesAlex Trotsenko2014-11-201-0/+22
| | | | | | | | | | Change-Id: I3bff6ba73b15ee810bb11b2902d11244c3205b2a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | Add rvalue-ref qualified {QString,QByteArray}::{simplified,trimmed}Thiago Macieira2014-11-021-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Of the const overloads that return a QString or a QByteArray, this is one that gains the most benefit. It happens often in constructs like: QByteArray s = x.readLine().trimmed(); After this change, 41 out of 103 calls to trimmed become rvalue in Qt and 272 out of 441 in Qt Creator. For simplified, the numbers are 27 out of 69 in Qt and 10 out of 19 in Qt Creator. Other candidates are left, right, and mid, but there are exactly zero uses of left, right and mid on an xvalue QString or QByteArray in Qt. I'm being lazy and using qstring_compat.cpp to store the QByteArray compat methods. Change-Id: I4e410fc1adc4c761bb07cc3d43b348a65befa9f6 Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
* | Merge remote-tracking branch 'origin/5.4' into devOswald Buddenhagen2014-09-292-38/+22
|\| | | | | | | | | | | | | | | | | | | | | Conflicts: src/corelib/tools/qbytearray.cpp src/gui/image/qimage.cpp src/gui/image/qppmhandler.cpp src/gui/kernel/qguiapplication.cpp src/gui/painting/qpaintengine_raster.cpp Change-Id: I7c1a8e7ebdfd7f7ae767fdb932823498a7660765
| * Update license headers and add new license filesMatti Paaso2014-09-242-38/+22
| | | | | | | | | | | | | | | | | | - Renamed LICENSE.LGPL to LICENSE.LGPLv21 - Added LICENSE.LGPLv3 - Removed LICENSE.GPL Change-Id: Iec3406e3eb3f133be549092015cefe33d259a3f2 Reviewed-by: Iikka Eklund <iikka.eklund@digia.com>
* | tst_QString: also test section(QChar) overloadMarc Mutz2014-09-121-0/+2
| | | | | | | | | | Change-Id: I5d631cdd33501ac10e3e4184518d3c70b20984d7 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | QString:add (last)indexOf overload with QRegularExpressionMatch outputSamuel Gaist2014-08-271-0/+39
| | | | | | | | | | | | | | | | | | | | | | | | This patch adds indexOf and lastIndexOf with QRegularExpressionMatch output overloads to QString. This allows to get the match corresponding to the index returned. [ChangeLog][QtCore][QString] Added support for retrieving the QRegularExpressionMatch to indexOf and lastIndexOf. Change-Id: Ia0ae2d3ff78864c7053ffa397874aca1d2b1c35c Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
* | tst_QString: Use a non-empty string for lastIndexOfInvalidRegexSamuel Gaist2014-08-271-1/+1
| | | | | | | | | | | | | | | | | | | | Testing using an empty string doesn't ensure that the regexp gets validated. The function may return earlier thus making the test useless. This patch adds a text to search in so that no early optimization avoids the regexp validation part Change-Id: If24b77385dde44a922d43e5ae1d7a5393d24f640 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
* | Add test case for indexOf using an invalid QRegularExpressionSamuel Gaist2014-08-261-0/+7
| | | | | | | | | | Change-Id: I3677d0ecd406388a8f1eb65ec013595904da4c2d Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
* | Simplify and unify Q{ByteArray,String{,Ref}}::{simplify,trimmed}Thiago Macieira2014-08-191-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As a side effect, QString::simplified() will always return a detached copy, even if it's the same contents. QStringRef::trimmed() can use the same calculation algorithm but can't use the trimmed_helper() template function due to its lack of a constructor taking begin pointer and size (std::string_view could do it). That constructor can't be added because QStringRef always refers to an existing QString, not to data in memory. Change-Id: Ib966c1741819c68c6bac5fcbb00f8ac818b3ccab Reviewed-by: Olivier Goffart <ogoffart@woboq.com> Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com> Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
* | Add rvalue-ref qualified QString::to{Upper,Lower,CaseFolded}Thiago Macieira2014-08-191-0/+2
|/ | | | | | | | | | | | This is even more common than the QByteArray equivalents. Qt Qt Creator const & && const & && toLower 71 50 45 26 toUpper 35 8 46 35 Change-Id: I8b797d2321b22ce414c23656c5f1709ac649c423 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
* Add QString::splitRef functions.Jędrzej Nowacki2014-07-311-15/+123
| | | | | | | | | | | | The functions can be used to optimize code that do not need to use the split results as QString directly. [ChangeLog][QtCore] QString can now split a string to a list of QStringRef. Change-Id: Ic2dc929e1fba82f9a060e37c51068a301cb5b866 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
* Improve QString::arg testJędrzej Nowacki2014-07-101-0/+6
| | | | | | | The function gives a warning if an argument doesn't exist. Change-Id: I6a4bbbaf2fd241ced06dc71edfe4ef69732606d1 Reviewed-by: Mitch Curtis <mitch.curtis@digia.com>
* Restore handling of BOMs in QString::fromUtf8Thiago Macieira2014-04-241-0/+8
| | | | | | | | | | | 8dd47e34b9b96ac27a99cdcf10b8aec506882fc2 removed the handling of the BOMs but did not document it. This brings the behavior back and adds a unit test so we don't break it again. Discussed-on: http://lists.qt-project.org/pipermail/development/2014-April/016532.html Change-Id: Ifb7a9a6e5a494622f46b8ab435e1d168b862d952 Reviewed-by: Olivier Goffart <ogoffart@woboq.com> Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Fix capacity reservation for shared QByteArrayThiago Macieira2014-04-051-0/+9
| | | | | | | | | | | | We can squeeze, but not by discarding elements. Make sure the size of the object stays intact after changing the reserved capacity. I've also added unit tests for other containers, just to be sure. Task-number: QTBUG-37750 Change-Id: I5135b095943b7589423c51cebcb52af792468e61 Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
* Reuse one QCollator instance for QString::localeAwareCompareLars Knoll2014-03-271-4/+2
| | | | | | | | | | | | | Constructing a QCollator is somewhat expensive, and made localeAwareCompare really slow. As QCollator (at least with the ICU implementation) is not thread safe, use one collator per thread. This speeds up collation of a long list of strings by a factor of 250 for the test case in the bug below. Task-number: QTBUG-36149 Change-Id: I645cdc3546347d1dcc7a03b7563b628c7f756944 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
* Merge "Merge remote-tracking branch 'origin/stable' into dev" into ↵Frederik Gladhorn2014-02-111-0/+56
|\ | | | | | | refs/staging/dev
| * Merge remote-tracking branch 'origin/stable' into devFrederik Gladhorn2014-02-071-0/+56
| |\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: src/gui/kernel/qguiapplication.cpp src/plugins/platforms/android/androidjnimain.cpp src/plugins/platforms/android/qandroidplatformintegration.cpp src/plugins/platforms/android/qandroidplatformintegration.h src/plugins/platforms/android/qandroidplatformopenglcontext.cpp src/plugins/platforms/cocoa/qcocoawindow.h src/plugins/platforms/cocoa/qcocoawindow.mm src/plugins/platforms/xcb/qxcbconnection_xi2.cpp src/sql/doc/src/sql-driver.qdoc src/widgets/widgets/qtoolbararealayout.cpp Change-Id: Ifd7e58760c3cb6bd8a7d1dd32ef83b7ec190d41e
| | * Fix a bug in some QString comparison operatorsLars Knoll2014-01-211-0/+56
| | | | | | | | | | | | | | | | | | | | | | | | | | | Some comparison operators comparing to const char * where not implemented correctly. Task-number: QTBUG-34024 Change-Id: Idbdc64c8ed93e88d9f2b2f55213bc785b33cb543 Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
* | | Fix QString::toUcs4 returning invalid data when encountering stray surrogatesGiuseppe D'Angelo2014-02-071-5/+68
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Code units 0xD800 .. 0xDFFF are not UCS-4, so we can't happily return them. Instead, if we encounter a stray surrogate, replace it with 0xFFFD, which is what Unicode recommends anyhow. References: §3.9 Unicode Encoding Forms D76: Unicode scalar value: Any Unicode code point except high-surrogate and low surrogate code points. As a result of this definition, the set of Unicode scalar values consists of the ranges 0 to D7FF_16 and E000_16 to 10FFFF_16, inclusive. [...] UTF-32 encoding form: The Unicode encoding form that assigns each Unicode scalar value to a single unsigned 32-bit code unit with the same numeric value as the Unicode scalar value. § C.2 Encoding Forms in ISO/IEC 10646 UCS-4. UCS-4 stands for “Universal Character Set coded in 4 octets.” It is now treated simply as a synonym for UTF-32, and is considered the canonical form for representation of characters in 10646. § 3.9 Unicode Encoding Forms (Best Practices for Using U+FFFD) and § 5.22 Best Practice for U+FFFD Substitution Whenever an unconvertible offset is reached during conversion of a code unit sequence: 1. The maximal subpart at that offset should be replaced by a single U+FFFD. 2. The conversion should proceed at the offset immediately after the maximal subpart. [...] Whenever an unconvertible offset is reached during conversion of a code unit sequence to Unicode: 1. Find the longest code unit sequence that is the initial subsequence of some sequence that could be converted. If there is such a sequence, replace it with a single U+FFFD; otherwise replace a single code unit with a single U+FFFD. 2. The conversion should proceed at the offset immediately after the subsequence which has been replaced. [ChangeLog][QtCore][QString] QString::toUcs4 now does not return invalid UCS-4 code units belonging to the surrogate range (U+D800 to U+DFFF) when the QString contains malformed UTF-16 data. Instead, U+FFFD is returned in place of the malformed subsequence. Change-Id: I19d7af03e749fea680fd5d9635439bc9d56558a9 Reviewed-by: Lars Knoll <lars.knoll@digia.com> Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | | Add QString::fromUtf16 with char16_t and fromUcs4 with char32_tThiago Macieira2014-02-071-3/+40
|/ / | | | | | | | | | | | | | | Because they make sense. I'm even thinking that the char16_t version should get a QString implicit constructor. Maybe both encodings. Change-Id: Ifffc61dd890795fbbbd5f7cb5efb3e6287d1270e Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* | Add the UTF16-to-Latin1 in-place converterThiago Macieira2013-12-131-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is only possible for two important reasons: 1) QString and QByteArray d pointers are both done with QArrayData and that class does not care that the alignof(T) changes from 2 to 1, so we can give the pointer from QString to QByteArray (after adapting the allocated size, which is now double) 2) conversion from UTF16 to Latin1 always has fewer bytes (exactly half) Change-Id: I17b2690c910f3de8db55156c6d6b5f55be06d827 Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com> Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
* | QString: add missing contains(QLatin1String) overloadMarc Mutz2013-11-261-0/+2
|/ | | | | | | | | | | Since contains() just wraps indexOf(), which has a QLatin1String overload, add one for contains(), too, for consistency. [ChangeLog][QtCore][QString] Added QLatin1String overload of contains() Change-Id: I2acc628a51e00789fb2b90400cf0c523a5b5e65a Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QString::reserve fix to avoid truncationMarko Pellikka2013-09-261-0/+12
| | | | | | | | | | In case of implicit memory sharing, QString::reserve caused data truncation if given size was smaller than size of data. Task-number: QTBUG-29664 Change-Id: If2da5ad051385635ebb829c18b5ebaa349f08e8a Reviewed-by: Olivier Goffart <ogoffart@woboq.com> Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
* Add Mac type conversion functions to QtCoreMorten Johan Sørvig2013-09-213-0/+95
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | New API: static QString QString::fromCFString(CFStringRef string); CFStringRef QString::toCFString() const; static QString QString::fromNSString(const NSString *string); NSString *QString::toNSString() const; static QUrl QUrl::fromCFURL(CFURLRef url); CFURLRef QUrl::toCFURL() const; static QUrl QUrl::fromNSURL(const NSURL *url); NSURL * QUrl::toNSURL() const; Add Q_OS_MAC-protected function declarations to header files, add implementation to _mm files. CF and NS types are forward-declared in the header files to avoid including the CoreFoundation and Foundation headers. This prevents accidental use of native types in application code. Add helper macros for forward- declaration to qglobal.h Add cf_returns_retained/ns_returns_autoreleased attributes to toCFString() and toNSURL(). These attributes assists the clang static analyzer. Add Q_DECL_ helper macros to qcompilerdetection.h. Add test functions (in _mac.mm files) to the QString and QUrl tests. Split out the test class declarations into a separate headers files. Change-Id: I60fd5e93f042316196284c3db0595835fe8c4ad4 Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>