Qx v0.5.7
Qt Extensions Library
Loading...
Searching...
No Matches
qx-string.h
1#ifndef QX_STRING_H
2#define QX_STRING_H
3
4// Shared Lib Support
5#include "qx/core/qx_core_export.h"
6
7// Qt Includes
8#include <QString>
9#include <QCryptographicHash>
10
11// Project Includes
13
14namespace Qx
15{
16
17class QX_CORE_EXPORT String
18{
19//-Class Functions----------------------------------------------------------------------------------------------
20public:
21 static bool isOnlyNumbers(QString checkStr);
22 static bool isHexNumber(QString hexNum);
23 static bool isValidChecksum(QString checksum, QCryptographicHash::Algorithm hashAlgorithm);
24 static QString stripToHexOnly(QString string);
25
26 template<typename T, typename F>
28 static QString join(QList<T> list, F&& toStringFunc, QString separator = {}, QString prefix = {})
29 {
30 QString conjuction;
31
32 for(int i = 0; i < list.length(); ++i)
33 {
34 conjuction += prefix;
35 conjuction += toStringFunc(list.at(i));
36 if(i < list.length() - 1)
37 conjuction += separator;
38 }
39
40 return conjuction;
41 }
42
43 static QString join(QList<QString> list, QString separator = {}, QString prefix = {}); // Overload for T = QString
44
45 template<typename T, typename F>
46 requires defines_call_for_s<F, QString, const T&>
47 static QString join(QSet<T> set, F&& toStringFunc, QString separator = {}, QString prefix = {})
48 {
49 QString conjuction;
50
51 typename QSet<T>::const_iterator i = set.constBegin();
52 while(i != set.constEnd())
53 {
54 conjuction += prefix;
55 conjuction += toStringFunc(*i);
56 if(++i != set.constEnd())
57 conjuction += separator;
58 }
59
60 return conjuction;
61 }
62
63 static QString join(QSet<QString> set, QString separator = {}, QString prefix = {}); // Overload for T = QString
64
65 static QString trimLeading(const QStringView string);
66 static QString trimTrailing(const QStringView string);
67};
68
69}
70
71#endif // QX_STRING_H
The String class is a collection of static functions pertaining to string types.
Definition qx-string.h:18
static QString join(QList< T > list, F &&toStringFunc, QString separator={}, QString prefix={})
Definition qx-string.h:28
static QString join(QSet< T > set, F &&toStringFunc, QString separator={}, QString prefix={})
Definition qx-string.h:47
Specifies that a type defines a call operator for the specified argument types (with strict return).
Definition qx-concepts.h:253
The Qx namespace is the main namespace through which all non-global functionality of the Qx library i...
Definition qx-processwaiter.cpp:5
QList::const_reference at(qsizetype i) const const
qsizetype length() const const
QSet::const_iterator constBegin() const const
QSet::const_iterator constEnd() const const
The qx-concepts header file provides a library of general purpose concepts as an extension of the sta...