18 enum class Empty { Keep, Skip };
19 enum class Case { Insensitive, Sensitive };
23 IString(
const string &s) : string(s) { }
24 IString(
string &&s) : string(std::move(s)) { }
25 IString(
const char *in) : string(in) { }
26 explicit IString(
int i,
char c) : string(i,c) { }
28 explicit IString(
char c) : string(1,c) { }
30 IString &operator=(
const IString &s) { string::operator=(s);
return *
this; }
31 IString &operator=(
IString &&s) { string::operator=(std::move(s));
return *
this; }
32 IString &operator=(
const char *str) { string::operator=(str);
return *
this; }
33 IString &operator=(
const string &s) { string::operator=(s);
return *
this; }
34 IString &operator=(
string &&s) { string::operator=(std::move(s));
return *
this; }
35 IString &operator=(
char c) { string::operator=({c});
return *
this; }
45 IString operator+(
const string &s)
const {
IString out(*
this); out += s;
return out; }
46 IString operator+(
const char *s)
const {
IString out(*
this); out += s;
return out; }
48 IString operator+=(
const IString &s) { string::operator+=(s);
return *
this; }
49 IString operator+=(
const char *str) { string::operator+=(str);
return *
this; }
50 IString operator+=(
const string &s) { string::operator+=(s);
return *
this; }
51 IString operator+=(
char c) { string::operator+=(c);
return *
this; }
54 int size()
const {
return to<int>(string::size()); }
55 int length()
const {
return size(); }
56 IString mid(
int start,
int end)
const {
return substr(to<size_type>(start),to<size_type>(end)); }
57 IString mid(
int start)
const { size_type s = to<size_type>(start);
return s<string::size() ? substr(to<size_type>(start)) :
string{}; }
58 IString left(
int pos)
const {
return substr(0,to<size_type>(pos)); }
59 IString right(
int pos)
const {
if ((pos<0) || (pos>=to<int>(size())))
return *
this;
return substr(size()-to<size_type>(pos),size()); }
60 int indexOf(
char c,
int start=0)
const {
auto pos = find(c,start);
if (pos==string::npos)
return -1;
return to<int>(pos); }
61 int indexOf(
const IString &s,
int start=0) {
auto pos = find(s,start);
if (pos==string::npos)
return -1;
return to<int>(pos); }
62 int lastIndexOf(
char c)
const {
auto pos = rfind(c);
if (pos==string::npos)
return -1;
return to<int>(pos); }
63 int lastIndexOf(
const IString &s)
const {
auto pos = rfind(s);
if (pos==string::npos)
return -1;
return to<int>(pos); }
66 IString simplified()
const { return ::simplified(*
this); }
67 string toStdString()
const {
return *
this; }
68 std::wstring toStdWString()
const {
return towstring(*
this); }
69 bool isEmpty()
const {
return size()==0; }
70 int compare(
const IString &s,Case c=Case::Sensitive)
const {
return compare(*
this,s,c); }
72 IString toLower()
const { return ::toLower(*
this); }
73 IString toUpper()
const { return ::toUpper(*
this); }
74 int32 toInt(
bool *ok=
nullptr)
const {
auto [i,ok2] = ::isInt32(*
this);
if (ok) *ok = ok2;
return i; }
75 uint32 toUInt(
bool *ok=
nullptr)
const {
auto [u,ok2] =
::isUInt32(*
this);
if (ok) *ok = ok2;
return u; }
76 uint64 toULongLong(
bool *ok=
nullptr)
const {
auto [u,ok2] =
::isUInt64(*
this);
if (ok) *ok = ok2;
return u; }
77 int64 toLongLong(
bool *ok=
nullptr)
const {
auto [i,ok2] =
::isInt64(*
this);
if (ok) *ok = ok2;
return i; }
78 double toDouble(
bool *ok=
nullptr)
const {
auto [d,ok2] = ::isDouble(*
this);
if (ok) *ok = ok2;
return d; }
81 IString toString()
const {
return *
this; }
88 IString trimmed()
const { return ::trimmed(*
this); }
91 IString arg(
float f,
int width=0,
char format=
'g',
int precision=0,
char fill=
' ')
const {
return arg(base::ts(f,width,format,precision,fill)); }
92 IString arg(
double d,
int width=0,
char format=
'g',
int precision=0,
char fill=
' ')
const;
93 IString arg(uint32 i,
int width=0,[[maybe_unused]]
int base=10,
char fill=
' ')
const {
return arg(base::ts(i,width,
'\0',-1,fill)); }
94 IString arg(uint64 i,
int width=0,[[maybe_unused]]
int base=10,
char fill=
' ')
const {
return arg(base::ts(i,width,
'\0',-1,fill)); }
95 IString arg(int32 i,
int width=0,[[maybe_unused]]
int base=10,
char fill=
' ')
const {
return arg(base::ts(i,width,
'\0',-1,fill)); }
96 IString arg(int64 i,
int width=0,[[maybe_unused]]
int base=10,
char fill=
' ')
const {
return arg(base::ts(i,width,
'\0',-1,fill)); }
110 IString &insert(
int position,
const IString &s) { string::insert(position,s);
return *
this; }
112 inline static IString fromStdString(
const string &s) {
return IString(s); }
113 inline static IString fromStdU16String(
const std::u16string &s) {
return tostring(s); }
114 inline static IString fromStdWString(
const std::wstring &s) {
return tostring(s); }
115 inline static IString fromUtf8(
const char *str) {
return str; }
116 inline static IString fromUtf8(
const char *str,
size_t size) {
return string(str,size); }
117 inline static IString fromLatin1(
const char *str) {
return str; }
122template <
typename ... Args>
IString build(
const IString &in,Args &&...args);
123template <
typename T>
IString toIString(
const T &t,
int width=0,
char format=
'\0',
int precision=-1,
char fill=
' ') {
return base::ts(t,width,format,precision,fill); }
125inline IString toIString(
const IString &v,
int width=0,
char fill=
' ') {
return base::ts(v,width,
'\0',-1,fill); }
126inline IString toIString(
const char *v ,
int width=0,
char fill=
' ') {
return base::ts(v,width,
'\0',-1,fill); }
127inline IString toIString(
const int8 &v ,
int width=0,
char fill=
' ') {
return base::ts(v,width,
'\0',-1,fill); }
128inline IString toIString(
const uint8 &v ,
int width=0,
char fill=
' ') {
return base::ts(v,width,
'\0',-1,fill); }
129inline IString toIString(
const int16 &v ,
int width=0,
char fill=
' ') {
return base::ts(v,width,
'\0',-1,fill); }
130inline IString toIString(
const uint16 &v ,
int width=0,
char fill=
' ') {
return base::ts(v,width,
'\0',-1,fill); }
131inline IString toIString(
const int32 &v ,
int width=0,
char fill=
' ') {
return base::ts(v,width,
'\0',-1,fill); }
132inline IString toIString(
const uint32 &v ,
int width=0,
char fill=
' ') {
return base::ts(v,width,
'\0',-1,fill); }
133inline IString toIString(
const int64 &v ,
int width=0,
char fill=
' ') {
return base::ts(v,width,
'\0',-1,fill); }
134inline IString toIString(
const uint64 &v ,
int width=0,
char fill=
' ') {
return base::ts(v,width,
'\0',-1,fill); }
135inline IString toIString(
const string &v ,
int width ,
char fill=
' ') {
return base::ts(v,width,
'\0',-1,fill); }
136inline IString toIString(
const void *v,
int width=0,
char fill=
' ') {
return base::ts(v,width,
'\0',-1,fill); }
140inline string tostring(
const IString &s) {
return s; }
144inline bool isInt(
const IString &s,int32 *i=
nullptr) {
auto [i2,ok] = ::isInt32(string_view(s));
if (i && ok) *i = i2;
return ok; }
145inline bool isDouble(
const IString &s,
double *d=
nullptr) {
auto [d2,ok] = ::isDouble(string_view(s));
if (d && ok) *d = d2;
return ok; }
146inline bool isUInt(
const IString &s,uint32 *u=
nullptr) {
auto [u2,ok] =
::isUInt32(string_view(s));
if (u && ok) *u = u2;
return ok; }
147inline bool isULong(
const IString &s,uint64 *u=
nullptr) {
auto [u2,ok] =
::isUInt64(string_view(s));
if (u && ok) *u = u2;
return ok; }
148inline bool isLong(
const IString &s,int64 *i=
nullptr) {
auto [i2,ok] =
::isInt64(string_view(s));
if (i && ok) *i = i2;
return ok; }
174template <
typename ... Args>
176 return fmt::format(convertPercentToBracket(in),args...);
179template <
typename T>
using IStringMap = std::map<IString, T, StringCILess>;
180template <
typename T>
using IStringHashMap = std::unordered_map<IString, T, StringCIHash, StringCIEqual>;
181using IStringSet = std::set<IString,StringCILess>;
185 size_t operator()(
const IString &in)
const { std::hash<string> h;
return h(in); }
QString helper functions, plus some additions.
Definition basestring.h:159
Definition istringlist.h:10
bool isLong(const QString &in, qint64 *l)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition baseqstring.cpp:257
bool isUInt(const QString &in, uint *u)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition baseqstring.cpp:250
bool isDouble(const QString &in, double *d)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition baseqstring.cpp:271
bool isInt(const QString &in, int *i)
Definition baseqstring.cpp:243
std::tuple< uint64, bool > isUInt64(const string_view &s)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition basestring.cpp:52
std::tuple< uint32, bool > isUInt32(const string_view &s)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition basestring.cpp:34
#define BASE_EXPORT
Definition basedef.h:24
bool match(const string &keyword, const string &token)
**
Definition basestring.cpp:462
POPWARNING QDataStream & operator<<(QDataStream &ds, const Orientation2 &o)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition basetoqt.cpp:107
bool isULong(const QString &in, quint64 *ul)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition baseqstring.cpp:264
std::tuple< int64, bool > isInt64(const string_view &s)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition basestring.cpp:43
A overflow checked shorthand for static_cast<T>().