1#ifndef QT_UTILITIES_COMPAT_H
2#define QT_UTILITIES_COMPAT_H
6#include <c++utilities/misc/traits.h>
10#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
11#define QT_UTILITIES_USE_Q_STRING_VIEW
16#ifdef QT_UTILITIES_USE_Q_STRING_VIEW
25#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
33#ifdef QT_UTILITIES_USE_Q_STRING_VIEW
55template <
typename PosType1,
typename PosType2 = PosType1,
56 CppUtilities::Traits::EnableIf<std::is_integral<PosType1>, std::is_signed<PosType1>, std::is_integral<PosType2>, std::is_signed<PosType2>>
60#ifdef QT_UTILITIES_USE_Q_STRING_VIEW
61 return QStringView(str).mid(pos, n);
63 return str.midRef(pos, n);
70template <
class... SplitArgs>
inline auto splitRef(
const QString &str, SplitArgs &&...args)
72#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
73 return QStringView(str).split(std::forward<SplitArgs>(args)...);
74#elif QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
75 return str.splitRef(std::forward<SplitArgs>(args)...);
77 return str.split(std::forward<SplitArgs>(args)...);
83#if (QT_VERSION < QT_VERSION_CHECK(5, 10, 0))
88inline QString qEnvironmentVariable(
const char *varName,
const QString &defaultValue)
90 const auto val = qgetenv(varName);
91 return !val.isEmpty() ? QString::fromLocal8Bit(val) : defaultValue;
#define QT_UTILITIES_USE_Q_STRING_VIEW
StringView midRef(const QString &str, PosType1 pos, PosType2 n=-1)
Makes either a QStringView or a QStringRef depending on the Qt version, applying "mid()" parameters.
StringView makeStringView(const QString &str)
Makes either a QStringView or a QStringRef depending on the Qt version.
auto splitRef(const QString &str, SplitArgs &&...args)
Splits str into QStringViews, QStringRefs or QStrings depending on the Qt version.