27#ifdef KDWINUTILS_WITHMFC
49 using QString::QString;
57 using QString::operator=;
65 using QString::operator+=;
83#ifdef KDWINUTILS_WITHMFC
87 operator CString()
const;
100 [[deprecated(
"Use explicit conversion methods")]]
explicit operator const char *()
const;
105 template <
typename... Ts>
108 *
this = FormatString(format, std::forward<Ts>(args)...);
318 template <
typename T,
typename... Ts>
319 static QString FormatString(T &&format, Ts... args);
323 template <
typename T>
324 static auto ToByteArray(T &&arg);
327 template <
typename T>
328 static auto ToConstData(T &&arg);
351#define KDWINUTILS_KSTRING_DEFINE_OP_PLUS(StringClass) \
352 template <typename T> \
353 inline std::enable_if_t<std::is_same_v<T, KString>, KString> operator+(T const &s1, StringClass const &s2) \
355 return s1 + KString(s2); \
357 template <typename T> \
358 inline std::enable_if_t<std::is_same_v<T, KString>, KString> operator+(StringClass const &s1, T const &s2) \
360 return KString(s1) + s2; \
367#ifdef KDWINUTILS_WITHMFC
371#undef KDWINUTILS_KSTRING_DEFINE_OP_PLUS
373template <
typename T,
typename... Ts>
380 auto convertStrings = std::make_tuple(ToByteArray(std::forward<T>(format)), ToByteArray(std::forward<Ts>(args))...);
384 auto convertArgs = std::apply(
385 [&](
const auto &...args) {
386 return std::tuple(ToConstData(args)...);
391 return std::apply(QString::asprintf, convertArgs);
395auto KString::ToByteArray(T &&arg)
397 if constexpr (std::is_same_v<QString, std::decay_t<T>>)
399 else if constexpr (std::is_same_v<KString, std::decay_t<T>>)
401 else if constexpr (std::is_same_v<const wchar_t *, std::decay_t<T>>)
402 return QString::fromWCharArray(std::forward<T>(arg)).toUtf8();
403 else if constexpr (std::is_same_v<std::wstring, std::decay_t<T>>)
404 return QString::fromStdWString(std::forward<T>(arg)).toUtf8();
405 else if constexpr (std::is_same_v<std::string, std::decay_t<T>>)
406 return QString::fromStdString(std::forward<T>(arg)).toUtf8();
407#ifdef KDWINUTILS_WITHMFC
408 else if constexpr (std::is_same_v<CStringW, std::decay_t<T>>)
409 return QString::fromWCharArray(std::forward<T>(arg), arg.GetLength()).toUtf8();
410 else if constexpr (std::is_same_v<CStringA, std::decay_t<T>>)
411 return (
const char *)arg;
414 return std::forward<T>(arg);
418auto KString::ToConstData(T &&arg)
420 if constexpr (std::is_same_v<QByteArray, std::decay_t<T>>)
421 return arg.constData();
423 return std::forward<T>(arg);
The KString class provides a Unicode character string.
Definition kstring.h:45
KString Right(int nCount) const
Extracts the rightmost nCount characters from this string object.
int GetLength() const
Returns the number of characters in a KString object.
KString & TrimRight(const KString &charsTarget)
Trims trailing characters from the string.
KString & TrimLeft()
Trims leading whitespace from the string.
KString & operator+=(const CString &str)
KString Tokenize(const KString &tokens, int &iStart) const
Finds the next token in a target string.
KString & operator=(const wchar_t *str)
KString & operator+=(QStringView str)
KString & operator=(const CString &str)
int CollateNoCase(const KString &other) const
Compares two strings according to a localized collation algorithm.
bool GetEnvironmentVariable(const KString &envVar)
Sets the string to the value of the specified environment variable.
int Replace(QChar before, QChar after)
Replaces a character by another character.
KString & TrimRight()
Trims trailing whitespace from the string.
int Collate(const KString &other) const
Compares two strings according to a localized collation algorithm.
KString & TrimLeft(const KString &charsTarget)
Trims leading characters from the string.
void Empty()
Forces a string to have 0 length.
KString(const CString &str)
int Find(const KString &other, int iStart=0) const
Finds a character or substring inside a larger string.
KString SpanExcluding(const KString &excludeChars) const
Extracts characters from the string, starting with the first character, that aren't in the set of cha...
KString & operator+=(const char *str)
KString & operator+=(const wchar_t *str)
KString & MakeReverse()
Reverses the order of the characters in the KString object.
KString & Trim(const KString &charsTarget)
Trims leading and trailing characters from the string.
KString operator+(const KString &s1, const KString &s2)
Concatenate two strings.
int Delete(int iIndex, int nCount=1)
Deletes a character or characters from a string starting with the character at the given index.
KString Mid(int iFirst, int nCount=-1) const
Extracts a substring of length nCount characters from this KString object, starting at position iFirs...
KString & operator=(const char *str)
KString & operator=(QString &&str) noexcept
CString toCString() const
int Insert(int iIndex, QChar character)
Inserts a single character at the given index within the string.
int Compare(const KString &other) const
Compares two strings (case-sensitive).
KString(const QString &str)
KString & Trim(QChar chTarget)
Trims leading and trailing character from the string.
KString SpanIncluding(const KString &includeChars) const
Extracts characters from the string, starting with the first character, that are in the set of charac...
KString & TrimRight(QChar charTarget)
Trims trailing character from the string.
KString & operator=(const std::wstring_view str)
int CompareNoCase(const KString &other) const
Compares two strings (case-insensitive).
int Remove(QChar chRemove)
Removes all instances of the specified character from the string.
KString & MakeLower()
Converts all the characters in this string to lowercase characters.
static QString FormatString(T &&format, Ts... args)
Creates a QString by passing a format string and arguments, like CString::Format.
Definition kstring.h:374
bool IsEmpty() const
Tests whether a CString object contains no characters.
int Insert(int iIndex, const KString &string)
Inserts a substring at the given index within the string.
int FindOneOf(const KString &charSet) const
Searches this string for the first character that matches any character contained in charSet.
KString & MakeUpper()
Converts all the characters in this string to uppercase characters.
KString & Format(const wchar_t *format, Ts &&...args)
Formats the string as sprintf does.
Definition kstring.h:106
int Replace(const KString &before, const KString &after)
Replaces a substring by another substring. Both substrings are null-terminated.
KString(const std::wstring_view str)
KString(QString &&str) noexcept
KString Left(int nCount) const
Extracts the leftmost nCount characters from this string object.
KString & TrimLeft(QChar charTarget)
Trims leading character from the string.
KString & operator=(const QString &str)
KString & operator+=(const QString &str)
KString(const wchar_t *text)
KString & Trim()
Trims leading and trailing whitespace from the string.
int ReverseFind(QChar ch)
Searches this KString object for the last match of a character.
#define KDWINUTILS_EXPORT
Definition kdwinutils_export.h:31
#define KDWINUTILS_BEGIN_NAMESPACE
Definition kdwinutils_global.h:27
#define KDWINUTILS_END_NAMESPACE
Definition kdwinutils_global.h:28
#define KDWINUTILS_KSTRING_DEFINE_OP_PLUS(StringClass)
Definition kstring.h:351