summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qstringconverter_base.h
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-02-21 16:33:50 +0100
committerMarc Mutz <marc.mutz@qt.io>2022-02-22 18:16:24 +0100
commit330f2132cade80b588e78971a24fc7d702ff6a3a (patch)
treec80880adf17a5877f2f745f088090943b40ece69 /src/corelib/text/qstringconverter_base.h
parent4b8bc8b5bb0b1224206e8dd5526cc8d1e8b6de52 (diff)
QStringEncoder/Decoder: add missing noexcept
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>
Diffstat (limited to 'src/corelib/text/qstringconverter_base.h')
-rw-r--r--src/corelib/text/qstringconverter_base.h22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/corelib/text/qstringconverter_base.h b/src/corelib/text/qstringconverter_base.h
index 23a011d297..b827f2d0a3 100644
--- a/src/corelib/text/qstringconverter_base.h
+++ b/src/corelib/text/qstringconverter_base.h
@@ -72,7 +72,7 @@ public:
Q_DECLARE_FLAGS(Flags, Flag)
struct State {
- constexpr State(Flags f = Flag::Default)
+ constexpr State(Flags f = Flag::Default) noexcept
: flags(f), state_data{0, 0, 0, 0} {}
~State() { clear(); }
State(State &&other) noexcept
@@ -155,33 +155,35 @@ protected:
LengthFn fromUtf16Len = nullptr;
};
- constexpr QStringConverter()
+ constexpr QStringConverter() noexcept
: iface(nullptr)
{}
constexpr explicit QStringConverter(Encoding encoding, Flags f)
: iface(&encodingInterfaces[int(encoding)]), state(f)
{}
- constexpr explicit QStringConverter(const Interface *i)
+ constexpr explicit QStringConverter(const Interface *i) noexcept
: iface(i)
{}
- Q_CORE_EXPORT explicit QStringConverter(const char *name, Flags f);
+ Q_CORE_EXPORT explicit QStringConverter(const char *name, Flags f) noexcept;
public:
- bool isValid() const { return iface != nullptr; }
- void resetState()
+ bool isValid() const noexcept { return iface != nullptr; }
+
+ void resetState() noexcept
{
state.clear();
}
- bool hasError() const { return state.invalidChars != 0; }
+ bool hasError() const noexcept { return state.invalidChars != 0; }
- const char *name() const
+ const char *name() const noexcept
{ return isValid() ? iface->name : nullptr; }
- Q_CORE_EXPORT static std::optional<Encoding> encodingForName(const char *name);
+ Q_CORE_EXPORT static std::optional<Encoding> encodingForName(const char *name) noexcept;
Q_CORE_EXPORT static const char *nameForEncoding(Encoding e);
- Q_CORE_EXPORT static std::optional<Encoding> encodingForData(QByteArrayView data, char16_t expectedFirstCharacter = 0);
+ Q_CORE_EXPORT static std::optional<Encoding>
+ encodingForData(QByteArrayView data, char16_t expectedFirstCharacter = 0) noexcept;
Q_CORE_EXPORT static std::optional<Encoding> encodingForHtml(QByteArrayView data);
protected: