summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qstringconverter.h
Commit message (Collapse)AuthorAgeFilesLines
* QString{En,De}coder: add constructors with QString parametersThiago Macieira11 days1-0/+6
| | | | | | | | | | | | | Because QStringConverter::availableCodecs() returns QString. Added as Q_WEAK_OVERLOAD so this doesn't create ambiguous overloads when passing QByteArrays. Fixes: QTBUG-123919 Change-Id: If1bf59ecbe014b569ba1fffd17c29a253ac22abe Reviewed-by: Sune Vuorela <sune@vuorela.dk> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QStringConverter: clarify decode()/encode() API docsAhmad Samir2023-10-061-14/+0
| | | | | | | | | | | These methods return a struct which is implicitly convertible to QString/QByteArray respectively. Don't hide the return type from QDoc, this simplifies telling users what those methods return exactly. Fixes: QTBUG-117705 Pick-to: 6.6 6.5 Change-Id: Ibb22a1e54fffce8f5f20aaabe47983870ccfba1e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QString: assign() [4/4]: (it,it) overload for UTF-8 data typesDennis Oberst2023-09-281-0/+60
| | | | | | | | | | | | | | | | | | | | | | Implement the missing overload to handle UTF-8 specific data types, including char8_t (C++20), char, uchar and signed char. Introduce the helper function 'assign_helper_char8' which handles the non-contiguous_iterator case. The contiguous_iterator case is already handled by the QAnyStringView overload. Include 'qstringconverter.h' at the end of the file, since it can't be included at the top due to diamond dependency conflicts. QStringDecoder is an implementation detail we don't want users to depend on when using assign(it, it). It would be unnatural to not be able to use a function just because we didn't include an apparently unrelated header. [ChangeLog][QtCore][QString] Enabled assign() for UTF-8 data types. Fixes: QTBUG-114208 Change-Id: Ia39bbb70ca105a6bbf1a131b2533f29a919ff66d Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Don't protect qstringbuilder.h indirect includesMarc Mutz2023-08-031-2/+0
| | | | | | | | | | | | | | | | | | | It's a) not needed, because qstringbuilder.h simply just defines op% and not op+ when these defines are not set and b) surprising for users that they have to include <qstringbuilder.h> if they want to use op% without also setting one of these defines. Finally, it just throws readers of the code off the track for no good reason. So, drop the external guards for qtringbuilder.h in qstring.h and qstringconverter.h. Task-number: QTBUG-114208 Pick-to: 6.6 6.5 Change-Id: I00b3e405d905d319437c32a7253b39de1625d096 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Dennis Oberst <dennis.oberst@qt.io>
* QStringDecoder: add a char16_t overload of appendToBuffer(QChar*, ~~~)Marc Mutz2023-06-041-0/+2
| | | | | | | | | | | | | More and more code in Qt uses char16_t instead of QChar, even QString::Data, so reduce the impedance mismatch with such code and supply a char16_t overload in parallel to the existing QChar* one. [ChangeLog][QtCore][QStringDecoder] Added appendToBuffer() overload for char16_t*, complementing the existing overload taking QChar*. Task-number: QTBUG-106198 Change-Id: I0cb8ab22c897c14b1318a676f5212cc0cf1b72b7 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QString(En|De)coder: Remove noexcept from ctor taking nameFabian Kosmale2022-06-271-2/+2
| | | | | | | | | | | | It is necessary as the QStringConverter ctor is no longer noexcept, as it can now allocate memory. This change is ABI-wise safe, as the method was only changed to be noexcept in 6.4. Amends 122270d6bea164e6df4357f4d4d77aacfa430470. Pick-to: 6.4 Change-Id: Ifab4302d659524e27f38f0f90e5813a2c2a4a452 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Add QStringDecoder::decoderForHtml()Lars Knoll2022-06-211-0/+3
| | | | | | | | | | | | | | Now that QStringConverter can handle non UTF encodings through ICU, add a way to get a decoder for arbitrary HTML code. Opposed to QStringConverter::encodingForHtml(), this method will try to create a valid string decoder also for non unicode codecs. Pick-to: 6.4 Change-Id: I343584da1b114396c744f482d9b433c9cedcc511 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QStringConverter: Do not crash if invalidFabian Kosmale2022-05-251-4/+26
| | | | | | | | | | | Attempting to use an invalid QStringConverter would so far have resulted in a crash, as we would dereference the null iface pointer. Fix this by inserting adequate checks, and ensure that hasError returns true if we attempt to en/decode with an invalid converter. Pick-to: 6.2 6.3 Change-Id: Icf74bb88cd8c95685481cc0bd512da99b62f33e6 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Use SPDX license identifiersLucie Gérard2022-05-161-38/+2
| | | | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Task-number: QTBUG-67283 Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* QStringEncoder/Decoder: add missing noexceptMarc Mutz2022-02-221-6/+6
| | | | | | | | | | | | | The interesting part is what cannot be noexcept: - nameForEncoding() and ctor from Encoding: because they don't handle all valid values of type Encoding, so have a narrow contract - encodingForHtml(): because it allocates memory (→ QTBUG-101046) Change-Id: I30cdc19a32537be047e43955e3337e4d6ccc363f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QStringConverter: make explicit what should never have been implicitMarc Mutz2022-02-221-17/+8
| | | | | | | | | | As a drive-by, remove the GCC 7 constexpr work-around. [ChangeLog][Potentially Source-Incompatible Changes] All QStringEncoder/Decoder constructors are now explicit. Change-Id: I0972e2736115993d44a48e73dbf4b08a1c94bef2 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* qtextstream.h: streamline includesFabian Kosmale2022-02-101-134/+8
| | | | | | | | | | | [ChangeLog][Potentially Source-Incompatible Changes] The qtextstream header no longer includes <QString>, <QStringEncoder> and <QStringDecoder>. Code which relied on the implicit inclusion of those classes might now need to include the headers explicitly. Task-number: QTBUG-97601 Change-Id: Ifb8c8452026195a772c0588dbbbc53fb51cac548 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Convert a couple of APIs to use viewsLars Knoll2020-10-061-44/+26
| | | | | | | | | | | Try to get rid of APIs that use raw 'const {char, QChar} *, length' pairs. Instead, use QByteArrayView or QStringView. As QStringConverter is a new class, simply change the API to what we'd like to have. Also adjust hidden API in QStringBuilder and friends. Change-Id: I897d47f63a7b965f5574a1e51da64147f9e981f6 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Fix some qdoc warningsFriedemann Kleint2020-07-211-1/+1
| | | | | | | | | | | | | | | | | | src/corelib/text/qstringconverter.h:160:54: error: no matching constructor for initialization of 'QStringConverterBase::State' src/corelib/text/qstringconverter.h:72:19: note: candidate constructor not viable: no known conversion from 'QFlags<QStringConverter::Flag>' to 'QFlags<QStringConverterBase::Flag>' for 1st argument src/corelib/text/qstringconverter.h:75:9: note: candidate constructor not viable: no known conversion from 'QStringConverter::Flags' (aka 'QFlags<QStringConverter::Flag>') to 'QStringConverterBase::State' for 1st argument src/corelib/text/qstringconverter.h:108:24: note: candidate constructor not viable: no known conversion from 'QStringConverter::Flags' (aka 'QFlags<QStringConverter::Flag>') to 'const QStringConverterBase::State' for 1st argument src/corelib/text/qstringconverter.h:159:32: warning: constexpr constructor that does not initialize all members is a C++20 extension [-Wc++20-extensions] src/corelib/text/qstringconverter.h:187:11: note: member not initialized by constructor src/corelib/kernel/qproperty.h:403:14: error: deduction guide must be declared in the same scope as template 'QProperty' src/corelib/kernel/qproperty.h:202:7: note: template is declared here src/corelib/kernel/qproperty.h:403:14: error: deduction guide declaration without trailing return type src/gui/painting/qregion.h:139:5: error: unknown type name 'HRGN' src/gui/painting/qregion.h:140:29: error: unknown type name 'HRGN' Change-Id: I3c195a60ceeb51664368a4aeef90c70c31954fc3 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Paul Wicking <paul.wicking@qt.io>
* Add explicit encode()/decode() methods to QStringConverterLars Knoll2020-06-261-4/+22
| | | | | | | | | The functional style interface is nice, but does feel alien in some contexts, so better also have explicit encode and decode methods. Change-Id: Ic07ced15f65cdb3a7f1cf044041e341d2ef87f79 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Fix QString{Encoder|Decoder} documentationKarsten Heimrich2020-06-181-4/+4
| | | | | | Change-Id: I8e29846db77581953d90c818060950744cb9f521 Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io> Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
* Don't change the implementation of a method depending on QT_USE_QSTRINGUILDERLars Knoll2020-05-261-23/+13
| | | | | | | | | | | | | | | | | | | | | | | This is rather evil and caused crashes in static builds, when library and application where compiler with different settings of the QT_USE_QSTRINGBUILDER flag. The reason is that the implementation of QStringDecoder::operator() was different (and returning different data) with or without the setting. The compiler would thus create two very different versions of this method in different .o files. When linking the app, one of the implementations would be chosen, leading to crashes in places where the other one was expected. Fix this by only providing the QStringBuilder enabled version of the methods. They return a temporary object that's converatable to a QString/QByteArray anyway. Make sure that qdoc shows a simple signature. As a drive by fix a compile error in a code path that didn't get hit so far. Change-Id: I312fa564d0bc6b464f2b4466de1d53841f7b7b0f Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Document the string converter classesLars Knoll2020-05-141-12/+26
| | | | | | | | | | Document QStringConverter, QStringDecoder and QStringEncoder. In addition, do some touches to the API, renaming one enum value, add a flags argument to one constructor and make some members private. Change-Id: I8f99dc3d98fb8860cf6fa46301e34b7eb400511b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Optimize appending to an existing stringLars Knoll2020-05-141-0/+22
| | | | | | | | Optimize the common pattern of "str += decode(data);" and "bytearray += encode(string);" Change-Id: I1da621fa1ad400f23c9718ecf8ae64c00d9d459c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Add a method to determine the encoding for encoded HTML dataLars Knoll2020-05-141-0/+1
| | | | | | | This is a replacement for Qt::codecForHtml(). Change-Id: I31f03518fd9c70507cbd210a8bcf405b6a0106b1 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Add QStringConverter::encodingForData()Lars Knoll2020-05-141-0/+1
| | | | | | | | Add method that tries to determine the encoding of the data from an initial byte order mark. Change-Id: I348c51a3d4db9b434af53359b739a7e17acfc760 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Add methods to convert between encoding and name to QStringConverterLars Knoll2020-05-141-1/+7
| | | | | | | | Add static methods that allow converting between a name for an encoding and the Encoding enum. Change-Id: I12bc503cf757ea31d3ca8d5e1f1216efddcb16d4 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Construct a string converter by nameLars Knoll2020-05-141-0/+20
| | | | | | | | | | | Add a constructor, that allows constructing a string converter by name. This is required in some cases and also makes it possible to (in the future) extend the API to 3rd party encodings. Also add a name() accessor. Change-Id: I606d6ce9405ee967f76197b803615e27c5b001cf Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Ensure the conversion methods in qstringconverter always get a valid stateLars Knoll2020-05-141-5/+4
| | | | | | | | | | | | Make sure that the conversion methods always get a valid state. This is already the ecase then using the new QStringConverter API, ensure the old QTextCodec API also passes in a valid state. This helps simplify the logic inside those methods. Change-Id: I1945e98cdefd46bf1427e11984337f1d62abcaa2 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Clean up the Flag handling in QStringConverterLars Knoll2020-05-141-14/+14
| | | | | | | | | | | | | | | IgnoreHeader was a rather badly defined enum, in addition the utf8 and utf16 codecs where handling BOMs somewhat different for stateless decoding. Fix this by introducing explicit flags for writing a bom when encoding and not skipping the initial bom when decoding. Source compatibility for QTextCodec is done with a couple of static constexpr variables. Change-Id: I0b2d94f84c937cec1e0494c16ef448c00382691d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Enable using QStringConverter together with QStringBuilderLars Knoll2020-05-141-6/+99
| | | | | | | | | | The way the new converters are structured allows us to use them together with QStringBuilder. Like this, we can avoid additional and unnecessary copies of the data. Change-Id: I168da3860537fe81a1eb62632e4d9a6680f86af1 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Allow moving of string converter objectsLars Knoll2020-05-141-0/+19
| | | | | | | They are still not copyable, but can be moved. Change-Id: Id66e35be4ecdaa781ecb9212d646d224b1767913 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Add Latin1 to the set of supported encodings in QStringConverterLars Knoll2020-05-141-0/+1
| | | | | | | | | | | | | Latin1 is the only non Unicode encoding that is still being used to some extent. Current web site statistics show that it is being used in ~2% of all web sites. An additional 1% of web sites use Windows1251 (which is almost the same as latin1). As it's trivial to support this encoding, we keep it supported in QStringConverter. Change-Id: I0eff53a490b6c43d3e474107e7823be245d1715a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Move local8bit conversion over to qutfsupportLars Knoll2020-05-141-1/+2
| | | | | | | | Local8Bit is always UTF-8 except for Windows platforms. Also add a Locale encoding to QStringConverter. Change-Id: I8d729931fd4c1d7fc6857696b6442a44def3fd9d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Start work on a new API to replace QTextCodecLars Knoll2020-05-141-0/+195
The new QStringEncoder and QStringDecoder classes (with a common QStringConverter base class) are there to replace QTextCodec in Qt 6. It currently uses a trivial wrapper around the utf encoding functionality. Added some autotests, mostly copied from the text codec tests. Change-Id: Ib6eeee55fba918b9424be244cbda9dfd5096f7eb Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>