1 /**************************************************************************** 2 ** 3 ** DQt - D bindings for the Qt Toolkit 4 ** 5 ** GNU Lesser General Public License Usage 6 ** This file may be used under the terms of the GNU Lesser 7 ** General Public License version 3 as published by the Free Software 8 ** Foundation and appearing in the file LICENSE.LGPL3 included in the 9 ** packaging of this file. Please review the following information to 10 ** ensure the GNU Lesser General Public License version 3 requirements 11 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. 12 ** 13 ****************************************************************************/ 14 module qt.core..string; 15 extern(C++): 16 17 import core.stdc.config; 18 import core.stdc.stddef; 19 import core.vararg; 20 import qt.config; 21 import qt.core.arraydata; 22 import qt.core.bytearray; 23 import qt.core.flags; 24 import qt.core.global; 25 import qt.core.metatype; 26 import qt.core.namespace; 27 import qt.core.qchar; 28 import qt.core.regularexpression; 29 import qt.core.stringlist; 30 import qt.core.stringliteral; 31 import qt.core.stringview; 32 import qt.core.typeinfo; 33 import qt.core.vector; 34 import qt.helpers; 35 version(QT_NO_REGEXP){}else 36 import qt.core.regexp; 37 38 /+ #if defined(QT_NO_CAST_FROM_ASCII) && defined(QT_RESTRICTED_CAST_FROM_ASCII) 39 #error QT_NO_CAST_FROM_ASCII and QT_RESTRICTED_CAST_FROM_ASCII must not be defined at the same time 40 #endif 41 42 #ifdef truncate 43 #error qstring.h must be included before any header file that defines truncate 44 #endif 45 46 #if defined(Q_OS_DARWIN) || defined(Q_QDOC) 47 Q_FORWARD_DECLARE_CF_TYPE(CFString); 48 Q_FORWARD_DECLARE_OBJC_CLASS(NSString); 49 #endif 50 51 52 class QCharRef; 53 class QRegularExpression; 54 class QRegularExpressionMatch; 55 class QString; 56 class QStringList; 57 class QTextCodec; 58 class QStringRef; 59 template <typename T> class QVector; 60 61 namespace QtPrivate { 62 template <bool...B> class BoolList; 63 } +/ 64 65 @Q_MOVABLE_TYPE extern(C++, class) struct QLatin1String 66 { 67 public: 68 static import qt.core.stringalgorithms; 69 @disable this(); 70 /+pragma(inline, true) this()/+ noexcept+/ 71 { 72 this.m_size = 0; 73 this.m_data = null; 74 }+/ 75 /+ explicit +/pragma(inline, true) this(const(char)* s)/+ noexcept+/ 76 { 77 import core.stdc.string; 78 this.m_size = s ? cast(int)(strlen(s)) : 0; 79 this.m_data = s; 80 } 81 /+ explicit +/this(const(char)* f, const(char)* l) 82 { 83 this(f, cast(int)(l - f)); 84 } 85 /+ explicit +/pragma(inline, true) this(const(char)* s, int sz)/+ noexcept+/ 86 { 87 this.m_size = sz; 88 this.m_data = s; 89 } 90 /+ explicit +/pragma(inline, true) this(ref const(QByteArray) s)/+ noexcept+/ 91 { 92 this.m_size = int(qstrnlen(s.constData(), s.size())); 93 this.m_data = s.constData(); 94 } 95 96 const(char)* latin1() const/+ noexcept+/ { return m_data; } 97 int size() const/+ noexcept+/ { return m_size; } 98 const(char)* data() const/+ noexcept+/ { return m_data; } 99 100 bool isNull() const/+ noexcept+/ { return !data(); } 101 bool isEmpty() const/+ noexcept+/ { return !size(); } 102 103 /+ template <typename...Args> +/ 104 /+ Q_REQUIRED_RESULT inline QString arg(Args &&...args) const; +/ 105 106 QLatin1Char at(int i) const 107 { return (){(){ (mixin(Q_ASSERT(q{i >= 0}))); 108 return /+ Q_ASSERT(i < size()) +/ mixin(Q_ASSERT(q{i < QLatin1String.size()})); 109 }(); 110 return QLatin1Char(m_data[i]); 111 }(); } 112 QLatin1Char opIndex(int i) const { return at(i); } 113 114 /+ Q_REQUIRED_RESULT +/ QLatin1Char front() const { return at(0); } 115 /+ Q_REQUIRED_RESULT +/ QLatin1Char back() const { return at(size() - 1); } 116 117 /+ Q_REQUIRED_RESULT +/ int compare(QStringView other, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const/+ noexcept+/ 118 { 119 import qt.core.stringalgorithms; 120 return /+ QtPrivate:: +/qt.core.stringalgorithms.compareStrings(this, other, cs); 121 } 122 /+ Q_REQUIRED_RESULT +/ int compare(QLatin1String other, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const/+ noexcept+/ 123 { 124 import qt.core.stringalgorithms; 125 return /+ QtPrivate:: +/qt.core.stringalgorithms.compareStrings(this, other, cs); 126 } 127 /+ Q_REQUIRED_RESULT +/ int compare(QChar c) const/+ noexcept+/ 128 { return isEmpty() || front().unicode == c.unicode ? size() - 1 : uchar(m_data[0]) - c.unicode() ; } 129 /+ Q_REQUIRED_RESULT +/ int compare(QChar c, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs) const/+ noexcept+/ 130 { 131 import qt.core.stringalgorithms; 132 return /+ QtPrivate:: +/qt.core.stringalgorithms.compareStrings(this, QStringView(&c, 1), cs); 133 } 134 135 /+ Q_REQUIRED_RESULT +/ bool startsWith(QStringView s, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const/+ noexcept+/ 136 { 137 import qt.core.stringalgorithms; 138 return /+ QtPrivate:: +/qt.core.stringalgorithms.startsWith(this, s, cs); 139 } 140 /+ Q_REQUIRED_RESULT +/ bool startsWith(QLatin1String s, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const/+ noexcept+/ 141 { 142 import qt.core.stringalgorithms; 143 return /+ QtPrivate:: +/qt.core.stringalgorithms.startsWith(this, s, cs); 144 } 145 /+ Q_REQUIRED_RESULT +/ bool startsWith(QChar c) const/+ noexcept+/ 146 { return !isEmpty() && front().unicode == c.unicode; } 147 /+ Q_REQUIRED_RESULT +/ pragma(inline, true) bool startsWith(QChar c, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs) const/+ noexcept+/ 148 { 149 import qt.core.stringalgorithms; 150 return /+ QtPrivate:: +/qt.core.stringalgorithms.startsWith(this, QStringView(&c, 1), cs); 151 } 152 153 /+ Q_REQUIRED_RESULT +/ bool endsWith(QStringView s, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const/+ noexcept+/ 154 { 155 import qt.core.stringalgorithms; 156 return /+ QtPrivate:: +/qt.core.stringalgorithms.endsWith(this, s, cs); 157 } 158 /+ Q_REQUIRED_RESULT +/ bool endsWith(QLatin1String s, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const/+ noexcept+/ 159 { 160 import qt.core.stringalgorithms; 161 return /+ QtPrivate:: +/qt.core.stringalgorithms.endsWith(this, s, cs); 162 } 163 /+ Q_REQUIRED_RESULT +/ bool endsWith(QChar c) const/+ noexcept+/ 164 { return !isEmpty() && back().unicode == c.unicode; } 165 /+ Q_REQUIRED_RESULT +/ pragma(inline, true) bool endsWith(QChar c, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs) const/+ noexcept+/ 166 { 167 import qt.core.stringalgorithms; 168 return /+ QtPrivate:: +/qt.core.stringalgorithms.endsWith(this, QStringView(&c, 1), cs); 169 } 170 171 /+ Q_REQUIRED_RESULT +/ int indexOf(QStringView s, int from = 0, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const/+ noexcept+/ 172 { 173 import qt.core.stringalgorithms; 174 return cast(int)(/+ QtPrivate:: +/qt.core.stringalgorithms.findString(this, from, s, cs)); 175 } // ### Qt6: qsizetype 176 /+ Q_REQUIRED_RESULT +/ int indexOf(QLatin1String s, int from = 0, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const/+ noexcept+/ 177 { 178 import qt.core.stringalgorithms; 179 return cast(int)(/+ QtPrivate:: +/qt.core.stringalgorithms.findString(this, from, s, cs)); 180 } // ### Qt6: qsizetype 181 /+ Q_REQUIRED_RESULT +/ pragma(inline, true) int indexOf(QChar c, int from = 0, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const/+ noexcept+/ 182 { 183 import qt.core.stringalgorithms; 184 return cast(int)(/+ QtPrivate:: +/qt.core.stringalgorithms.findString(this, from, QStringView(&c, 1), cs)); 185 } // ### Qt6: qsizetype 186 187 /+ Q_REQUIRED_RESULT +/ bool contains(QStringView s, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const/+ noexcept+/ 188 { return indexOf(s, 0, cs) != -1; } 189 /+ Q_REQUIRED_RESULT +/ bool contains(QLatin1String s, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const/+ noexcept+/ 190 { return indexOf(s, 0, cs) != -1; } 191 /+ Q_REQUIRED_RESULT +/ pragma(inline, true) bool contains(QChar c, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const/+ noexcept+/ 192 { return indexOf(QStringView(&c, 1), 0, cs) != -1; } 193 194 /+ Q_REQUIRED_RESULT +/ int lastIndexOf(QStringView s, int from = -1, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const/+ noexcept+/ 195 { 196 import qt.core.stringalgorithms; 197 return cast(int)(/+ QtPrivate:: +/qt.core.stringalgorithms.lastIndexOf(this, from, s, cs)); 198 } // ### Qt6: qsizetype 199 /+ Q_REQUIRED_RESULT +/ int lastIndexOf(QLatin1String s, int from = -1, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const/+ noexcept+/ 200 { 201 import qt.core.stringalgorithms; 202 return cast(int)(/+ QtPrivate:: +/qt.core.stringalgorithms.lastIndexOf(this, from, s, cs)); 203 } // ### Qt6: qsizetype 204 /+ Q_REQUIRED_RESULT +/ pragma(inline, true) int lastIndexOf(QChar c, int from = -1, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const/+ noexcept+/ 205 { 206 import qt.core.stringalgorithms; 207 return cast(int)(/+ QtPrivate:: +/qt.core.stringalgorithms.lastIndexOf(this, from, QStringView(&c, 1), cs)); 208 } // ### Qt6: qsizetype 209 210 alias value_type = const(char); 211 /+ using reference = value_type&; +/ 212 /+ using const_reference = reference; +/ 213 alias iterator = value_type*; 214 alias const_iterator = iterator; 215 alias difference_type = int; // violates Container concept requirements 216 alias size_type = int; // violates Container concept requirements 217 218 const_iterator begin() const/+ noexcept+/ { return data(); } 219 const_iterator cbegin() const/+ noexcept+/ { return data(); } 220 const_iterator end() const/+ noexcept+/ { return data() + size(); } 221 const_iterator cend() const/+ noexcept+/ { return data() + size(); } 222 223 /+ using reverse_iterator = std::reverse_iterator<iterator>; +/ 224 /+ using const_reverse_iterator = reverse_iterator; +/ 225 226 /+ const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(end()); } +/ 227 /+ const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(end()); } +/ 228 /+ const_reverse_iterator rend() const noexcept { return const_reverse_iterator(begin()); } +/ 229 /+ const_reverse_iterator crend() const noexcept { return const_reverse_iterator(begin()); } +/ 230 231 QLatin1String mid(int pos) const 232 { return (){(){ (mixin(Q_ASSERT(q{pos >= 0}))); 233 return /+ Q_ASSERT(pos <= size()) +/ mixin(Q_ASSERT(q{pos <= QLatin1String.size()})); 234 }(); 235 return QLatin1String(m_data + pos, m_size - pos); 236 }(); } 237 QLatin1String mid(int pos, int n) const 238 { return (){(){(){ (mixin(Q_ASSERT(q{pos >= 0}))); 239 return /+ Q_ASSERT(n >= 0) +/ mixin(Q_ASSERT(q{n >= 0})); 240 }(); 241 return /+ Q_ASSERT(pos + n <= size()) +/ mixin(Q_ASSERT(q{pos + n <= QLatin1String.size()})); 242 }(); 243 return QLatin1String(m_data + pos, n); 244 }(); } 245 QLatin1String left(int n) const 246 { return (){(){ (mixin(Q_ASSERT(q{n >= 0}))); 247 return /+ Q_ASSERT(n <= size()) +/ mixin(Q_ASSERT(q{n <= QLatin1String.size()})); 248 }(); 249 return QLatin1String(m_data, n); 250 }(); } 251 QLatin1String right(int n) const 252 { return (){(){ (mixin(Q_ASSERT(q{n >= 0}))); 253 return /+ Q_ASSERT(n <= size()) +/ mixin(Q_ASSERT(q{n <= QLatin1String.size()})); 254 }(); 255 return QLatin1String(m_data + m_size - n, n); 256 }(); } 257 /+ Q_REQUIRED_RESULT +/ QLatin1String chopped(int n) const 258 { return (){(){ (mixin(Q_ASSERT(q{n >= 0}))); 259 return /+ Q_ASSERT(n <= size()) +/ mixin(Q_ASSERT(q{n <= QLatin1String.size()})); 260 }(); 261 return QLatin1String(m_data, m_size - n); 262 }(); } 263 264 void chop(int n) 265 { (mixin(Q_ASSERT(q{n >= 0}))); (mixin(Q_ASSERT(q{n <= QLatin1String.size()}))); m_size -= n; } 266 void truncate(int n) 267 { (mixin(Q_ASSERT(q{n >= 0}))); (mixin(Q_ASSERT(q{n <= QLatin1String.size()}))); m_size = n; } 268 269 /+ Q_REQUIRED_RESULT +/ QLatin1String trimmed() const/+ noexcept+/ { 270 import qt.core.stringalgorithms; 271 return /+ QtPrivate:: +/qt.core.stringalgorithms.trimmed(this); 272 } 273 274 /+pragma(inline, true) bool operator ==(ref const(QString) s) const/+ noexcept+/ 275 { return s == this; }+/ 276 /+pragma(inline, true) bool operator !=(ref const(QString) s) const/+ noexcept+/ 277 { return s != this; }+/ 278 /+pragma(inline, true) bool operator >(ref const(QString) s) const/+ noexcept+/ 279 { return s < this; }+/ 280 /+pragma(inline, true) bool operator <(ref const(QString) s) const/+ noexcept+/ 281 { return s > this; }+/ 282 /+pragma(inline, true) bool operator >=(ref const(QString) s) const/+ noexcept+/ 283 { return s <= this; }+/ 284 /+pragma(inline, true) bool operator <=(ref const(QString) s) const/+ noexcept+/ 285 { return s >= this; }+/ 286 287 /+ #if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) 288 inline QT_ASCII_CAST_WARN bool operator==(const char *s) const; 289 inline QT_ASCII_CAST_WARN bool operator!=(const char *s) const; 290 inline QT_ASCII_CAST_WARN bool operator<(const char *s) const; 291 inline QT_ASCII_CAST_WARN bool operator>(const char *s) const; 292 inline QT_ASCII_CAST_WARN bool operator<=(const char *s) const; 293 inline QT_ASCII_CAST_WARN bool operator>=(const char *s) const; 294 295 inline QT_ASCII_CAST_WARN bool operator==(const QByteArray &s) const; 296 inline QT_ASCII_CAST_WARN bool operator!=(const QByteArray &s) const; 297 inline QT_ASCII_CAST_WARN bool operator<(const QByteArray &s) const; 298 inline QT_ASCII_CAST_WARN bool operator>(const QByteArray &s) const; 299 inline QT_ASCII_CAST_WARN bool operator<=(const QByteArray &s) const; 300 inline QT_ASCII_CAST_WARN bool operator>=(const QByteArray &s) const; 301 #endif +/ // !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) 302 303 private: 304 int m_size = 0; 305 const(char)* m_data = null; 306 } 307 /+ Q_DECLARE_TYPEINFO(QLatin1String, Q_MOVABLE_TYPE); 308 309 // Qt 4.x compatibility 310 #if QT_DEPRECATED_SINCE(5, 14) +/ 311 /+ QT_DEPRECATED_X("Use QLatin1String") +/ 312 alias QLatin1Literal = QLatin1String; 313 /+ #endif +/ 314 315 // 316 // QLatin1String inline implementations 317 // 318 bool isLatin1(QLatin1String)/+ noexcept+/ 319 { return true; } 320 static if(!versionIsSet!("QT_COMPILING_QSTRING_COMPAT_CPP") && defined!"Q_COMPILER_REF_QUALIFIERS") 321 { 322 /+ # define Q_REQUIRED_RESULT 323 # define Q_REQUIRED_RESULT_pushed +/ 324 } 325 326 @(QMetaType.Type.QString) @Q_MOVABLE_TYPE extern(C++, class) struct /+ Q_CORE_EXPORT +/ QString 327 { 328 public: 329 static import qt.core.stringalgorithms; 330 static import qt.core.namespace; 331 alias Data = QStringData; 332 333 version(Windows) 334 { 335 @disable this(); 336 pragma(inline, true) void rawConstructor()/+ noexcept+/ 337 { 338 this.d = Data.sharedNull(); 339 } 340 static typeof(this) create() 341 { 342 typeof(this) r = typeof(this).init; 343 r.rawConstructor(); 344 return r; 345 } 346 } 347 else 348 { 349 static typeof(this) create() 350 { 351 return typeof(this).init; 352 } 353 } 354 355 /+ explicit +/this(const(QChar)* unicode, int size = -1); 356 this(QChar c); 357 this(int size, QChar c); 358 359 extern(D) this(const(wchar)[] unicode) 360 { 361 this(cast(const(QChar)*) unicode.ptr, cast(int)unicode.length); 362 } 363 364 extern(D) this(const(char)[] unicode) 365 { 366 QString s = fromUtf8_helper(unicode.ptr, cast(int)unicode.length); 367 this.d = s.d; 368 s.d = Data.sharedNull(); 369 } 370 371 extern(D) this(const(dchar)[] unicode) 372 { 373 QString s = fromUcs4(unicode.ptr, cast(int)unicode.length); 374 this.d = s.d; 375 s.d = Data.sharedNull(); 376 } 377 378 // 379 // QString inline members 380 // 381 pragma(inline, true) this(QLatin1String aLatin1) 382 { 383 this.d = fromLatin1_helper(aLatin1.latin1(), aLatin1.size()); 384 } 385 this(this) 386 { 387 d.ref_.ref_(); 388 } 389 pragma(inline, true) ~this() { if (!d.ref_.deref()) Data.deallocate(d); } 390 /+ref QString operator =(QChar c);+/ 391 /+ref QString operator =(ref const(QString) )/+ noexcept+/;+/ 392 /+ref QString operator =(QLatin1String latin1);+/ 393 /+ inline QString(QString && other) noexcept : d(other.d) { other.d = Data::sharedNull(); } +/ 394 /+ inline QString &operator=(QString &&other) noexcept 395 { qSwap(d, other.d); return *this; } +/ 396 /+ inline void swap(QString &other) noexcept { qSwap(d, other.d); } +/ 397 pragma(inline, true) int size() const { return d.base0.size; } 398 pragma(inline, true) int count() const { return d.base0.size; } 399 pragma(inline, true) int length() const 400 { return d.size; } 401 pragma(inline, true) bool isEmpty() const 402 { return d.size == 0; } 403 void resize(int size); 404 void resize(int size, QChar fillChar); 405 406 ref QString fill(QChar c, int size = -1); 407 void truncate(int pos); 408 void chop(int n); 409 410 pragma(inline, true) int capacity() const 411 { return d.alloc ? d.alloc - 1 : 0; } 412 pragma(inline, true) void reserve(int asize) 413 { 414 if (d.ref_.isShared() || uint(asize) >= d.alloc) 415 reallocData(qMax(asize, d.size) + 1u); 416 417 if (!d.capacityReserved) { 418 // cannot set unconditionally, since d could be the shared_null/shared_empty (which is const) 419 d.capacityReserved = true; 420 } 421 } 422 pragma(inline, true) void squeeze() 423 { 424 if (d.ref_.isShared() || uint(d.size) + 1u < d.alloc) 425 reallocData(uint(d.size) + 1u); 426 427 if (d.capacityReserved) { 428 // cannot set unconditionally, since d could be shared_null or 429 // otherwise static. 430 d.capacityReserved = false; 431 } 432 } 433 434 pragma(inline, true) const(QChar)* unicode() const 435 { return reinterpret_cast!(const(QChar)*)(d.data()); } 436 pragma(inline, true) QChar* data() 437 { detach(); return reinterpret_cast!(QChar*)(d.data()); } 438 pragma(inline, true) const(QChar)* data() const 439 { return reinterpret_cast!(const(QChar)*)(d.data()); } 440 pragma(inline, true) const(QChar)* constData() const 441 { return reinterpret_cast!(const(QChar)*)(d.data()); } 442 443 extern(D) const(wchar)[] toConstWString() 444 { 445 return (cast(const(wchar)*)constData())[0..length]; 446 } 447 448 pragma(inline, true) void detach() 449 { if (d.ref_.isShared() || (d.offset != QStringData.sizeof)) reallocData(uint(d.size) + 1u); } 450 pragma(inline, true) bool isDetached() const 451 { return !d.ref_.isShared(); } 452 pragma(inline, true) bool isSharedWith(ref const(QString) other) const { return d == other.d; } 453 pragma(inline, true) void clear() 454 { if (!isNull()) this = QString.create(); } 455 456 pragma(inline, true) const(QChar) at(int i) const 457 { (mixin(Q_ASSERT(q{uint(i) < uint(QString.size())}))); return QChar(d.data()[i]); } 458 pragma(inline, true) const(QChar) opIndex(int i) const 459 { (mixin(Q_ASSERT(q{uint(i) < uint(QString.size())}))); return QChar(d.data()[i]); } 460 /+ Q_REQUIRED_RESULT +/ pragma(inline, true) QCharRef opIndex(int i) 461 { (mixin(Q_ASSERT(q{i >= 0}))); detach(); return QCharRef(this, i); } 462 pragma(inline, true) const(QChar) opIndex(uint i) const 463 { (mixin(Q_ASSERT(q{i < uint(QString.size())}))); return QChar(d.data()[i]); } 464 /+ Q_REQUIRED_RESULT +/ pragma(inline, true) QCharRef opIndex(uint i) 465 { detach(); return QCharRef(this, i); } 466 467 /+ Q_REQUIRED_RESULT +/ pragma(inline, true) QChar front() const { return at(0); } 468 /+ Q_REQUIRED_RESULT +/ pragma(inline, true) QCharRef front() { return opIndex(0); } 469 /+ Q_REQUIRED_RESULT +/ pragma(inline, true) QChar back() const { return at(size() - 1); } 470 /+ Q_REQUIRED_RESULT +/ pragma(inline, true) QCharRef back() { return opIndex(size() - 1); } 471 472 /+ Q_REQUIRED_RESULT +/ QString arg(qlonglong a, int fieldwidth=0, int base=10, 473 QChar fillChar = QChar(QLatin1Char(' '))) const; 474 /+ Q_REQUIRED_RESULT +/ QString arg(qulonglong a, int fieldwidth=0, int base=10, 475 QChar fillChar = QLatin1Char(' ')) const; 476 /+ Q_REQUIRED_RESULT +/ pragma(inline, true) QString arg(cpp_long a, int fieldWidth=0, int base=10, 477 QChar fillChar = QLatin1Char(' ')) const 478 { return arg(qlonglong(a), fieldWidth, base, fillChar); } 479 /+ Q_REQUIRED_RESULT +/ pragma(inline, true) QString arg(cpp_ulong a, int fieldWidth=0, int base=10, 480 QChar fillChar = QLatin1Char(' ')) const 481 { return arg(qulonglong(a), fieldWidth, base, fillChar); } 482 /+ Q_REQUIRED_RESULT +/ pragma(inline, true) QString arg(int a, int fieldWidth = 0, int base = 10, 483 QChar fillChar = QLatin1Char(' ')) const 484 { return arg(qlonglong(a), fieldWidth, base, fillChar); } 485 /+ Q_REQUIRED_RESULT +/ pragma(inline, true) QString arg(uint a, int fieldWidth = 0, int base = 10, 486 QChar fillChar = QLatin1Char(' ')) const 487 { return arg(qulonglong(a), fieldWidth, base, fillChar); } 488 /+ Q_REQUIRED_RESULT +/ pragma(inline, true) QString arg(short a, int fieldWidth = 0, int base = 10, 489 QChar fillChar = QLatin1Char(' ')) const 490 { return arg(qlonglong(a), fieldWidth, base, fillChar); } 491 /+ Q_REQUIRED_RESULT +/ pragma(inline, true) QString arg(ushort a, int fieldWidth = 0, int base = 10, 492 QChar fillChar = QLatin1Char(' ')) const 493 { return arg(qulonglong(a), fieldWidth, base, fillChar); } 494 /+ Q_REQUIRED_RESULT +/ QString arg(double a, int fieldWidth = 0, char fmt = 'g', int prec = -1, 495 QChar fillChar = QLatin1Char(' ')) const; 496 /+ Q_REQUIRED_RESULT +/ QString arg(char a, int fieldWidth = 0, 497 QChar fillChar = QLatin1Char(' ')) const; 498 /+ Q_REQUIRED_RESULT +/ QString arg(QChar a, int fieldWidth = 0, 499 QChar fillChar = QLatin1Char(' ')) const; 500 static if(QT_STRINGVIEW_LEVEL < 2) 501 { 502 /+ Q_REQUIRED_RESULT +/ QString arg(ref const(QString) a, int fieldWidth = 0, 503 QChar fillChar = QLatin1Char(' ')) const; 504 } 505 /+ Q_REQUIRED_RESULT +/ QString arg(QStringView a, int fieldWidth = 0, 506 QChar fillChar = QLatin1Char(' ')) const; 507 /+ Q_REQUIRED_RESULT +/ QString arg(QLatin1String a, int fieldWidth = 0, 508 QChar fillChar = QLatin1Char(' ')) const; 509 static if(QT_STRINGVIEW_LEVEL < 2) 510 { 511 /+ /+ Q_REQUIRED_RESULT +/ pragma(inline, true) QString arg(ref const(QString) a1, ref const(QString) a2) const 512 { return qToStringViewIgnoringNull(this).arg(a1, a2); } 513 /+ Q_REQUIRED_RESULT +/ pragma(inline, true) QString arg(ref const(QString) a1, ref const(QString) a2, ref const(QString) a3) const 514 { return qToStringViewIgnoringNull(this).arg(a1, a2, a3); } 515 /+ Q_REQUIRED_RESULT +/ pragma(inline, true) QString arg(ref const(QString) a1, ref const(QString) a2, ref const(QString) a3, 516 ref const(QString) a4) const 517 { return qToStringViewIgnoringNull(this).arg(a1, a2, a3, a4); } 518 /+ Q_REQUIRED_RESULT +/ pragma(inline, true) QString arg(ref const(QString) a1, ref const(QString) a2, ref const(QString) a3, 519 ref const(QString) a4, ref const(QString) a5) const 520 { return qToStringViewIgnoringNull(this).arg(a1, a2, a3, a4, a5); } 521 /+ Q_REQUIRED_RESULT +/ pragma(inline, true) QString arg(ref const(QString) a1, ref const(QString) a2, ref const(QString) a3, 522 ref const(QString) a4, ref const(QString) a5, ref const(QString) a6) const 523 { return qToStringViewIgnoringNull(this).arg(a1, a2, a3, a4, a5, a6); } 524 /+ Q_REQUIRED_RESULT +/ pragma(inline, true) QString arg(ref const(QString) a1, ref const(QString) a2, ref const(QString) a3, 525 ref const(QString) a4, ref const(QString) a5, ref const(QString) a6, 526 ref const(QString) a7) const 527 { return qToStringViewIgnoringNull(this).arg(a1, a2, a3, a4, a5, a6, a7); } 528 /+ Q_REQUIRED_RESULT +/ pragma(inline, true) QString arg(ref const(QString) a1, ref const(QString) a2, ref const(QString) a3, 529 ref const(QString) a4, ref const(QString) a5, ref const(QString) a6, 530 ref const(QString) a7, ref const(QString) a8) const 531 { return qToStringViewIgnoringNull(this).arg(a1, a2, a3, a4, a5, a6, a7, a8); } 532 /+ Q_REQUIRED_RESULT +/ pragma(inline, true) QString arg(ref const(QString) a1, ref const(QString) a2, ref const(QString) a3, 533 ref const(QString) a4, ref const(QString) a5, ref const(QString) a6, 534 ref const(QString) a7, ref const(QString) a8, ref const(QString) a9) const 535 { return qToStringViewIgnoringNull(this).arg(a1, a2, a3, a4, a5, a6, a7, a8, a9); } 536 +/ 537 } 538 private: 539 /+ template <typename T> +/ 540 /+ struct is_convertible_to_view_or_qstring_helper 541 : std::integral_constant<bool, 542 std::is_convertible<T, QString>::value || 543 std::is_convertible<T, QStringView>::value || 544 std::is_convertible<T, QLatin1String>::value> {}; +/ 545 /+ template <typename T> +/ 546 /+ struct is_convertible_to_view_or_qstring 547 : is_convertible_to_view_or_qstring_helper<typename std::decay<T>::type> {}; +/ 548 public: 549 /+ template <typename...Args> +/ 550 /+ Q_REQUIRED_RESULT 551 #ifdef Q_CLANG_QDOC 552 QString 553 #else 554 typename std::enable_if< 555 sizeof...(Args) >= 2 && std::is_same< 556 QtPrivate::BoolList<is_convertible_to_view_or_qstring<Args>::value..., true>, 557 QtPrivate::BoolList<true, is_convertible_to_view_or_qstring<Args>::value...> 558 >::value, 559 QString 560 >::type 561 #endif 562 arg(Args &&...args) const 563 { return qToStringViewIgnoringNull(*this).arg(std::forward<Args>(args)...); } +/ 564 565 /+ #if QT_DEPRECATED_SINCE(5, 14) +/ 566 /+ QT_DEPRECATED_X("Use vasprintf(), arg() or QTextStream instead") 567 QString &vsprintf(const char *format, va_list ap) Q_ATTRIBUTE_FORMAT_PRINTF(2, 0); +/ 568 /+ QT_DEPRECATED_X("Use asprintf(), arg() or QTextStream instead") +/ 569 ref QString sprintf(const(char)* format, ...) /+ Q_ATTRIBUTE_FORMAT_PRINTF(2, 3) +/; 570 /+ #endif +/ 571 static QString vasprintf(const(char)* format, va_list ap) /+ Q_ATTRIBUTE_FORMAT_PRINTF(1, 0) +/; 572 static QString asprintf(const(char)* format, ...) /+ Q_ATTRIBUTE_FORMAT_PRINTF(1, 2) +/; 573 574 int indexOf(QChar c, int from = 0, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 575 int indexOf(QLatin1String s, int from = 0, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 576 static if(QT_STRINGVIEW_LEVEL < 2) 577 { 578 int indexOf(ref const(QString) s, int from = 0, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 579 int indexOf(ref const(QStringRef) s, int from = 0, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 580 } 581 /+ Q_REQUIRED_RESULT +/ int indexOf(QStringView s, int from = 0, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const/+ noexcept+/ 582 { 583 import qt.core.stringalgorithms; 584 return cast(int)(/+ QtPrivate:: +/qt.core.stringalgorithms.findString(QStringView(this), from, s, cs)); 585 } // ### Qt6: qsizetype 586 int lastIndexOf(QChar c, int from = -1, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 587 int lastIndexOf(QLatin1String s, int from = -1, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 588 static if(QT_STRINGVIEW_LEVEL < 2) 589 { 590 int lastIndexOf(ref const(QString) s, int from = -1, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 591 int lastIndexOf(ref const(QStringRef) s, int from = -1, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 592 } 593 594 /+ Q_REQUIRED_RESULT +/ int lastIndexOf(QStringView s, int from = -1, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const/+ noexcept+/ 595 { 596 import qt.core.stringalgorithms; 597 return cast(int)(/+ QtPrivate:: +/qt.core.stringalgorithms.lastIndexOf(QStringView(this), from, s, cs)); 598 } // ### Qt6: qsizetype 599 600 pragma(inline, true) bool contains(QChar c, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const 601 { return indexOf(c, 0, cs) != -1; } 602 static if(QT_STRINGVIEW_LEVEL < 2) 603 { 604 pragma(inline, true) bool contains(ref const(QString) s, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const 605 { return indexOf(s, 0, cs) != -1; } 606 pragma(inline, true) bool contains(ref const(QStringRef) s, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const 607 { return indexOf(s, 0, cs) != -1; } 608 } 609 pragma(inline, true) bool contains(QLatin1String s, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const 610 { return indexOf(s, 0, cs) != -1; } 611 pragma(inline, true) bool contains(QStringView s, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const/+ noexcept+/ 612 { return indexOf(s, 0, cs) != -1; } 613 int count(QChar c, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 614 int count(ref const(QString) s, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 615 int count(ref const(QStringRef) s, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 616 617 /+ #ifndef QT_NO_REGEXP +/ 618 version(QT_NO_REGEXP){}else 619 { 620 int indexOf(ref const(QRegExp) , int from = 0) const; 621 int lastIndexOf(ref const(QRegExp) , int from = -1) const; 622 pragma(inline, true) bool contains(ref const(QRegExp) rx) const { return indexOf(rx) != -1; } 623 int count(ref const(QRegExp) ) const; 624 625 int indexOf(ref QRegExp , int from = 0) const; 626 int lastIndexOf(ref QRegExp , int from = -1) const; 627 pragma(inline, true) bool contains(ref QRegExp rx) const { return indexOf(rx) != -1; } 628 } 629 /+ #endif 630 631 #if QT_CONFIG(regularexpression) +/ 632 int indexOf(ref const(QRegularExpression) re, int from = 0) const; 633 int indexOf(ref const(QRegularExpression) re, int from, QRegularExpressionMatch* rmatch) const; // ### Qt 6: merge overloads 634 int lastIndexOf(ref const(QRegularExpression) re, int from = -1) const; 635 int lastIndexOf(ref const(QRegularExpression) re, int from, QRegularExpressionMatch* rmatch) const; // ### Qt 6: merge overloads 636 bool contains(ref const(QRegularExpression) re) const; 637 bool contains(ref const(QRegularExpression) re, QRegularExpressionMatch* rmatch) const; // ### Qt 6: merge overloads 638 int count(ref const(QRegularExpression) re) const; 639 /+ #endif +/ 640 641 enum SectionFlag { 642 SectionDefault = 0x00, 643 SectionSkipEmpty = 0x01, 644 SectionIncludeLeadingSep = 0x02, 645 SectionIncludeTrailingSep = 0x04, 646 SectionCaseInsensitiveSeps = 0x08 647 } 648 /+ Q_DECLARE_FLAGS(SectionFlags, SectionFlag) +/ 649 alias SectionFlags = QFlags!(SectionFlag); 650 pragma(inline, true) QString section(QChar asep, int astart, int aend = -1, SectionFlags aflags = SectionFlag.SectionDefault) const 651 { auto tmp = QString(asep); return section(tmp, astart, aend, aflags); } 652 QString section(ref const(QString) in_sep, int start, int end = -1, SectionFlags flags = SectionFlag.SectionDefault) const; 653 /+ #ifndef QT_NO_REGEXP +/ 654 version(QT_NO_REGEXP){}else 655 { 656 QString section(ref const(QRegExp) reg, int start, int end = -1, SectionFlags flags = SectionFlag.SectionDefault) const; 657 } 658 /+ #endif 659 #if QT_CONFIG(regularexpression) +/ 660 QString section(ref const(QRegularExpression) re, int start, int end = -1, SectionFlags flags = SectionFlag.SectionDefault) const; 661 /+ #endif +/ 662 /+ Q_REQUIRED_RESULT +/ QString left(int n) const; 663 /+ Q_REQUIRED_RESULT +/ QString right(int n) const; 664 /+ Q_REQUIRED_RESULT +/ QString mid(int position, int n = -1) const; 665 /+ Q_REQUIRED_RESULT +/ QString chopped(int n) const 666 { (mixin(Q_ASSERT(q{n >= 0}))); (mixin(Q_ASSERT(q{n <= QString.size()}))); return left(size() - n); } 667 668 669 /+ Q_REQUIRED_RESULT +/ QStringRef leftRef(int n) const; 670 /+ Q_REQUIRED_RESULT +/ QStringRef rightRef(int n) const; 671 /+ Q_REQUIRED_RESULT +/ QStringRef midRef(int position, int n = -1) const; 672 673 static if(QT_STRINGVIEW_LEVEL < 2) 674 { 675 bool startsWith(ref const(QString) s, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 676 bool startsWith(ref const(QStringRef) s, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 677 } 678 /+ Q_REQUIRED_RESULT +/ bool startsWith(QStringView s, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const/+ noexcept+/ 679 { 680 import qt.core.stringalgorithms; 681 return /+ QtPrivate:: +/qt.core.stringalgorithms.startsWith(QStringView(this), s, cs); 682 } 683 bool startsWith(QLatin1String s, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 684 bool startsWith(QChar c, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 685 686 static if(QT_STRINGVIEW_LEVEL < 2) 687 { 688 bool endsWith(ref const(QString) s, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 689 bool endsWith(ref const(QStringRef) s, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 690 } 691 /+ Q_REQUIRED_RESULT +/ bool endsWith(QStringView s, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const/+ noexcept+/ 692 { 693 import qt.core.stringalgorithms; 694 return /+ QtPrivate:: +/qt.core.stringalgorithms.endsWith(QStringView(this), s, cs); 695 } 696 bool endsWith(QLatin1String s, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 697 bool endsWith(QChar c, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 698 699 bool isUpper() const; 700 bool isLower() const; 701 702 /+ Q_REQUIRED_RESULT +/ QString leftJustified(int width, QChar fill = QChar(QLatin1Char(' ')), bool trunc = false) const; 703 /+ Q_REQUIRED_RESULT +/ QString rightJustified(int width, QChar fill = QChar(QLatin1Char(' ')), bool trunc = false) const; 704 705 /+ #if defined(Q_COMPILER_REF_QUALIFIERS) && !defined(QT_COMPILING_QSTRING_COMPAT_CPP) && !defined(Q_CLANG_QDOC) 706 # if defined(Q_CC_GNU) && !defined(Q_CC_CLANG) && !defined(Q_CC_INTEL) && !__has_cpp_attribute(nodiscard) 707 // required due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61941 708 # pragma push_macro("Q_REQUIRED_RESULT") 709 # undef Q_REQUIRED_RESULT 710 # define Q_REQUIRED_RESULT 711 # define Q_REQUIRED_RESULT_pushed 712 # endif 713 Q_REQUIRED_RESULT +/ 714 static if((!versionIsSet!("QT_COMPILING_QSTRING_COMPAT_CPP") && defined!"Q_COMPILER_REF_QUALIFIERS")) 715 { 716 QString toLower() const/+ &+/ 717 { return toLower_helper(this); } 718 /+ Q_REQUIRED_RESULT +/ QString toLower()/+ &&+/ 719 { return toLower_helper(this); } 720 /+ Q_REQUIRED_RESULT +/ QString toUpper() const/+ &+/ 721 { return toUpper_helper(this); } 722 /+ Q_REQUIRED_RESULT +/ QString toUpper()/+ &&+/ 723 { return toUpper_helper(this); } 724 /+ Q_REQUIRED_RESULT +/ QString toCaseFolded() const/+ &+/ 725 { return toCaseFolded_helper(this); } 726 /+ Q_REQUIRED_RESULT +/ QString toCaseFolded()/+ &&+/ 727 { return toCaseFolded_helper(this); } 728 /+ Q_REQUIRED_RESULT +/ QString trimmed() const/+ &+/ 729 { return trimmed_helper(this); } 730 /+ Q_REQUIRED_RESULT +/ QString trimmed()/+ &&+/ 731 { return trimmed_helper(this); } 732 /+ Q_REQUIRED_RESULT +/ QString simplified() const/+ &+/ 733 { return simplified_helper(this); } 734 /+ Q_REQUIRED_RESULT +/ QString simplified()/+ &&+/ 735 { return simplified_helper(this); } 736 } 737 else 738 { 739 /+ # ifdef Q_REQUIRED_RESULT_pushed 740 # pragma pop_macro("Q_REQUIRED_RESULT") 741 # endif 742 #else +/ 743 /+ Q_REQUIRED_RESULT +/ QString toLower() const; 744 /+ Q_REQUIRED_RESULT +/ QString toUpper() const; 745 /+ Q_REQUIRED_RESULT +/ QString toCaseFolded() const; 746 /+ Q_REQUIRED_RESULT +/ QString trimmed() const; 747 /+ Q_REQUIRED_RESULT +/ QString simplified() const; 748 } 749 /+ #endif +/ 750 /+ Q_REQUIRED_RESULT +/ QString toHtmlEscaped() const; 751 752 ref QString insert(int i, QChar c); 753 ref QString insert(int i, const(QChar)* uc, int len); 754 pragma(inline, true) ref QString insert(int i, ref const(QString) s) { return insert(i, s.constData(), s.length()); } 755 pragma(inline, true) ref QString insert(int i, ref const(QStringRef) s) 756 { return insert(i, s.constData(), s.length()); } 757 pragma(inline, true) ref QString insert(int i, QStringView s) 758 { return insert(i, s.data(), s.length()); } 759 ref QString insert(int i, QLatin1String s); 760 ref QString append(QChar c); 761 ref QString append(const(QChar)* uc, int len); 762 ref QString append(ref const(QString) s); 763 ref QString append(ref const(QStringRef) s); 764 ref QString append(QLatin1String s); 765 pragma(inline, true) ref QString append(QStringView s) { return append(s.data(), s.length()); } 766 pragma(inline, true) ref QString prepend(QChar c) { return insert(0, c); } 767 pragma(inline, true) ref QString prepend(const(QChar)* uc, int len) { return insert(0, uc, len); } 768 pragma(inline, true) ref QString prepend(ref const(QString) s) { return insert(0, s); } 769 pragma(inline, true) ref QString prepend(ref const(QStringRef) s) { return insert(0, s); } 770 pragma(inline, true) ref QString prepend(QLatin1String s) { return insert(0, s); } 771 pragma(inline, true) ref QString prepend(QStringView s) { return insert(0, s); } 772 773 extern(D) pragma(inline, true) ref QString opOpAssign(string op)(QChar c) if(op == "~") { 774 if (d.ref_.isShared() || uint(d.size) + 2u > d.alloc) 775 reallocData(uint(d.size) + 2u, true); 776 d.data()[d.size++] = c.unicode(); 777 d.data()[d.size] = '\0'; 778 return this; 779 } 780 781 extern(D) pragma(inline, true) ref QString opOpAssign(string op)(QChar.SpecialCharacter c) if(op == "~") { return append(QChar(c)); } 782 extern(D) pragma(inline, true) ref QString opOpAssign(string op)(ref const(QString) s) if(op == "~") { return append(s); } 783 extern(D) pragma(inline, true) ref QString opOpAssign(string op)(const QString s) if(op == "~") { return append(s); } 784 extern(D) pragma(inline, true) ref QString opOpAssign(string op)(ref const(QStringRef) s) if(op == "~") { return append(s); } 785 extern(D) pragma(inline, true) ref QString opOpAssign(string op)(QLatin1String s) if(op == "~") { return append(s); } 786 extern(D) pragma(inline, true) ref QString opOpAssign(string op)(QStringView s) if(op == "~") { return append(s); } 787 788 ref QString remove(int i, int len); 789 ref QString remove(QChar c, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive); 790 ref QString remove(QLatin1String s, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive); 791 ref QString remove(ref const(QString) s, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive); 792 ref QString replace(int i, int len, QChar after); 793 ref QString replace(int i, int len, const(QChar)* s, int slen); 794 ref QString replace(int i, int len, ref const(QString) after); 795 ref QString replace(QChar before, QChar after, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive); 796 ref QString replace(const(QChar)* before, int blen, const(QChar)* after, int alen, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive); 797 ref QString replace(QLatin1String before, QLatin1String after, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive); 798 ref QString replace(QLatin1String before, ref const(QString) after, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive); 799 ref QString replace(ref const(QString) before, QLatin1String after, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive); 800 ref QString replace(ref const(QString) before, ref const(QString) after, 801 /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive); 802 ref QString replace(QChar c, ref const(QString) after, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive); 803 ref QString replace(QChar c, QLatin1String after, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive); 804 /+ #ifndef QT_NO_REGEXP +/ 805 version(QT_NO_REGEXP){}else 806 { 807 ref QString replace(ref const(QRegExp) rx, ref const(QString) after); 808 /+pragma(inline, true) ref QString remove(ref const(QRegExp) rx) 809 { auto tmp = QString(); return replace(rx, tmp); }+/ 810 } 811 /+ #endif 812 #if QT_CONFIG(regularexpression) +/ 813 ref QString replace(ref const(QRegularExpression) re, ref const(QString) after); 814 pragma(inline, true) ref QString remove(ref const(QRegularExpression) re) 815 { auto tmp = QString.create(); return replace(re, tmp); } 816 /+ #endif 817 818 #if QT_DEPRECATED_SINCE(5, 15) +/ 819 enum SplitBehavior // ### Qt 6: replace with Qt:: version 820 { 821 KeepEmptyParts /+ Q_DECL_ENUMERATOR_DEPRECATED +/, 822 SkipEmptyParts /+ Q_DECL_ENUMERATOR_DEPRECATED +/ 823 } 824 825 /+ Q_REQUIRED_RESULT +/ /+ QT_DEPRECATED_VERSION_X_5_15("Use Qt::SplitBehavior variant instead") +/ 826 QStringList split(ref const(QString) sep, SplitBehavior behavior, 827 /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 828 /+ Q_REQUIRED_RESULT +/ /+ QT_DEPRECATED_VERSION_X_5_15("Use Qt::SplitBehavior variant instead") +/ 829 QVector!(QStringRef) splitRef(ref const(QString) sep, SplitBehavior behavior, 830 /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 831 /+ Q_REQUIRED_RESULT +/ /+ QT_DEPRECATED_VERSION_X_5_15("Use Qt::SplitBehavior variant instead") +/ 832 QStringList split(QChar sep, SplitBehavior behavior, 833 /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 834 /+ Q_REQUIRED_RESULT +/ /+ QT_DEPRECATED_VERSION_X_5_15("Use Qt::SplitBehavior variant instead") +/ 835 QVector!(QStringRef) splitRef(QChar sep, SplitBehavior behavior, 836 /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 837 /+ #ifndef QT_NO_REGEXP +/ 838 version(QT_NO_REGEXP){}else 839 { 840 /+ Q_REQUIRED_RESULT +/ /+ QT_DEPRECATED_VERSION_X_5_15("Use Qt::SplitBehavior variant instead") +/ 841 QStringList split(ref const(QRegExp) sep, SplitBehavior behavior) const; 842 /+ Q_REQUIRED_RESULT +/ /+ QT_DEPRECATED_VERSION_X_5_15("Use Qt::SplitBehavior variant instead") +/ 843 QVector!(QStringRef) splitRef(ref const(QRegExp) sep, SplitBehavior behavior) const; 844 } 845 /+ #endif 846 #if QT_CONFIG(regularexpression) +/ 847 /+ Q_REQUIRED_RESULT +/ /+ QT_DEPRECATED_VERSION_X_5_15("Use Qt::SplitBehavior variant instead") +/ 848 QStringList split(ref const(QRegularExpression) sep, SplitBehavior behavior) const; 849 /+ Q_REQUIRED_RESULT +/ /+ QT_DEPRECATED_VERSION_X_5_15("Use Qt::SplitBehavior variant instead") +/ 850 QVector!(QStringRef) splitRef(ref const(QRegularExpression) sep, SplitBehavior behavior) const; 851 /+ #endif 852 #endif +/ // 5.15 deprecations 853 854 public: 855 /+ Q_REQUIRED_RESULT +/ 856 QStringList split(ref const(QString) sep, /+ Qt:: +/qt.core.namespace.SplitBehavior behavior = /+ Qt:: +/qt.core.namespace.SplitBehaviorFlags.KeepEmptyParts, 857 /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 858 /+ Q_REQUIRED_RESULT +/ 859 QVector!(QStringRef) splitRef(ref const(QString) sep, 860 /+ Qt:: +/qt.core.namespace.SplitBehavior behavior = /+ Qt:: +/qt.core.namespace.SplitBehaviorFlags.KeepEmptyParts, 861 /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 862 /+ Q_REQUIRED_RESULT +/ 863 QStringList split(QChar sep, /+ Qt:: +/qt.core.namespace.SplitBehavior behavior = /+ Qt:: +/qt.core.namespace.SplitBehaviorFlags.KeepEmptyParts, 864 /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 865 /+ Q_REQUIRED_RESULT +/ 866 QVector!(QStringRef) splitRef(QChar sep, /+ Qt:: +/qt.core.namespace.SplitBehavior behavior = /+ Qt:: +/qt.core.namespace.SplitBehaviorFlags.KeepEmptyParts, 867 /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 868 /+ #ifndef QT_NO_REGEXP +/ 869 version(QT_NO_REGEXP){}else 870 { 871 /+ Q_REQUIRED_RESULT +/ 872 QStringList split(ref const(QRegExp) sep, 873 /+ Qt:: +/qt.core.namespace.SplitBehavior behavior = /+ Qt:: +/qt.core.namespace.SplitBehaviorFlags.KeepEmptyParts) const; 874 /+ Q_REQUIRED_RESULT +/ 875 QVector!(QStringRef) splitRef(ref const(QRegExp) sep, 876 /+ Qt:: +/qt.core.namespace.SplitBehavior behavior = /+ Qt:: +/qt.core.namespace.SplitBehaviorFlags.KeepEmptyParts) const; 877 } 878 /+ #endif 879 #ifndef QT_NO_REGULAREXPRESSION +/ 880 version(QT_NO_REGULAREXPRESSION){}else 881 { 882 /+ Q_REQUIRED_RESULT +/ 883 QStringList split(ref const(QRegularExpression) sep, 884 /+ Qt:: +/qt.core.namespace.SplitBehavior behavior = /+ Qt:: +/qt.core.namespace.SplitBehaviorFlags.KeepEmptyParts) const; 885 /+ Q_REQUIRED_RESULT +/ 886 QVector!(QStringRef) splitRef(ref const(QRegularExpression) sep, 887 /+ Qt:: +/qt.core.namespace.SplitBehavior behavior = /+ Qt:: +/qt.core.namespace.SplitBehaviorFlags.KeepEmptyParts) const; 888 } 889 /+ #endif +/ 890 891 892 enum NormalizationForm { 893 NormalizationForm_D, 894 NormalizationForm_C, 895 NormalizationForm_KD, 896 NormalizationForm_KC 897 } 898 /+ Q_REQUIRED_RESULT +/ QString normalized(NormalizationForm mode, QChar.UnicodeVersion version_ = QChar.UnicodeVersion.Unicode_Unassigned) const; 899 900 /+ Q_REQUIRED_RESULT +/ QString repeated(int times) const; 901 902 const(ushort)* utf16() const; 903 904 905 static if((!versionIsSet!("QT_COMPILING_QSTRING_COMPAT_CPP") && defined!"Q_COMPILER_REF_QUALIFIERS")) 906 { 907 /+ Q_REQUIRED_RESULT +/ QByteArray toLatin1() const/+ &+/ 908 { return toLatin1_helper(this); } 909 /+ Q_REQUIRED_RESULT +/ QByteArray toLatin1()/+ &&+/ 910 { return toLatin1_helper_inplace(this); } 911 /+ Q_REQUIRED_RESULT +/ QByteArray toUtf8() const/+ &+/ 912 { return toUtf8_helper(this); } 913 /+ Q_REQUIRED_RESULT +/ QByteArray toUtf8()/+ &&+/ 914 { return toUtf8_helper(this); } 915 /+ Q_REQUIRED_RESULT +/ QByteArray toLocal8Bit() const/+ &+/ 916 { return toLocal8Bit_helper(isNull() ? null : constData(), size()); } 917 /+ Q_REQUIRED_RESULT +/ QByteArray toLocal8Bit()/+ &&+/ 918 { return toLocal8Bit_helper(isNull() ? null : constData(), size()); } 919 } 920 else 921 { 922 /+ Q_REQUIRED_RESULT +/ QByteArray toLatin1() const; 923 /+ Q_REQUIRED_RESULT +/ QByteArray toUtf8() const; 924 /+ Q_REQUIRED_RESULT +/ QByteArray toLocal8Bit() const; 925 } 926 /+ Q_REQUIRED_RESULT +/ QVector!(uint) toUcs4() const; 927 928 // note - this are all inline so we can benefit from strlen() compile time optimizations 929 pragma(inline, true) static QString fromLatin1(const(char)* str, int size = -1) 930 { 931 import core.stdc.string; 932 933 QStringDataPtr dataPtr = QStringDataPtr( fromLatin1_helper(str, (str && size == -1) ? cast(int)(strlen(str)) : size)) ; 934 return QString(dataPtr); 935 } 936 pragma(inline, true) static QString fromUtf8(const(char)* str, int size = -1) 937 { 938 import core.stdc.string; 939 940 return fromUtf8_helper(str, (str && size == -1) ? cast(int)(strlen(str)) : size); 941 } 942 pragma(inline, true) static QString fromLocal8Bit(const(char)* str, int size = -1) 943 { 944 import core.stdc.string; 945 946 return fromLocal8Bit_helper(str, (str && size == -1) ? cast(int)(strlen(str)) : size); 947 } 948 pragma(inline, true) static QString fromLatin1(ref const(QByteArray) str) 949 { return str.isNull() ? QString.create() : fromLatin1(str.data(), qstrnlen(str.constData(), str.size())); } 950 pragma(inline, true) static QString fromUtf8(ref const(QByteArray) str) 951 { return str.isNull() ? QString.create() : fromUtf8(str.data(), qstrnlen(str.constData(), str.size())); } 952 pragma(inline, true) static QString fromLocal8Bit(ref const(QByteArray) str) 953 { return str.isNull() ? QString.create() : fromLocal8Bit(str.data(), qstrnlen(str.constData(), str.size())); } 954 static QString fromUtf16(const(ushort)* , int size = -1); 955 static QString fromUcs4(const(uint)* , int size = -1); 956 static QString fromRawData(const(QChar)* , int size); 957 958 /+ #if defined(Q_COMPILER_UNICODE_STRINGS) +/ 959 static QString fromUtf16(const(wchar)* str, int size = -1) 960 { return fromUtf16(reinterpret_cast!(const(ushort)*)(str), size); } 961 static QString fromUcs4(const(dchar)* str, int size = -1) 962 { return fromUcs4(reinterpret_cast!(const(uint)*)(str), size); } 963 /+ #endif 964 965 #if QT_DEPRECATED_SINCE(5, 0) 966 QT_DEPRECATED static inline QString fromAscii(const char *str, int size = -1) 967 { return fromLatin1(str, size); } 968 QT_DEPRECATED static inline QString fromAscii(const QByteArray &str) 969 { return fromLatin1(str); } 970 Q_REQUIRED_RESULT QByteArray toAscii() const 971 { return toLatin1(); } 972 #endif +/ 973 974 /+ pragma(inline, true) int toWCharArray(wchar_t* array) const 975 { 976 return qToStringViewIgnoringNull(this).toWCharArray(array); 977 }+/ 978 /+ Q_REQUIRED_RESULT +/ pragma(inline, true) static QString fromWCharArray(const(wchar_t)* string, int size = -1) 979 { 980 return wchar_t.sizeof == QChar.sizeof ? fromUtf16(reinterpret_cast!(const(ushort)*)(string), size) 981 : fromUcs4(reinterpret_cast!(const(uint)*)(string), size); 982 } 983 984 ref QString setRawData(const(QChar)* unicode, int size); 985 ref QString setUnicode(const(QChar)* unicode, int size); 986 pragma(inline, true) ref QString setUtf16(const(ushort)* autf16, int asize) 987 { return setUnicode(reinterpret_cast!(const(QChar)*)(autf16), asize); } 988 989 static if(QT_STRINGVIEW_LEVEL < 2) 990 { 991 int compare(ref const(QString) s, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const/+ noexcept+/; 992 pragma(inline, true) int compare(ref const(QStringRef) s, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const/+ noexcept+/ 993 { return QString.compare_helper(constData(), length(), s.constData(), s.length(), cs); } 994 } 995 int compare(QLatin1String other, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const/+ noexcept+/; 996 pragma(inline, true) int compare(QStringView s, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const/+ noexcept+/ 997 { return -s.compare(QStringView(this), cs); } 998 int compare(QChar ch, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const/+ noexcept+/ 999 { return compare(QStringView(&ch, 1), cs); } 1000 1001 pragma(inline, true) static int compare(ref const(QString) s1, ref const(QString) s2, 1002 /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive)/+ noexcept+/ 1003 { return s1.compare(s2, cs); } 1004 1005 pragma(inline, true) static int compare(ref const(QString) s1, QLatin1String s2, 1006 /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive)/+ noexcept+/ 1007 { return s1.compare(s2, cs); } 1008 pragma(inline, true) static int compare(QLatin1String s1, ref const(QString) s2, 1009 /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive)/+ noexcept+/ 1010 { return -s2.compare(s1, cs); } 1011 1012 pragma(inline, true) static int compare(ref const(QString) s1, ref const(QStringRef) s2, 1013 /+ Qt:: +/qt.core.namespace.CaseSensitivity cs /+ = Qt::CaseSensitive +/)/+ noexcept+/ 1014 { return QString.compare_helper(s1.constData(), s1.length(), s2.constData(), s2.length(), cs); } 1015 1016 int localeAwareCompare(ref const(QString) s) const; 1017 static int localeAwareCompare(ref const(QString) s1, ref const(QString) s2) 1018 { return s1.localeAwareCompare(s2); } 1019 1020 pragma(inline, true) int localeAwareCompare(ref const(QStringRef) s) const 1021 { return localeAwareCompare_helper(constData(), length(), s.constData(), s.length()); } 1022 pragma(inline, true) static int localeAwareCompare(ref const(QString) s1, ref const(QStringRef) s2) 1023 { return localeAwareCompare_helper(s1.constData(), s1.length(), s2.constData(), s2.length()); } 1024 1025 // ### Qt6: make inline except for the long long versions 1026 short toShort(bool* ok=null, int base=10) const; 1027 ushort toUShort(bool* ok=null, int base=10) const; 1028 int toInt(bool* ok=null, int base=10) const; 1029 uint toUInt(bool* ok=null, int base=10) const; 1030 cpp_long toLong(bool* ok=null, int base=10) const; 1031 cpp_ulong toULong(bool* ok=null, int base=10) const; 1032 qlonglong toLongLong(bool* ok=null, int base=10) const; 1033 qulonglong toULongLong(bool* ok=null, int base=10) const; 1034 float toFloat(bool* ok=null) const; 1035 double toDouble(bool* ok=null) const; 1036 1037 pragma(inline, true) ref QString setNum(short n, int base=10) 1038 { return setNum(qlonglong(n), base); } 1039 pragma(inline, true) ref QString setNum(ushort n, int base=10) 1040 { return setNum(qulonglong(n), base); } 1041 pragma(inline, true) ref QString setNum(int n, int base=10) 1042 { return setNum(qlonglong(n), base); } 1043 pragma(inline, true) ref QString setNum(uint n, int base=10) 1044 { return setNum(qulonglong(n), base); } 1045 pragma(inline, true) ref QString setNum(cpp_long n, int base=10) 1046 { return setNum(qlonglong(n), base); } 1047 pragma(inline, true) ref QString setNum(cpp_ulong n, int base=10) 1048 { return setNum(qulonglong(n), base); } 1049 ref QString setNum(qlonglong, int base=10); 1050 ref QString setNum(qulonglong, int base=10); 1051 pragma(inline, true) ref QString setNum(float n, char f='g', int prec=6) 1052 { return setNum(double(n),f,prec); } 1053 ref QString setNum(double, char f='g', int prec=6); 1054 1055 static QString number(int, int base=10); 1056 static QString number(uint, int base=10); 1057 static QString number(cpp_long, int base=10); 1058 static QString number(cpp_ulong, int base=10); 1059 static QString number(qlonglong, int base=10); 1060 static QString number(qulonglong, int base=10); 1061 static QString number(double, char f='g', int prec=6); 1062 1063 /+ friend Q_CORE_EXPORT bool operator==(const QString &s1, const QString &s2) noexcept; +/ 1064 /+ friend Q_CORE_EXPORT bool operator<(const QString &s1, const QString &s2) noexcept; +/ 1065 /+ friend inline bool operator>(const QString &s1, const QString &s2) noexcept { return s2 < s1; } +/ 1066 /+ friend inline bool operator!=(const QString &s1, const QString &s2) noexcept { return !(s1 == s2); } +/ 1067 /+ friend inline bool operator<=(const QString &s1, const QString &s2) noexcept { return !(s1 > s2); } +/ 1068 /+ friend inline bool operator>=(const QString &s1, const QString &s2) noexcept { return !(s1 < s2); } +/ 1069 1070 /+bool operator ==(QLatin1String s) const/+ noexcept+/;+/ 1071 /+bool operator <(QLatin1String s) const/+ noexcept+/;+/ 1072 /+bool operator >(QLatin1String s) const/+ noexcept+/;+/ 1073 /+pragma(inline, true) bool operator !=(QLatin1String s) const/+ noexcept+/ { return !operator==(s); }+/ 1074 /+pragma(inline, true) bool operator <=(QLatin1String s) const/+ noexcept+/ { return !operator>(s); }+/ 1075 /+pragma(inline, true) bool operator >=(QLatin1String s) const/+ noexcept+/ { return !operator<(s); }+/ 1076 1077 // ASCII compatibility 1078 /+ #if defined(QT_RESTRICTED_CAST_FROM_ASCII) +/ 1079 version(QT_RESTRICTED_CAST_FROM_ASCII) 1080 { 1081 /+ template <int N> +/ 1082 /+ inline QString(const char (&ch)[N]) 1083 : d(fromAscii_helper(ch, N - 1)) 1084 {} +/ 1085 /+ template <int N> +/ 1086 /+ QString(char (&)[N]) = delete; +/ 1087 /+ template <int N> +/ 1088 /+ inline QString &operator=(const char (&ch)[N]) 1089 { return (*this = fromUtf8(ch, N - 1)); } +/ 1090 /+ template <int N> +/ 1091 /+ QString &operator=(char (&)[N]) = delete; +/ 1092 } 1093 /+ #endif 1094 #if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) 1095 inline QT_ASCII_CAST_WARN QString(const char *ch) 1096 : d(fromAscii_helper(ch, ch ? int(strlen(ch)) : -1)) 1097 {} 1098 inline QT_ASCII_CAST_WARN QString(const QByteArray &a) 1099 : d(fromAscii_helper(a.constData(), qstrnlen(a.constData(), a.size()))) 1100 {} 1101 inline QT_ASCII_CAST_WARN QString &operator=(const char *ch) 1102 { return (*this = fromUtf8(ch)); } 1103 inline QT_ASCII_CAST_WARN QString &operator=(const QByteArray &a) 1104 { return (*this = fromUtf8(a)); } 1105 inline QT_ASCII_CAST_WARN QString &operator=(char c) 1106 { return (*this = QChar::fromLatin1(c)); } 1107 1108 // these are needed, so it compiles with STL support enabled 1109 inline QT_ASCII_CAST_WARN QString &prepend(const char *s) 1110 { return prepend(QString::fromUtf8(s)); } 1111 inline QT_ASCII_CAST_WARN QString &prepend(const QByteArray &s) 1112 { return prepend(QString::fromUtf8(s)); } 1113 inline QT_ASCII_CAST_WARN QString &append(const char *s) 1114 { return append(QString::fromUtf8(s)); } 1115 inline QT_ASCII_CAST_WARN QString &append(const QByteArray &s) 1116 { return append(QString::fromUtf8(s)); } 1117 inline QT_ASCII_CAST_WARN QString &insert(int i, const char *s) 1118 { return insert(i, QString::fromUtf8(s)); } 1119 inline QT_ASCII_CAST_WARN QString &insert(int i, const QByteArray &s) 1120 { return insert(i, QString::fromUtf8(s)); } 1121 inline QT_ASCII_CAST_WARN QString &operator+=(const char *s) 1122 { return append(QString::fromUtf8(s)); } 1123 inline QT_ASCII_CAST_WARN QString &operator+=(const QByteArray &s) 1124 { return append(QString::fromUtf8(s)); } 1125 inline QT_ASCII_CAST_WARN QString &operator+=(char c) 1126 { return append(QChar::fromLatin1(c)); } 1127 1128 inline QT_ASCII_CAST_WARN bool operator==(const char *s) const; 1129 inline QT_ASCII_CAST_WARN bool operator!=(const char *s) const; 1130 inline QT_ASCII_CAST_WARN bool operator<(const char *s) const; 1131 inline QT_ASCII_CAST_WARN bool operator<=(const char *s) const; 1132 inline QT_ASCII_CAST_WARN bool operator>(const char *s) const; 1133 inline QT_ASCII_CAST_WARN bool operator>=(const char *s) const; 1134 1135 inline QT_ASCII_CAST_WARN bool operator==(const QByteArray &s) const; 1136 inline QT_ASCII_CAST_WARN bool operator!=(const QByteArray &s) const; 1137 inline QT_ASCII_CAST_WARN bool operator<(const QByteArray &s) const; 1138 inline QT_ASCII_CAST_WARN bool operator>(const QByteArray &s) const; 1139 inline QT_ASCII_CAST_WARN bool operator<=(const QByteArray &s) const; 1140 inline QT_ASCII_CAST_WARN bool operator>=(const QByteArray &s) const; 1141 1142 friend inline QT_ASCII_CAST_WARN bool operator==(const char *s1, const QString &s2); 1143 friend inline QT_ASCII_CAST_WARN bool operator!=(const char *s1, const QString &s2); 1144 friend inline QT_ASCII_CAST_WARN bool operator<(const char *s1, const QString &s2); 1145 friend inline QT_ASCII_CAST_WARN bool operator>(const char *s1, const QString &s2); 1146 friend inline QT_ASCII_CAST_WARN bool operator<=(const char *s1, const QString &s2); 1147 friend inline QT_ASCII_CAST_WARN bool operator>=(const char *s1, const QString &s2); 1148 1149 friend inline QT_ASCII_CAST_WARN bool operator==(const char *s1, const QStringRef &s2); 1150 friend inline QT_ASCII_CAST_WARN bool operator!=(const char *s1, const QStringRef &s2); 1151 friend inline QT_ASCII_CAST_WARN bool operator<(const char *s1, const QStringRef &s2); 1152 friend inline QT_ASCII_CAST_WARN bool operator>(const char *s1, const QStringRef &s2); 1153 friend inline QT_ASCII_CAST_WARN bool operator<=(const char *s1, const QStringRef &s2); 1154 friend inline QT_ASCII_CAST_WARN bool operator>=(const char *s1, const QStringRef &s2); 1155 #endif +/ 1156 1157 /*extern(D) bool opEquals(const char *s) const 1158 { 1159 auto r = compare_helper(constData(), size(), s, -1); 1160 return r == 0; 1161 }*/ 1162 extern(D) bool opEquals(const(char)[] s) const 1163 { 1164 auto r = compare_helper(constData(), size(), s.ptr, cast(int)s.length); 1165 return r == 0; 1166 } 1167 extern(D) bool opEquals(const(wchar)[] s) const 1168 { 1169 return (cast(wchar*)constData())[0..size()] == s; 1170 } 1171 extern(D) bool opEquals(const ref QString s) const 1172 { 1173 return compare_helper(constData(), size(), s.constData, s.size()) == 0; 1174 } 1175 1176 alias iterator = QChar*; 1177 alias const_iterator = const(QChar)*; 1178 alias Iterator = iterator; 1179 alias ConstIterator = const_iterator; 1180 /+ typedef std::reverse_iterator<iterator> reverse_iterator; +/ 1181 /+ typedef std::reverse_iterator<const_iterator> const_reverse_iterator; +/ 1182 pragma(inline, true) iterator begin() 1183 /+pragma(inline, true) QString.iterator begin()+/ 1184 { detach(); return reinterpret_cast!(QChar*)(d.data()); } 1185 pragma(inline, true) const_iterator begin() const 1186 /+pragma(inline, true) QString.const_iterator begin() const+/ 1187 { return reinterpret_cast!(const(QChar)*)(d.data()); } 1188 pragma(inline, true) const_iterator cbegin() const 1189 /+pragma(inline, true) QString.const_iterator cbegin() const+/ 1190 { return reinterpret_cast!(const(QChar)*)(d.data()); } 1191 pragma(inline, true) const_iterator constBegin() const 1192 /+pragma(inline, true) QString.const_iterator constBegin() const+/ 1193 { return reinterpret_cast!(const(QChar)*)(d.data()); } 1194 pragma(inline, true) iterator end() 1195 /+pragma(inline, true) QString.iterator end()+/ 1196 { detach(); return reinterpret_cast!(QChar*)(d.data() + d.size); } 1197 pragma(inline, true) const_iterator end() const 1198 /+pragma(inline, true) QString.const_iterator end() const+/ 1199 { return reinterpret_cast!(const(QChar)*)(d.data() + d.size); } 1200 pragma(inline, true) const_iterator cend() const 1201 /+pragma(inline, true) QString.const_iterator cend() const+/ 1202 { return reinterpret_cast!(const(QChar)*)(d.data() + d.size); } 1203 pragma(inline, true) const_iterator constEnd() const 1204 /+pragma(inline, true) QString.const_iterator constEnd() const+/ 1205 { return reinterpret_cast!(const(QChar)*)(d.data() + d.size); } 1206 /+ reverse_iterator rbegin() { return reverse_iterator(end()); } +/ 1207 /+ reverse_iterator rend() { return reverse_iterator(begin()); } +/ 1208 /+ const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); } +/ 1209 /+ const_reverse_iterator rend() const { return const_reverse_iterator(begin()); } +/ 1210 /+ const_reverse_iterator crbegin() const { return const_reverse_iterator(end()); } +/ 1211 /+ const_reverse_iterator crend() const { return const_reverse_iterator(begin()); } +/ 1212 1213 // STL compatibility 1214 alias size_type = int; 1215 alias difference_type = qptrdiff; 1216 /+ typedef const QChar & const_reference; +/ 1217 /+ typedef QChar & reference; +/ 1218 alias pointer = QChar*; 1219 alias const_pointer = const(QChar)*; 1220 alias value_type = QChar; 1221 pragma(inline, true) void push_back(QChar c) { append(c); } 1222 pragma(inline, true) void push_back(ref const(QString) s) { append(s); } 1223 pragma(inline, true) void push_front(QChar c) { prepend(c); } 1224 pragma(inline, true) void push_front(ref const(QString) s) { prepend(s); } 1225 void shrink_to_fit() { squeeze(); } 1226 1227 /+ static inline QString fromStdString(const std::string &s); +/ 1228 /+ inline std::string toStdString() const; +/ 1229 /+ static inline QString fromStdWString(const std::wstring &s); +/ 1230 /+ inline std::wstring toStdWString() const; +/ 1231 1232 /+ #if defined(Q_STDLIB_UNICODE_STRINGS) || defined(Q_QDOC) 1233 static inline QString fromStdU16String(const std::u16string &s); 1234 inline std::u16string toStdU16String() const; 1235 static inline QString fromStdU32String(const std::u32string &s); 1236 inline std::u32string toStdU32String() const; 1237 #endif 1238 1239 #if defined(Q_OS_DARWIN) || defined(Q_QDOC) +/ 1240 static if((versionIsSet!("OSX") || versionIsSet!("iOS") || versionIsSet!("TVOS") || versionIsSet!("WatchOS"))) 1241 { 1242 /+ static QString fromCFString(CFStringRef string); +/ 1243 /+ CFStringRef toCFString() const Q_DECL_CF_RETURNS_RETAINED; +/ 1244 /+ static QString fromNSString(const NSString *string); +/ 1245 /+ NSString *toNSString() const Q_DECL_NS_RETURNS_AUTORELEASED; +/ 1246 } 1247 /+ #endif 1248 // compatibility 1249 #if QT_DEPRECATED_SINCE(5, 9) +/ 1250 struct Null { } 1251 /+ QT_DEPRECATED_X("use QString()") +/ 1252 /+ extern static __gshared const(Null) null_; +/ 1253 pragma(inline, true) this(ref const(Null) ) 1254 { 1255 this.d = Data.sharedNull(); 1256 } 1257 /+pragma(inline, true) ref QString operator =(ref const(Null) ) { this = QString(); return this; }+/ 1258 /+ #endif +/ 1259 pragma(inline, true) bool isNull() const { return d == Data.sharedNull(); } 1260 1261 1262 bool isSimpleText() const; 1263 bool isRightToLeft() const; 1264 /+ Q_REQUIRED_RESULT +/ bool isValidUtf16() const/+ noexcept+/ 1265 { return QStringView(this).isValidUtf16(); } 1266 1267 this(int size, /+ Qt:: +/qt.core.namespace.Initialization); 1268 pragma(inline, true) this(QStringDataPtr dd) 1269 { 1270 this.d = dd.ptr; 1271 } 1272 1273 extern(D) QString opBinary(string op)(const ref QString s2) const if(op == "~") 1274 { 1275 QString t = *cast(QString*)&this; t ~= s2; return t; 1276 } 1277 extern(D) QString opBinary(string op)(const QString s2) const if(op == "~") 1278 { 1279 QString t = *cast(QString*)&this; t ~= s2; return t; 1280 } 1281 extern(D) QString opBinary(string op)(const char *s2) const if(op == "~") 1282 { 1283 QString t = *cast(QString*)&this; auto tmp = QString.fromUtf8(s2); t ~= tmp; return t; 1284 } 1285 extern(D) QString opBinaryRight(string op)(const char *s1) const if(op == "~") 1286 { 1287 QString t = QString.fromUtf8(s1); t ~= this; return t; 1288 } 1289 1290 pragma(inline, true) bool opEquals(QStringView rhs)/+ noexcept+/ { 1291 import qt.core.stringalgorithms; 1292 return this.size() == rhs.size() && /+ QtPrivate:: +/qt.core.stringalgorithms.compareStrings(QStringView(this), rhs) == 0; 1293 } 1294 1295 pragma(inline, true) bool opEquals(QLatin1String rhs)/+ noexcept+/ { 1296 import qt.core.stringalgorithms; 1297 return this.size() == rhs.size() && /+ QtPrivate:: +/qt.core.stringalgorithms.compareStrings(QStringView(this), rhs) == 0; 1298 } 1299 1300 1301 private: 1302 /+ #if defined(QT_NO_CAST_FROM_ASCII) +/ 1303 extern(D) ref QString opOpAssign(string op)(const(char)* s) if(op == "~"); 1304 extern(D) ref QString opOpAssign(string op)(ref const(QByteArray) s) if(op == "~"); 1305 //this(const(char)* ch); 1306 //this(ref const(QByteArray) a); 1307 /+ref QString operator =(const(char)* ch);+/ 1308 /+ref QString operator =(ref const(QByteArray) a);+/ 1309 /+ #endif +/ 1310 1311 version(Windows) 1312 Data* d; 1313 else 1314 { 1315 union 1316 { 1317 const(QArrayData)* d2 = QArrayData.shared_null.ptr; 1318 Data* d; 1319 } 1320 } 1321 1322 /+ friend inline bool operator==(QChar, const QString &) noexcept; +/ 1323 /+ friend inline bool operator< (QChar, const QString &) noexcept; +/ 1324 /+ friend inline bool operator> (QChar, const QString &) noexcept; +/ 1325 /+ friend inline bool operator==(QChar, const QStringRef &) noexcept; +/ 1326 /+ friend inline bool operator< (QChar, const QStringRef &) noexcept; +/ 1327 /+ friend inline bool operator> (QChar, const QStringRef &) noexcept; +/ 1328 /+ friend inline bool operator==(QChar, QLatin1String) noexcept; +/ 1329 /+ friend inline bool operator< (QChar, QLatin1String) noexcept; +/ 1330 /+ friend inline bool operator> (QChar, QLatin1String) noexcept; +/ 1331 1332 void reallocData(uint alloc, bool grow = false); 1333 /+ #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +/ 1334 void expand(int i); 1335 QString multiArg(int numArgs, const(QString)** args) const; 1336 /+ #endif +/ 1337 static int compare_helper(const(QChar)* data1, int length1, 1338 const(QChar)* data2, int length2, 1339 /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive)/+ noexcept+/; 1340 static int compare_helper(const(QChar)* data1, int length1, 1341 const(char)* data2, int length2, 1342 /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive); 1343 static int compare_helper(const(QChar)* data1, int length1, 1344 QLatin1String s2, 1345 /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive)/+ noexcept+/; 1346 static int localeAwareCompare_helper(const(QChar)* data1, int length1, 1347 const(QChar)* data2, int length2); 1348 static QString toLower_helper(ref const(QString) str); 1349 static QString toLower_helper(ref QString str); 1350 static QString toUpper_helper(ref const(QString) str); 1351 static QString toUpper_helper(ref QString str); 1352 static QString toCaseFolded_helper(ref const(QString) str); 1353 static QString toCaseFolded_helper(ref QString str); 1354 static QString trimmed_helper(ref const(QString) str); 1355 static QString trimmed_helper(ref QString str); 1356 static QString simplified_helper(ref const(QString) str); 1357 static QString simplified_helper(ref QString str); 1358 static Data* fromLatin1_helper(const(char)* str, int size = -1); 1359 static Data* fromAscii_helper(const(char)* str, int size = -1); 1360 static QString fromUtf8_helper(const(char)* str, int size); 1361 static QString fromLocal8Bit_helper(const(char)* , int size); 1362 static QByteArray toLatin1_helper(ref const(QString) ); 1363 static QByteArray toLatin1_helper_inplace(ref QString ); 1364 static QByteArray toUtf8_helper(ref const(QString) ); 1365 static QByteArray toLocal8Bit_helper(const(QChar)* data, int size); 1366 static int toUcs4_helper(const(ushort)* uc, int length, uint* out_); 1367 static qlonglong toIntegral_helper(const(QChar)* data, int len, bool* ok, int base); 1368 static qulonglong toIntegral_helper(const(QChar)* data, uint len, bool* ok, int base); 1369 void replace_helper(uint* indices, int nIndices, int blen, const(QChar)* after, int alen); 1370 /+ friend class QCharRef; +/ 1371 /+ friend class QTextCodec; +/ 1372 /+ friend class QStringRef; +/ 1373 /+ friend class QStringView; +/ 1374 /+ friend class QByteArray; +/ 1375 /+ friend class QCollator; +/ 1376 /+ friend struct QAbstractConcatenable; +/ 1377 1378 /+ template <typename T> +/ /+ static 1379 T toIntegral_helper(const QChar *data, int len, bool *ok, int base) 1380 { 1381 using Int64 = typename std::conditional<std::is_unsigned<T>::value, qulonglong, qlonglong>::type; 1382 using Int32 = typename std::conditional<std::is_unsigned<T>::value, uint, int>::type; 1383 1384 // we select the right overload by casting size() to int or uint 1385 Int64 val = toIntegral_helper(data, Int32(len), ok, base); 1386 if (T(val) != val) { 1387 if (ok) 1388 *ok = false; 1389 val = 0; 1390 } 1391 return T(val); 1392 } +/ 1393 1394 public: 1395 alias DataPtr = Data*; 1396 pragma(inline, true) ref DataPtr data_ptr() return { return d; } 1397 } 1398 /+ #if QT_STRINGVIEW_LEVEL < 2 1399 #endif 1400 1401 QT_WARNING_PUSH 1402 QT_WARNING_DISABLE_MSVC(4127) // "conditional expression is constant" 1403 QT_WARNING_DISABLE_INTEL(111) // "statement is unreachable" 1404 1405 QT_WARNING_POP +/ 1406 1407 @Q_MOVABLE_TYPE extern(C++, class) struct 1408 /+ #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 1409 Q_CORE_EXPORT 1410 #endif +/ 1411 QCharRef { // ### Qt 7: remove 1412 private: 1413 QString *s; 1414 int i; 1415 pragma(inline, true) this(ref QString str, int idx) 1416 { 1417 this.s = &str; 1418 this.i = idx; 1419 } 1420 /+ friend class QString; +/ 1421 public: 1422 /+ QCharRef(const QCharRef &) = default; +/ 1423 1424 // most QChar operations repeated here 1425 1426 // all this is not documented: We just say "like QChar" and let it be. 1427 //pragma(inline, true) auto opCast(T : QChar)() const 1428 pragma(inline, true) QChar toQChar() const 1429 { 1430 //using namespace /+ QtPrivate:: +/DeprecatedRefClassBehavior; 1431 if (/+ Q_LIKELY +/(i < s.d.size)) 1432 return QChar(s.d.data()[i]); 1433 version(QT_DEBUG) 1434 { 1435 // warn(WarningType.OutOfRange, EmittingClass.QCharRef); 1436 } 1437 return QChar(); 1438 } 1439 /+pragma(inline, true) ref QCharRef operator =(QChar c) 1440 { 1441 using namespace /+ QtPrivate:: +/DeprecatedRefClassBehavior; 1442 if (/+ Q_UNLIKELY +/(i >= s.d.size)) { 1443 version(QT_DEBUG) 1444 { 1445 warn(WarningType.OutOfRange, EmittingClass.QCharRef); 1446 } 1447 s.resize(i + 1, QLatin1Char(' ')); 1448 } else { 1449 version(QT_DEBUG) 1450 { 1451 if (/+ Q_UNLIKELY +/(!s.isDetached())) 1452 warn(WarningType.DelayedDetach, EmittingClass.QCharRef); 1453 } 1454 s.detach(); 1455 } 1456 s.d.data()[i] = c.unicode(); 1457 return this; 1458 }+/ 1459 1460 // An operator= for each QChar cast constructors 1461 /+ #ifndef QT_NO_CAST_FROM_ASCII 1462 inline QT_ASCII_CAST_WARN QCharRef &operator=(char c) 1463 { return operator=(QChar::fromLatin1(c)); } 1464 inline QT_ASCII_CAST_WARN QCharRef &operator=(uchar c) 1465 { return operator=(QChar::fromLatin1(c)); } 1466 #endif +/ 1467 /+pragma(inline, true) ref QCharRef operator =(ref const(QCharRef) c) { return operator=(QChar(c)); }+/ 1468 /+pragma(inline, true) ref QCharRef operator =(ushort rc) { return operator=(QChar(rc)); }+/ 1469 /+pragma(inline, true) ref QCharRef operator =(short rc) { return operator=(QChar(rc)); }+/ 1470 /+pragma(inline, true) ref QCharRef operator =(uint rc) { return operator=(QChar(rc)); }+/ 1471 /+pragma(inline, true) ref QCharRef operator =(int rc) { return operator=(QChar(rc)); }+/ 1472 1473 // each function... 1474 /+pragma(inline, true) bool isNull() const { return this.toQChar.isNull(); } 1475 pragma(inline, true) bool isPrint() const { return this.toQChar.isPrint(); } 1476 pragma(inline, true) bool isPunct() const { return this.toQChar.isPunct(); } 1477 pragma(inline, true) bool isSpace() const { return this.toQChar.isSpace(); } 1478 pragma(inline, true) bool isMark() const { return this.toQChar.isMark(); } 1479 pragma(inline, true) bool isLetter() const { return this.toQChar.isLetter(); } 1480 pragma(inline, true) bool isNumber() const { return this.toQChar.isNumber(); } 1481 pragma(inline, true) bool isLetterOrNumber() { return this.toQChar.isLetterOrNumber(); } 1482 pragma(inline, true) bool isDigit() const { return this.toQChar.isDigit(); } 1483 pragma(inline, true) bool isLower() const { return this.toQChar.isLower(); } 1484 pragma(inline, true) bool isUpper() const { return this.toQChar.isUpper(); } 1485 pragma(inline, true) bool isTitleCase() const { return this.toQChar.isTitleCase(); } 1486 1487 pragma(inline, true) int digitValue() const { return this.toQChar.digitValue(); } 1488 QChar toLower() const { return this.toQChar.toLower(); } 1489 QChar toUpper() const { return this.toQChar.toUpper(); } 1490 QChar toTitleCase () const { return this.toQChar.toTitleCase(); } 1491 1492 QChar.Category category() const { return this.toQChar.category(); } 1493 QChar.Direction direction() const { return this.toQChar.direction(); } 1494 QChar.JoiningType joiningType() const { return this.toQChar.joiningType(); } 1495 /+ #if QT_DEPRECATED_SINCE(5, 3) +/ 1496 /+ QT_DEPRECATED +/ QChar.Joining joining() const 1497 { 1498 switch (this.toQChar.joiningType()) { 1499 case QChar.JoiningType.Joining_Causing: return QChar.Joining.Center; 1500 case QChar.JoiningType.Joining_Dual: return QChar.Joining.Dual; 1501 case QChar.JoiningType.Joining_Right: return QChar.Joining.Right; 1502 case QChar.JoiningType.Joining_None: 1503 case QChar.JoiningType.Joining_Left: 1504 case QChar.JoiningType.Joining_Transparent: 1505 default: return QChar.Joining.OtherJoining; 1506 } 1507 } 1508 /+ #endif +/ 1509 bool hasMirrored() const { return this.toQChar.hasMirrored(); } 1510 QChar mirroredChar() const { return this.toQChar.mirroredChar(); } 1511 QString decomposition() const { return this.toQChar.decomposition(); } 1512 QChar.Decomposition decompositionTag() const { return this.toQChar.decompositionTag(); } 1513 uchar combiningClass() const { return this.toQChar.combiningClass(); } 1514 1515 pragma(inline, true) QChar.Script script() const { return this.toQChar.script(); } 1516 1517 QChar.UnicodeVersion unicodeVersion() const { return this.toQChar.unicodeVersion(); } 1518 1519 pragma(inline, true) uchar cell() const { return this.toQChar.cell(); } 1520 pragma(inline, true) uchar row() const { return this.toQChar.row(); } 1521 pragma(inline, true) void setCell(uchar acell) { this.toQChar.setCell(acell); } 1522 pragma(inline, true) void setRow(uchar arow) { this.toQChar.setRow(arow); }+/ 1523 1524 /+ #if QT_DEPRECATED_SINCE(5, 0) 1525 /+ QT_DEPRECATED char toAscii() const { return QChar(*this).toLatin1(); } +/ 1526 #endif +/ 1527 char toLatin1() const { return this.toQChar.toLatin1(); } 1528 ushort unicode() const { return this.toQChar.unicode(); } 1529 ref ushort unicode() { return s.data()[i].unicode(); } 1530 1531 } 1532 /+ Q_DECLARE_TYPEINFO(QCharRef, Q_MOVABLE_TYPE); 1533 1534 #if QT_STRINGVIEW_LEVEL < 2 1535 #endif 1536 1537 #if QT_DEPRECATED_SINCE(5, 9) +/ 1538 /+pragma(inline, true) bool operator ==(QString.Null, QString.Null) { return true; }+/ 1539 /+/+ QT_DEPRECATED_X("use QString::isNull()") +/ 1540 pragma(inline, true) bool operator ==(QString.Null, ref const(QString) s) { return s.isNull(); }+/ 1541 /+/+ QT_DEPRECATED_X("use QString::isNull()") +/ 1542 pragma(inline, true) bool operator ==(ref const(QString) s, QString.Null) { return s.isNull(); }+/ 1543 /+pragma(inline, true) bool operator !=(QString.Null, QString.Null) { return false; }+/ 1544 /+/+ QT_DEPRECATED_X("use !QString::isNull()") +/ 1545 pragma(inline, true) bool operator !=(QString.Null, ref const(QString) s) { return !s.isNull(); }+/ 1546 /+/+ QT_DEPRECATED_X("use !QString::isNull()") +/ 1547 pragma(inline, true) bool operator !=(ref const(QString) s, QString.Null) { return !s.isNull(); }+/ 1548 /+ #endif +/ 1549 1550 /+pragma(inline, true) bool operator ==(QLatin1String s1, QLatin1String s2)/+ noexcept+/ 1551 { 1552 import core.stdc.string; 1553 return s1.size() == s2.size() && (!s1.size() || !memcmp(s1.latin1(), s2.latin1(), s1.size())); 1554 }+/ 1555 /+pragma(inline, true) bool operator !=(QLatin1String s1, QLatin1String s2)/+ noexcept+/ 1556 { return !operator==(s1, s2); }+/ 1557 /+pragma(inline, true) bool operator <(QLatin1String s1, QLatin1String s2)/+ noexcept+/ 1558 { 1559 import core.stdc.string; 1560 1561 const(int) len = qMin(s1.size(), s2.size()); 1562 const(int) r = len ? memcmp(s1.latin1(), s2.latin1(), len) : 0; 1563 return r < 0 || (r == 0 && s1.size() < s2.size()); 1564 }+/ 1565 /+pragma(inline, true) bool operator >(QLatin1String s1, QLatin1String s2)/+ noexcept+/ 1566 { return operator<(s2, s1); }+/ 1567 /+pragma(inline, true) bool operator <=(QLatin1String s1, QLatin1String s2)/+ noexcept+/ 1568 { return !operator>(s1, s2); }+/ 1569 /+pragma(inline, true) bool operator >=(QLatin1String s1, QLatin1String s2)/+ noexcept+/ 1570 { return !operator<(s1, s2); }+/ 1571 1572 /+ #if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) 1573 inline bool QString::operator==(const char *s) const 1574 { return QString::compare_helper(constData(), size(), s, -1) == 0; } 1575 inline bool QString::operator!=(const char *s) const 1576 { return QString::compare_helper(constData(), size(), s, -1) != 0; } 1577 inline bool QString::operator<(const char *s) const 1578 { return QString::compare_helper(constData(), size(), s, -1) < 0; } 1579 inline bool QString::operator>(const char *s) const 1580 { return QString::compare_helper(constData(), size(), s, -1) > 0; } 1581 inline bool QString::operator<=(const char *s) const 1582 { return QString::compare_helper(constData(), size(), s, -1) <= 0; } 1583 inline bool QString::operator>=(const char *s) const 1584 { return QString::compare_helper(constData(), size(), s, -1) >= 0; } 1585 1586 inline QT_ASCII_CAST_WARN bool operator==(const char *s1, const QString &s2) 1587 { return QString::compare_helper(s2.constData(), s2.size(), s1, -1) == 0; } 1588 inline QT_ASCII_CAST_WARN bool operator!=(const char *s1, const QString &s2) 1589 { return QString::compare_helper(s2.constData(), s2.size(), s1, -1) != 0; } 1590 inline QT_ASCII_CAST_WARN bool operator<(const char *s1, const QString &s2) 1591 { return QString::compare_helper(s2.constData(), s2.size(), s1, -1) > 0; } 1592 inline QT_ASCII_CAST_WARN bool operator>(const char *s1, const QString &s2) 1593 { return QString::compare_helper(s2.constData(), s2.size(), s1, -1) < 0; } 1594 inline QT_ASCII_CAST_WARN bool operator<=(const char *s1, const QString &s2) 1595 { return QString::compare_helper(s2.constData(), s2.size(), s1, -1) >= 0; } 1596 inline QT_ASCII_CAST_WARN bool operator>=(const char *s1, const QString &s2) 1597 { return QString::compare_helper(s2.constData(), s2.size(), s1, -1) <= 0; } 1598 1599 inline QT_ASCII_CAST_WARN bool operator==(const char *s1, QLatin1String s2) 1600 { return QString::fromUtf8(s1) == s2; } 1601 inline QT_ASCII_CAST_WARN bool operator!=(const char *s1, QLatin1String s2) 1602 { return QString::fromUtf8(s1) != s2; } 1603 inline QT_ASCII_CAST_WARN bool operator<(const char *s1, QLatin1String s2) 1604 { return (QString::fromUtf8(s1) < s2); } 1605 inline QT_ASCII_CAST_WARN bool operator>(const char *s1, QLatin1String s2) 1606 { return (QString::fromUtf8(s1) > s2); } 1607 inline QT_ASCII_CAST_WARN bool operator<=(const char *s1, QLatin1String s2) 1608 { return (QString::fromUtf8(s1) <= s2); } 1609 inline QT_ASCII_CAST_WARN bool operator>=(const char *s1, QLatin1String s2) 1610 { return (QString::fromUtf8(s1) >= s2); } 1611 1612 inline QT_ASCII_CAST_WARN bool QLatin1String::operator==(const char *s) const 1613 { return QString::fromUtf8(s) == *this; } 1614 inline QT_ASCII_CAST_WARN bool QLatin1String::operator!=(const char *s) const 1615 { return QString::fromUtf8(s) != *this; } 1616 inline QT_ASCII_CAST_WARN bool QLatin1String::operator<(const char *s) const 1617 { return QString::fromUtf8(s) > *this; } 1618 inline QT_ASCII_CAST_WARN bool QLatin1String::operator>(const char *s) const 1619 { return QString::fromUtf8(s) < *this; } 1620 inline QT_ASCII_CAST_WARN bool QLatin1String::operator<=(const char *s) const 1621 { return QString::fromUtf8(s) >= *this; } 1622 inline QT_ASCII_CAST_WARN bool QLatin1String::operator>=(const char *s) const 1623 { return QString::fromUtf8(s) <= *this; } 1624 1625 inline QT_ASCII_CAST_WARN bool QLatin1String::operator==(const QByteArray &s) const 1626 { return QString::fromUtf8(s) == *this; } 1627 inline QT_ASCII_CAST_WARN bool QLatin1String::operator!=(const QByteArray &s) const 1628 { return QString::fromUtf8(s) != *this; } 1629 inline QT_ASCII_CAST_WARN bool QLatin1String::operator<(const QByteArray &s) const 1630 { return QString::fromUtf8(s) > *this; } 1631 inline QT_ASCII_CAST_WARN bool QLatin1String::operator>(const QByteArray &s) const 1632 { return QString::fromUtf8(s) < *this; } 1633 inline QT_ASCII_CAST_WARN bool QLatin1String::operator<=(const QByteArray &s) const 1634 { return QString::fromUtf8(s) >= *this; } 1635 inline QT_ASCII_CAST_WARN bool QLatin1String::operator>=(const QByteArray &s) const 1636 { return QString::fromUtf8(s) <= *this; } 1637 1638 inline QT_ASCII_CAST_WARN bool QString::operator==(const QByteArray &s) const 1639 { return QString::compare_helper(constData(), size(), s.constData(), qstrnlen(s.constData(), s.size())) == 0; } 1640 inline QT_ASCII_CAST_WARN bool QString::operator!=(const QByteArray &s) const 1641 { return QString::compare_helper(constData(), size(), s.constData(), qstrnlen(s.constData(), s.size())) != 0; } 1642 inline QT_ASCII_CAST_WARN bool QString::operator<(const QByteArray &s) const 1643 { return QString::compare_helper(constData(), size(), s.constData(), s.size()) < 0; } 1644 inline QT_ASCII_CAST_WARN bool QString::operator>(const QByteArray &s) const 1645 { return QString::compare_helper(constData(), size(), s.constData(), s.size()) > 0; } 1646 inline QT_ASCII_CAST_WARN bool QString::operator<=(const QByteArray &s) const 1647 { return QString::compare_helper(constData(), size(), s.constData(), s.size()) <= 0; } 1648 inline QT_ASCII_CAST_WARN bool QString::operator>=(const QByteArray &s) const 1649 { return QString::compare_helper(constData(), size(), s.constData(), s.size()) >= 0; } 1650 1651 inline bool QByteArray::operator==(const QString &s) const 1652 { return QString::compare_helper(s.constData(), s.size(), constData(), qstrnlen(constData(), size())) == 0; } 1653 inline bool QByteArray::operator!=(const QString &s) const 1654 { return QString::compare_helper(s.constData(), s.size(), constData(), qstrnlen(constData(), size())) != 0; } 1655 inline bool QByteArray::operator<(const QString &s) const 1656 { return QString::compare_helper(s.constData(), s.size(), constData(), size()) > 0; } 1657 inline bool QByteArray::operator>(const QString &s) const 1658 { return QString::compare_helper(s.constData(), s.size(), constData(), size()) < 0; } 1659 inline bool QByteArray::operator<=(const QString &s) const 1660 { return QString::compare_helper(s.constData(), s.size(), constData(), size()) >= 0; } 1661 inline bool QByteArray::operator>=(const QString &s) const 1662 { return QString::compare_helper(s.constData(), s.size(), constData(), size()) <= 0; } 1663 1664 #endif // !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) 1665 1666 #if !defined(QT_NO_CAST_TO_ASCII) && QT_DEPRECATED_SINCE(5, 15) 1667 inline QByteArray &QByteArray::append(const QString &s) 1668 { return append(s.toUtf8()); } 1669 inline QByteArray &QByteArray::insert(int i, const QString &s) 1670 { return insert(i, s.toUtf8()); } 1671 inline QByteArray &QByteArray::replace(char c, const QString &after) 1672 { return replace(c, after.toUtf8()); } 1673 inline QByteArray &QByteArray::replace(const QString &before, const char *after) 1674 { return replace(before.toUtf8(), after); } 1675 inline QByteArray &QByteArray::replace(const QString &before, const QByteArray &after) 1676 { return replace(before.toUtf8(), after); } 1677 inline QByteArray &QByteArray::operator+=(const QString &s) 1678 { return operator+=(s.toUtf8()); } 1679 inline int QByteArray::indexOf(const QString &s, int from) const 1680 { return indexOf(s.toUtf8(), from); } 1681 inline int QByteArray::lastIndexOf(const QString &s, int from) const 1682 { return lastIndexOf(s.toUtf8(), from); } 1683 #endif +/ // !defined(QT_NO_CAST_TO_ASCII) && QT_DEPRECATED_SINCE(5, 15) 1684 1685 version(QT_USE_FAST_OPERATOR_PLUS){}else 1686 version(QT_USE_QSTRINGBUILDER){}else 1687 { 1688 /+pragma(inline, true) const(QString) operator +(ref const(QString) s1, ref const(QString) s2) 1689 { auto t = QString(s1); t ~= s2; return t; }+/ 1690 /+pragma(inline, true) const(QString) operator +(ref const(QString) s1, QChar s2) 1691 { auto t = QString(s1); t ~= s2; return t; }+/ 1692 /+pragma(inline, true) const(QString) operator +(QChar s1, ref const(QString) s2) 1693 { auto t = QString(s1); t ~= s2; return t; }+/ 1694 /+ # if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) 1695 inline QT_ASCII_CAST_WARN const QString operator+(const QString &s1, const char *s2) 1696 { QString t(s1); t += QString::fromUtf8(s2); return t; } 1697 inline QT_ASCII_CAST_WARN const QString operator+(const char *s1, const QString &s2) 1698 { QString t = QString::fromUtf8(s1); t += s2; return t; } 1699 inline QT_ASCII_CAST_WARN const QString operator+(char c, const QString &s) 1700 { QString t = s; t.prepend(QChar::fromLatin1(c)); return t; } 1701 inline QT_ASCII_CAST_WARN const QString operator+(const QString &s, char c) 1702 { QString t = s; t += QChar::fromLatin1(c); return t; } 1703 inline QT_ASCII_CAST_WARN const QString operator+(const QByteArray &ba, const QString &s) 1704 { QString t = QString::fromUtf8(ba); t += s; return t; } 1705 inline QT_ASCII_CAST_WARN const QString operator+(const QString &s, const QByteArray &ba) 1706 { QString t(s); t += QString::fromUtf8(ba); return t; } 1707 # endif +/ // QT_NO_CAST_FROM_ASCII 1708 } 1709 1710 /+ inline std::string QString::toStdString() const 1711 { return toUtf8().toStdString(); } 1712 1713 inline QString QString::fromStdString(const std::string &s) 1714 { return fromUtf8(s.data(), int(s.size())); } 1715 1716 inline std::wstring QString::toStdWString() const 1717 { 1718 std::wstring str; 1719 str.resize(length()); 1720 #if __cplusplus >= 201703L 1721 str.resize(toWCharArray(str.data())); 1722 #else 1723 if (length()) 1724 str.resize(toWCharArray(&str.front())); 1725 #endif 1726 return str; 1727 } 1728 1729 inline QString QString::fromStdWString(const std::wstring &s) 1730 { return fromWCharArray(s.data(), int(s.size())); } 1731 1732 #if defined(Q_STDLIB_UNICODE_STRINGS) 1733 inline QString QString::fromStdU16String(const std::u16string &s) 1734 { return fromUtf16(s.data(), int(s.size())); } 1735 1736 inline std::u16string QString::toStdU16String() const 1737 { return std::u16string(reinterpret_cast<const char16_t*>(utf16()), length()); } 1738 1739 inline QString QString::fromStdU32String(const std::u32string &s) 1740 { return fromUcs4(s.data(), int(s.size())); } 1741 1742 inline std::u32string QString::toStdU32String() const 1743 { 1744 std::u32string u32str(length(), char32_t(0)); 1745 int len = toUcs4_helper(d->data(), length(), reinterpret_cast<uint*>(&u32str[0])); 1746 u32str.resize(len); 1747 return u32str; 1748 } 1749 #endif 1750 1751 #if !defined(QT_NO_DATASTREAM) || (defined(QT_BOOTSTRAPPED) && !defined(QT_BUILD_QMAKE)) 1752 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QString &); 1753 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QString &); 1754 #endif +/ 1755 /+pragma(inline, true) QFlags!(QString.SectionFlags.enum_type) operator |(QString.SectionFlags.enum_type f1, QString.SectionFlags.enum_type f2)/+noexcept+/{return QFlags!(QString.SectionFlags.enum_type)(f1)|f2;}+/ 1756 /+pragma(inline, true) QFlags!(QString.SectionFlags.enum_type) operator |(QString.SectionFlags.enum_type f1, QFlags!(QString.SectionFlags.enum_type) f2)/+noexcept+/{return f2|f1;}+/ 1757 /+pragma(inline, true) QIncompatibleFlag operator |(QString.SectionFlags.enum_type f1, int f2)/+noexcept+/{return QIncompatibleFlag(int(f1)|f2);}+/ 1758 1759 /+ Q_DECLARE_SHARED(QString) 1760 Q_DECLARE_OPERATORS_FOR_FLAGS(QString::SectionFlags) +/ 1761 1762 @Q_PRIMITIVE_TYPE extern(C++, class) struct /+ Q_CORE_EXPORT +/ QStringRef { 1763 private: 1764 static import qt.core.stringalgorithms; 1765 static import qt.core.namespace; 1766 const(QString)* m_string = null; 1767 int m_position = 0; 1768 int m_size = 0; 1769 public: 1770 alias size_type = QString.size_type; 1771 alias value_type = QString.value_type; 1772 alias const_iterator = const(QChar)*; 1773 /+ typedef std::reverse_iterator<const_iterator> const_reverse_iterator; +/ 1774 alias const_pointer = QString.const_pointer; 1775 /+ typedef QString::const_reference const_reference; +/ 1776 1777 // ### Qt 6: make this constructor constexpr, after the destructor is made trivial 1778 /+pragma(inline, true) this() 1779 { 1780 this.m_string = null; 1781 this.m_position = 0; 1782 this.m_size = 0; 1783 }+/ 1784 pragma(inline, true) this(const(QString)* aString, int aPosition, int aSize) 1785 { 1786 this.m_string = aString; 1787 this.m_position = aPosition; 1788 this.m_size = aSize; 1789 } 1790 pragma(inline, true) this(const(QString)* aString) 1791 { 1792 this.m_string = aString; 1793 this.m_position = 0; 1794 this.m_size = aString?aString.size() : 0; 1795 } 1796 1797 /+ #if QT_VERSION < QT_VERSION_CHECK(6,0,0) +/ 1798 // ### Qt 6: remove all of these, the implicit ones are fine 1799 @disable this(this); 1800 this(ref const(QStringRef) other)/+ noexcept+/ 1801 { 1802 this.m_string = other.m_string; 1803 this.m_position = other.m_position; 1804 this.m_size = other.m_size; 1805 } 1806 /+ QStringRef(QStringRef &&other) noexcept : m_string(other.m_string), m_position(other.m_position), m_size(other.m_size) {} +/ 1807 /+ QStringRef &operator=(QStringRef &&other) noexcept { return *this = other; } +/ 1808 /+ref QStringRef operator =(ref const(QStringRef) other)/+ noexcept+/ 1809 { 1810 m_string = other.m_string; m_position = other.m_position; 1811 m_size = other.m_size; return this; 1812 }+/ 1813 pragma(inline, true) ~this(){} 1814 /+ #endif +/ // Qt < 6.0.0 1815 1816 /+ inline const QString *string() const { return m_string; } +/ 1817 pragma(inline, true) int position() const { return m_position; } 1818 pragma(inline, true) int size() const { return m_size; } 1819 pragma(inline, true) int count() const { return m_size; } 1820 pragma(inline, true) int length() const { return m_size; } 1821 1822 static if(QT_STRINGVIEW_LEVEL < 2) 1823 { 1824 int indexOf(ref const(QString) str, int from = 0, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 1825 int indexOf(ref const(QStringRef) str, int from = 0, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 1826 } 1827 /+ Q_REQUIRED_RESULT +/ int indexOf(QStringView s, int from = 0, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const/+ noexcept+/ 1828 { 1829 import qt.core.stringalgorithms; 1830 return cast(int)(/+ QtPrivate:: +/qt.core.stringalgorithms.findString(QStringView(this), from, s, cs)); 1831 } // ### Qt6: qsizetype 1832 int indexOf(QChar ch, int from = 0, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 1833 int indexOf(QLatin1String str, int from = 0, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 1834 static if(QT_STRINGVIEW_LEVEL < 2) 1835 { 1836 int lastIndexOf(ref const(QStringRef) str, int from = -1, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 1837 int lastIndexOf(ref const(QString) str, int from = -1, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 1838 } 1839 int lastIndexOf(QChar ch, int from = -1, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 1840 int lastIndexOf(QLatin1String str, int from = -1, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 1841 /+ Q_REQUIRED_RESULT +/ int lastIndexOf(QStringView s, int from = -1, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const/+ noexcept+/ 1842 { 1843 import qt.core.stringalgorithms; 1844 return cast(int)(/+ QtPrivate:: +/qt.core.stringalgorithms.lastIndexOf(QStringView(this), from, s, cs)); 1845 } // ### Qt6: qsizetype 1846 1847 static if(QT_STRINGVIEW_LEVEL < 2) 1848 { 1849 pragma(inline, true) bool contains(ref const(QString) s, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const 1850 { return indexOf(s, 0, cs) != -1; } 1851 pragma(inline, true) bool contains(ref const(QStringRef) s, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const 1852 { return indexOf(s, 0, cs) != -1; } 1853 } 1854 pragma(inline, true) bool contains(QChar c, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const 1855 { return indexOf(c, 0, cs) != -1; } 1856 pragma(inline, true) bool contains(QLatin1String s, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const 1857 { return indexOf(s, 0, cs) != -1; } 1858 pragma(inline, true) bool contains(QStringView s, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const/+ noexcept+/ 1859 { return indexOf(s, 0, cs) != -1; } 1860 1861 int count(ref const(QString) s, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 1862 int count(QChar c, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 1863 int count(ref const(QStringRef) s, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 1864 1865 /+ #if QT_DEPRECATED_SINCE(5, 15) +/ 1866 /+ Q_REQUIRED_RESULT +/ /+ QT_DEPRECATED_VERSION_X_5_15("Use Qt::SplitBehavior variant instead") +/ 1867 QVector!(QStringRef) split(ref const(QString) sep, QString.SplitBehavior behavior, 1868 /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 1869 /+ Q_REQUIRED_RESULT +/ /+ QT_DEPRECATED_VERSION_X_5_15("Use Qt::SplitBehavior variant instead") +/ 1870 QVector!(QStringRef) split(QChar sep, QString.SplitBehavior behavior, 1871 /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 1872 /+ #endif +/ // 5.15 deprecations 1873 1874 /+ Q_REQUIRED_RESULT +/ 1875 QVector!(QStringRef) split(ref const(QString) sep, /+ Qt:: +/qt.core.namespace.SplitBehavior behavior = /+ Qt:: +/qt.core.namespace.SplitBehaviorFlags.KeepEmptyParts, 1876 /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 1877 /+ Q_REQUIRED_RESULT +/ 1878 QVector!(QStringRef) split(QChar sep, /+ Qt:: +/qt.core.namespace.SplitBehavior behavior = /+ Qt:: +/qt.core.namespace.SplitBehaviorFlags.KeepEmptyParts, 1879 /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 1880 1881 /+ Q_REQUIRED_RESULT +/ QStringRef left(int n) const; 1882 /+ Q_REQUIRED_RESULT +/ QStringRef right(int n) const; 1883 /+ Q_REQUIRED_RESULT +/ QStringRef mid(int pos, int n = -1) const; 1884 /+ Q_REQUIRED_RESULT +/ QStringRef chopped(int n) const 1885 { (mixin(Q_ASSERT(q{n >= 0}))); (mixin(Q_ASSERT(q{n <= QStringRef.size()}))); return left(size() - n); } 1886 1887 void truncate(int pos)/+ noexcept+/ { m_size = qBound(0, pos, m_size); } 1888 void chop(int n)/+ noexcept+/ 1889 { 1890 if (n >= m_size) 1891 m_size = 0; 1892 else if (n > 0) 1893 m_size -= n; 1894 } 1895 1896 bool isRightToLeft() const; 1897 1898 /+ Q_REQUIRED_RESULT +/ bool startsWith(QStringView s, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const/+ noexcept+/ 1899 { 1900 import qt.core.stringalgorithms; 1901 return /+ QtPrivate:: +/qt.core.stringalgorithms.startsWith(QStringView(this), s, cs); 1902 } 1903 bool startsWith(QLatin1String s, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 1904 bool startsWith(QChar c, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 1905 static if(QT_STRINGVIEW_LEVEL < 2) 1906 { 1907 bool startsWith(ref const(QString) s, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 1908 bool startsWith(ref const(QStringRef) c, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 1909 } 1910 1911 /+ Q_REQUIRED_RESULT +/ bool endsWith(QStringView s, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const/+ noexcept+/ 1912 { 1913 import qt.core.stringalgorithms; 1914 return /+ QtPrivate:: +/qt.core.stringalgorithms.endsWith(QStringView(this), s, cs); 1915 } 1916 bool endsWith(QLatin1String s, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 1917 bool endsWith(QChar c, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 1918 static if(QT_STRINGVIEW_LEVEL < 2) 1919 { 1920 bool endsWith(ref const(QString) s, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 1921 bool endsWith(ref const(QStringRef) c, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const; 1922 } 1923 1924 /+pragma(inline, true) ref QStringRef operator =(const(QString)* aString) 1925 { m_string = aString; m_position = 0; m_size = aString?aString.size():0; return this; }+/ 1926 1927 pragma(inline, true) const(QChar)* unicode() const 1928 { 1929 if (!m_string) 1930 return reinterpret_cast!(const(QChar)*)(QString.Data.sharedNull().data()); 1931 return m_string.unicode() + m_position; 1932 } 1933 pragma(inline, true) const(QChar)* data() const { return unicode(); } 1934 pragma(inline, true) const(QChar)* constData() const { return unicode(); } 1935 1936 pragma(inline, true) const_iterator begin() const { return unicode(); } 1937 pragma(inline, true) const_iterator cbegin() const { return unicode(); } 1938 pragma(inline, true) const_iterator constBegin() const { return unicode(); } 1939 pragma(inline, true) const_iterator end() const { return unicode() + size(); } 1940 pragma(inline, true) const_iterator cend() const { return unicode() + size(); } 1941 pragma(inline, true) const_iterator constEnd() const { return unicode() + size(); } 1942 /+ inline const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); } +/ 1943 /+ inline const_reverse_iterator crbegin() const { return rbegin(); } +/ 1944 /+ inline const_reverse_iterator rend() const { return const_reverse_iterator(begin()); } +/ 1945 /+ inline const_reverse_iterator crend() const { return rend(); } +/ 1946 1947 /+ #if QT_DEPRECATED_SINCE(5, 0) 1948 Q_REQUIRED_RESULT QT_DEPRECATED QByteArray toAscii() const 1949 { return toLatin1(); } 1950 #endif +/ 1951 /+ Q_REQUIRED_RESULT +/ QByteArray toLatin1() const; 1952 /+ Q_REQUIRED_RESULT +/ QByteArray toUtf8() const; 1953 /+ Q_REQUIRED_RESULT +/ QByteArray toLocal8Bit() const; 1954 /+ Q_REQUIRED_RESULT +/ QVector!(uint) toUcs4() const; 1955 1956 pragma(inline, true) void clear() { m_string = null; m_position = m_size = 0; } 1957 QString toString() const; 1958 pragma(inline, true) bool isEmpty() const { return m_size == 0; } 1959 pragma(inline, true) bool isNull() const { return m_string is null || m_string.isNull(); } 1960 1961 QStringRef appendTo(QString* string) const; 1962 1963 pragma(inline, true) const(QChar) at(int i) const 1964 { (mixin(Q_ASSERT(q{uint(i) < uint(QStringRef.size())}))); return m_string.at(i + m_position); } 1965 QChar opIndex(int i) const { return at(i); } 1966 /+ Q_REQUIRED_RESULT +/ QChar front() const { return at(0); } 1967 /+ Q_REQUIRED_RESULT +/ QChar back() const { return at(size() - 1); } 1968 1969 /+ #if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) 1970 // ASCII compatibility 1971 inline QT_ASCII_CAST_WARN bool operator==(const char *s) const; 1972 inline QT_ASCII_CAST_WARN bool operator!=(const char *s) const; 1973 inline QT_ASCII_CAST_WARN bool operator<(const char *s) const; 1974 inline QT_ASCII_CAST_WARN bool operator<=(const char *s) const; 1975 inline QT_ASCII_CAST_WARN bool operator>(const char *s) const; 1976 inline QT_ASCII_CAST_WARN bool operator>=(const char *s) const; 1977 #endif +/ 1978 1979 pragma(inline, true) int compare(ref const(QString) s, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const/+ noexcept+/ 1980 { return QString.compare_helper(constData(), length(), s.constData(), s.length(), cs); } 1981 pragma(inline, true) int compare(ref const(QStringRef) s, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const/+ noexcept+/ 1982 { return QString.compare_helper(constData(), length(), s.constData(), s.length(), cs); } 1983 int compare(QChar c, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const/+ noexcept+/ 1984 { 1985 import qt.core.stringalgorithms; 1986 return /+ QtPrivate:: +/qt.core.stringalgorithms.compareStrings(QStringView(this), QStringView(&c, 1), cs); 1987 } 1988 pragma(inline, true) int compare(QLatin1String s, /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive) const/+ noexcept+/ 1989 { return QString.compare_helper(constData(), length(), s, cs); } 1990 /+ #if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) 1991 int compare(const QByteArray &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const 1992 { return QString::compare_helper(unicode(), size(), s.data(), qstrnlen(s.data(), s.size()), cs); } 1993 #endif +/ 1994 pragma(inline, true) static int compare(ref const(QStringRef) s1, ref const(QString) s2, 1995 /+ Qt:: +/qt.core.namespace.CaseSensitivity cs /+ = Qt::CaseSensitive +/)/+ noexcept+/ 1996 { return QString.compare_helper(s1.constData(), s1.length(), s2.constData(), s2.length(), cs); } 1997 pragma(inline, true) static int compare(ref const(QStringRef) s1, ref const(QStringRef) s2, 1998 /+ Qt:: +/qt.core.namespace.CaseSensitivity cs /+ = Qt::CaseSensitive +/)/+ noexcept+/ 1999 { return QString.compare_helper(s1.constData(), s1.length(), s2.constData(), s2.length(), cs); } 2000 pragma(inline, true) static int compare(ref const(QStringRef) s1, QLatin1String s2, 2001 /+ Qt:: +/qt.core.namespace.CaseSensitivity cs = /+ Qt:: +/qt.core.namespace.CaseSensitivity.CaseSensitive)/+ noexcept+/ 2002 { return QString.compare_helper(s1.constData(), s1.length(), s2, cs); } 2003 2004 pragma(inline, true) int localeAwareCompare(ref const(QString) s) const 2005 { return QString.localeAwareCompare_helper(constData(), length(), s.constData(), s.length()); } 2006 pragma(inline, true) int localeAwareCompare(ref const(QStringRef) s) const 2007 { return QString.localeAwareCompare_helper(constData(), length(), s.constData(), s.length()); } 2008 pragma(inline, true) int localeAwareCompare(QStringView s) const 2009 { return QString.localeAwareCompare_helper(constData(), length(), s.data(), cast(int)(s.size())); } 2010 pragma(inline, true) static int localeAwareCompare(ref const(QStringRef) s1, ref const(QString) s2) 2011 { return QString.localeAwareCompare_helper(s1.constData(), s1.length(), s2.constData(), s2.length()); } 2012 pragma(inline, true) static int localeAwareCompare(ref const(QStringRef) s1, ref const(QStringRef) s2) 2013 { return QString.localeAwareCompare_helper(s1.constData(), s1.length(), s2.constData(), s2.length()); } 2014 pragma(inline, true) static int localeAwareCompare(QStringView s1, QStringView s2) 2015 { return QString.localeAwareCompare_helper(s1.data(), cast(int)(s1.size()), s2.data(), cast(int)(s2.size())); } 2016 2017 /+ Q_REQUIRED_RESULT +/ QStringRef trimmed() const; 2018 short toShort(bool* ok = null, int base = 10) const; 2019 ushort toUShort(bool* ok = null, int base = 10) const; 2020 int toInt(bool* ok = null, int base = 10) const; 2021 uint toUInt(bool* ok = null, int base = 10) const; 2022 cpp_long toLong(bool* ok = null, int base = 10) const; 2023 cpp_ulong toULong(bool* ok = null, int base = 10) const; 2024 qlonglong toLongLong(bool* ok = null, int base = 10) const; 2025 qulonglong toULongLong(bool* ok = null, int base = 10) const; 2026 float toFloat(bool* ok = null) const; 2027 double toDouble(bool* ok = null) const; 2028 } 2029 /+ Q_DECLARE_TYPEINFO(QStringRef, Q_PRIMITIVE_TYPE); +/ 2030 2031 // QStringRef <> QStringRef 2032 /+/+ Q_CORE_EXPORT +/ bool operator ==(ref const(QStringRef) s1, ref const(QStringRef) s2)/+ noexcept+/;+/ 2033 /+pragma(inline, true) bool operator !=(ref const(QStringRef) s1, ref const(QStringRef) s2)/+ noexcept+/ 2034 { return !(s1 == s2); }+/ 2035 /+/+ Q_CORE_EXPORT +/ bool operator <(ref const(QStringRef) s1, ref const(QStringRef) s2)/+ noexcept+/;+/ 2036 /+pragma(inline, true) bool operator >(ref const(QStringRef) s1, ref const(QStringRef) s2)/+ noexcept+/ 2037 { return s2 < s1; }+/ 2038 /+pragma(inline, true) bool operator <=(ref const(QStringRef) s1, ref const(QStringRef) s2)/+ noexcept+/ 2039 { return !(s1 > s2); }+/ 2040 /+pragma(inline, true) bool operator >=(ref const(QStringRef) s1, ref const(QStringRef) s2)/+ noexcept+/ 2041 { return !(s1 < s2); }+/ 2042 2043 // QString <> QStringRef 2044 /+/+ Q_CORE_EXPORT +/ bool operator ==(ref const(QString) lhs, ref const(QStringRef) rhs)/+ noexcept+/;+/ 2045 /+pragma(inline, true) bool operator !=(ref const(QString) lhs, ref const(QStringRef) rhs)/+ noexcept+/ { return lhs.compare(rhs) != 0; }+/ 2046 /+pragma(inline, true) bool operator < (ref const(QString) lhs, ref const(QStringRef) rhs)/+ noexcept+/ { return lhs.compare(rhs) < 0; }+/ 2047 /+pragma(inline, true) bool operator > (ref const(QString) lhs, ref const(QStringRef) rhs)/+ noexcept+/ { return lhs.compare(rhs) > 0; }+/ 2048 /+pragma(inline, true) bool operator <=(ref const(QString) lhs, ref const(QStringRef) rhs)/+ noexcept+/ { return lhs.compare(rhs) <= 0; }+/ 2049 /+pragma(inline, true) bool operator >=(ref const(QString) lhs, ref const(QStringRef) rhs)/+ noexcept+/ { return lhs.compare(rhs) >= 0; }+/ 2050 2051 /+pragma(inline, true) bool operator ==(ref const(QStringRef) lhs, ref const(QString) rhs)/+ noexcept+/ { return rhs == lhs; }+/ 2052 /+pragma(inline, true) bool operator !=(ref const(QStringRef) lhs, ref const(QString) rhs)/+ noexcept+/ { return rhs != lhs; }+/ 2053 /+pragma(inline, true) bool operator < (ref const(QStringRef) lhs, ref const(QString) rhs)/+ noexcept+/ { return rhs > lhs; }+/ 2054 /+pragma(inline, true) bool operator > (ref const(QStringRef) lhs, ref const(QString) rhs)/+ noexcept+/ { return rhs < lhs; }+/ 2055 /+pragma(inline, true) bool operator <=(ref const(QStringRef) lhs, ref const(QString) rhs)/+ noexcept+/ { return rhs >= lhs; }+/ 2056 /+pragma(inline, true) bool operator >=(ref const(QStringRef) lhs, ref const(QString) rhs)/+ noexcept+/ { return rhs <= lhs; }+/ 2057 2058 /+ #if QT_STRINGVIEW_LEVEL < 2 2059 #endif +/ 2060 2061 // QLatin1String <> QStringRef 2062 /+/+ Q_CORE_EXPORT +/ bool operator ==(QLatin1String lhs, ref const(QStringRef) rhs)/+ noexcept+/;+/ 2063 /+pragma(inline, true) bool operator !=(QLatin1String lhs, ref const(QStringRef) rhs)/+ noexcept+/ { return rhs.compare(lhs) != 0; }+/ 2064 /+pragma(inline, true) bool operator < (QLatin1String lhs, ref const(QStringRef) rhs)/+ noexcept+/ { return rhs.compare(lhs) > 0; }+/ 2065 /+pragma(inline, true) bool operator > (QLatin1String lhs, ref const(QStringRef) rhs)/+ noexcept+/ { return rhs.compare(lhs) < 0; }+/ 2066 /+pragma(inline, true) bool operator <=(QLatin1String lhs, ref const(QStringRef) rhs)/+ noexcept+/ { return rhs.compare(lhs) >= 0; }+/ 2067 /+pragma(inline, true) bool operator >=(QLatin1String lhs, ref const(QStringRef) rhs)/+ noexcept+/ { return rhs.compare(lhs) <= 0; }+/ 2068 2069 /+pragma(inline, true) bool operator ==(ref const(QStringRef) lhs, QLatin1String rhs)/+ noexcept+/ { return rhs == lhs; }+/ 2070 /+pragma(inline, true) bool operator !=(ref const(QStringRef) lhs, QLatin1String rhs)/+ noexcept+/ { return rhs != lhs; }+/ 2071 /+pragma(inline, true) bool operator < (ref const(QStringRef) lhs, QLatin1String rhs)/+ noexcept+/ { return rhs > lhs; }+/ 2072 /+pragma(inline, true) bool operator > (ref const(QStringRef) lhs, QLatin1String rhs)/+ noexcept+/ { return rhs < lhs; }+/ 2073 /+pragma(inline, true) bool operator <=(ref const(QStringRef) lhs, QLatin1String rhs)/+ noexcept+/ { return rhs >= lhs; }+/ 2074 /+pragma(inline, true) bool operator >=(ref const(QStringRef) lhs, QLatin1String rhs)/+ noexcept+/ { return rhs <= lhs; }+/ 2075 2076 // QChar <> QString 2077 /+pragma(inline, true) bool operator ==(QChar lhs, ref const(QString) rhs)/+ noexcept+/ 2078 { return rhs.size() == 1 && lhs == rhs.front(); }+/ 2079 /+pragma(inline, true) bool operator < (QChar lhs, ref const(QString) rhs)/+ noexcept+/ 2080 { return QString.compare_helper(&lhs, 1, rhs.data(), rhs.size()) < 0; }+/ 2081 /+pragma(inline, true) bool operator > (QChar lhs, ref const(QString) rhs)/+ noexcept+/ 2082 { return QString.compare_helper(&lhs, 1, rhs.data(), rhs.size()) > 0; }+/ 2083 2084 /+pragma(inline, true) bool operator !=(QChar lhs, ref const(QString) rhs)/+ noexcept+/ { return !(lhs == rhs); }+/ 2085 /+pragma(inline, true) bool operator <=(QChar lhs, ref const(QString) rhs)/+ noexcept+/ { return !(lhs > rhs); }+/ 2086 /+pragma(inline, true) bool operator >=(QChar lhs, ref const(QString) rhs)/+ noexcept+/ { return !(lhs < rhs); }+/ 2087 2088 /+pragma(inline, true) bool operator ==(ref const(QString) lhs, QChar rhs)/+ noexcept+/ { return rhs == lhs; }+/ 2089 /+pragma(inline, true) bool operator !=(ref const(QString) lhs, QChar rhs)/+ noexcept+/ { return !(rhs == lhs); }+/ 2090 /+pragma(inline, true) bool operator < (ref const(QString) lhs, QChar rhs)/+ noexcept+/ { return rhs > lhs; }+/ 2091 /+pragma(inline, true) bool operator > (ref const(QString) lhs, QChar rhs)/+ noexcept+/ { return rhs < lhs; }+/ 2092 /+pragma(inline, true) bool operator <=(ref const(QString) lhs, QChar rhs)/+ noexcept+/ { return !(rhs < lhs); }+/ 2093 /+pragma(inline, true) bool operator >=(ref const(QString) lhs, QChar rhs)/+ noexcept+/ { return !(rhs > lhs); }+/ 2094 2095 // QChar <> QStringRef 2096 /+pragma(inline, true) bool operator ==(QChar lhs, ref const(QStringRef) rhs)/+ noexcept+/ 2097 { return rhs.size() == 1 && lhs == rhs.front(); }+/ 2098 /+pragma(inline, true) bool operator < (QChar lhs, ref const(QStringRef) rhs)/+ noexcept+/ 2099 { return QString.compare_helper(&lhs, 1, rhs.data(), rhs.size()) < 0; }+/ 2100 /+pragma(inline, true) bool operator > (QChar lhs, ref const(QStringRef) rhs)/+ noexcept+/ 2101 { return QString.compare_helper(&lhs, 1, rhs.data(), rhs.size()) > 0; }+/ 2102 2103 /+pragma(inline, true) bool operator !=(QChar lhs, ref const(QStringRef) rhs)/+ noexcept+/ { return !(lhs == rhs); }+/ 2104 /+pragma(inline, true) bool operator <=(QChar lhs, ref const(QStringRef) rhs)/+ noexcept+/ { return !(lhs > rhs); }+/ 2105 /+pragma(inline, true) bool operator >=(QChar lhs, ref const(QStringRef) rhs)/+ noexcept+/ { return !(lhs < rhs); }+/ 2106 2107 /+pragma(inline, true) bool operator ==(ref const(QStringRef) lhs, QChar rhs)/+ noexcept+/ { return rhs == lhs; }+/ 2108 /+pragma(inline, true) bool operator !=(ref const(QStringRef) lhs, QChar rhs)/+ noexcept+/ { return !(rhs == lhs); }+/ 2109 /+pragma(inline, true) bool operator < (ref const(QStringRef) lhs, QChar rhs)/+ noexcept+/ { return rhs > lhs; }+/ 2110 /+pragma(inline, true) bool operator > (ref const(QStringRef) lhs, QChar rhs)/+ noexcept+/ { return rhs < lhs; }+/ 2111 /+pragma(inline, true) bool operator <=(ref const(QStringRef) lhs, QChar rhs)/+ noexcept+/ { return !(rhs < lhs); }+/ 2112 /+pragma(inline, true) bool operator >=(ref const(QStringRef) lhs, QChar rhs)/+ noexcept+/ { return !(rhs > lhs); }+/ 2113 2114 // QChar <> QLatin1String 2115 /+pragma(inline, true) bool operator ==(QChar lhs, QLatin1String rhs)/+ noexcept+/ 2116 { return rhs.size() == 1 && lhs == rhs.front(); }+/ 2117 /+pragma(inline, true) bool operator < (QChar lhs, QLatin1String rhs)/+ noexcept+/ 2118 { return QString.compare_helper(&lhs, 1, rhs) < 0; }+/ 2119 /+pragma(inline, true) bool operator > (QChar lhs, QLatin1String rhs)/+ noexcept+/ 2120 { return QString.compare_helper(&lhs, 1, rhs) > 0; }+/ 2121 2122 /+pragma(inline, true) bool operator !=(QChar lhs, QLatin1String rhs)/+ noexcept+/ { return !(lhs == rhs); }+/ 2123 /+pragma(inline, true) bool operator <=(QChar lhs, QLatin1String rhs)/+ noexcept+/ { return !(lhs > rhs); }+/ 2124 /+pragma(inline, true) bool operator >=(QChar lhs, QLatin1String rhs)/+ noexcept+/ { return !(lhs < rhs); }+/ 2125 2126 /+pragma(inline, true) bool operator ==(QLatin1String lhs, QChar rhs)/+ noexcept+/ { return rhs == lhs; }+/ 2127 /+pragma(inline, true) bool operator !=(QLatin1String lhs, QChar rhs)/+ noexcept+/ { return !(rhs == lhs); }+/ 2128 /+pragma(inline, true) bool operator < (QLatin1String lhs, QChar rhs)/+ noexcept+/ { return rhs > lhs; }+/ 2129 /+pragma(inline, true) bool operator > (QLatin1String lhs, QChar rhs)/+ noexcept+/ { return rhs < lhs; }+/ 2130 /+pragma(inline, true) bool operator <=(QLatin1String lhs, QChar rhs)/+ noexcept+/ { return !(rhs < lhs); }+/ 2131 /+pragma(inline, true) bool operator >=(QLatin1String lhs, QChar rhs)/+ noexcept+/ { return !(rhs > lhs); }+/ 2132 2133 // QStringView <> QStringView 2134 /+pragma(inline, true) bool operator ==(QStringView lhs, QStringView rhs)/+ noexcept+/ { 2135 import qt.core.stringalgorithms; 2136 return lhs.size() == rhs.size() && /+ QtPrivate:: +/qt.core.stringalgorithms.compareStrings(lhs, rhs) == 0; 2137 }+/ 2138 /+pragma(inline, true) bool operator !=(QStringView lhs, QStringView rhs)/+ noexcept+/ { return !(lhs == rhs); }+/ 2139 /+pragma(inline, true) bool operator < (QStringView lhs, QStringView rhs)/+ noexcept+/ { 2140 import qt.core.stringalgorithms; 2141 return /+ QtPrivate:: +/qt.core.stringalgorithms.compareStrings(lhs, rhs) < 0; 2142 }+/ 2143 /+pragma(inline, true) bool operator <=(QStringView lhs, QStringView rhs)/+ noexcept+/ { 2144 import qt.core.stringalgorithms; 2145 return /+ QtPrivate:: +/qt.core.stringalgorithms.compareStrings(lhs, rhs) <= 0; 2146 }+/ 2147 /+pragma(inline, true) bool operator > (QStringView lhs, QStringView rhs)/+ noexcept+/ { 2148 import qt.core.stringalgorithms; 2149 return /+ QtPrivate:: +/qt.core.stringalgorithms.compareStrings(lhs, rhs) > 0; 2150 }+/ 2151 /+pragma(inline, true) bool operator >=(QStringView lhs, QStringView rhs)/+ noexcept+/ { 2152 import qt.core.stringalgorithms; 2153 return /+ QtPrivate:: +/qt.core.stringalgorithms.compareStrings(lhs, rhs) >= 0; 2154 }+/ 2155 2156 // QStringView <> QChar 2157 /+pragma(inline, true) bool operator ==(QStringView lhs, QChar rhs)/+ noexcept+/ { return lhs == QStringView(&rhs, 1); }+/ 2158 /+pragma(inline, true) bool operator !=(QStringView lhs, QChar rhs)/+ noexcept+/ { return lhs != QStringView(&rhs, 1); }+/ 2159 /+pragma(inline, true) bool operator < (QStringView lhs, QChar rhs)/+ noexcept+/ { return lhs < QStringView(&rhs, 1); }+/ 2160 /+pragma(inline, true) bool operator <=(QStringView lhs, QChar rhs)/+ noexcept+/ { return lhs <= QStringView(&rhs, 1); }+/ 2161 /+pragma(inline, true) bool operator > (QStringView lhs, QChar rhs)/+ noexcept+/ { return lhs > QStringView(&rhs, 1); }+/ 2162 /+pragma(inline, true) bool operator >=(QStringView lhs, QChar rhs)/+ noexcept+/ { return lhs >= QStringView(&rhs, 1); }+/ 2163 2164 /+pragma(inline, true) bool operator ==(QChar lhs, QStringView rhs)/+ noexcept+/ { return QStringView(&lhs, 1) == rhs; }+/ 2165 /+pragma(inline, true) bool operator !=(QChar lhs, QStringView rhs)/+ noexcept+/ { return QStringView(&lhs, 1) != rhs; }+/ 2166 /+pragma(inline, true) bool operator < (QChar lhs, QStringView rhs)/+ noexcept+/ { return QStringView(&lhs, 1) < rhs; }+/ 2167 /+pragma(inline, true) bool operator <=(QChar lhs, QStringView rhs)/+ noexcept+/ { return QStringView(&lhs, 1) <= rhs; }+/ 2168 /+pragma(inline, true) bool operator > (QChar lhs, QStringView rhs)/+ noexcept+/ { return QStringView(&lhs, 1) > rhs; }+/ 2169 /+pragma(inline, true) bool operator >=(QChar lhs, QStringView rhs)/+ noexcept+/ { return QStringView(&lhs, 1) >= rhs; }+/ 2170 2171 // QStringView <> QLatin1String 2172 /+pragma(inline, true) bool operator ==(QStringView lhs, QLatin1String rhs)/+ noexcept+/ { 2173 import qt.core.stringalgorithms; 2174 return lhs.size() == rhs.size() && /+ QtPrivate:: +/qt.core.stringalgorithms.compareStrings(lhs, rhs) == 0; 2175 }+/ 2176 /+pragma(inline, true) bool operator !=(QStringView lhs, QLatin1String rhs)/+ noexcept+/ { return !(lhs == rhs); }+/ 2177 /+pragma(inline, true) bool operator < (QStringView lhs, QLatin1String rhs)/+ noexcept+/ { 2178 import qt.core.stringalgorithms; 2179 return /+ QtPrivate:: +/qt.core.stringalgorithms.compareStrings(lhs, rhs) < 0; 2180 }+/ 2181 /+pragma(inline, true) bool operator <=(QStringView lhs, QLatin1String rhs)/+ noexcept+/ { 2182 import qt.core.stringalgorithms; 2183 return /+ QtPrivate:: +/qt.core.stringalgorithms.compareStrings(lhs, rhs) <= 0; 2184 }+/ 2185 /+pragma(inline, true) bool operator > (QStringView lhs, QLatin1String rhs)/+ noexcept+/ { 2186 import qt.core.stringalgorithms; 2187 return /+ QtPrivate:: +/qt.core.stringalgorithms.compareStrings(lhs, rhs) > 0; 2188 }+/ 2189 /+pragma(inline, true) bool operator >=(QStringView lhs, QLatin1String rhs)/+ noexcept+/ { 2190 import qt.core.stringalgorithms; 2191 return /+ QtPrivate:: +/qt.core.stringalgorithms.compareStrings(lhs, rhs) >= 0; 2192 }+/ 2193 2194 /+pragma(inline, true) bool operator ==(QLatin1String lhs, QStringView rhs)/+ noexcept+/ { 2195 import qt.core.stringalgorithms; 2196 return lhs.size() == rhs.size() && /+ QtPrivate:: +/qt.core.stringalgorithms.compareStrings(lhs, rhs) == 0; 2197 }+/ 2198 /+pragma(inline, true) bool operator !=(QLatin1String lhs, QStringView rhs)/+ noexcept+/ { return !(lhs == rhs); }+/ 2199 /+pragma(inline, true) bool operator < (QLatin1String lhs, QStringView rhs)/+ noexcept+/ { 2200 import qt.core.stringalgorithms; 2201 return /+ QtPrivate:: +/qt.core.stringalgorithms.compareStrings(lhs, rhs) < 0; 2202 }+/ 2203 /+pragma(inline, true) bool operator <=(QLatin1String lhs, QStringView rhs)/+ noexcept+/ { 2204 import qt.core.stringalgorithms; 2205 return /+ QtPrivate:: +/qt.core.stringalgorithms.compareStrings(lhs, rhs) <= 0; 2206 }+/ 2207 /+pragma(inline, true) bool operator > (QLatin1String lhs, QStringView rhs)/+ noexcept+/ { 2208 import qt.core.stringalgorithms; 2209 return /+ QtPrivate:: +/qt.core.stringalgorithms.compareStrings(lhs, rhs) > 0; 2210 }+/ 2211 /+pragma(inline, true) bool operator >=(QLatin1String lhs, QStringView rhs)/+ noexcept+/ { 2212 import qt.core.stringalgorithms; 2213 return /+ QtPrivate:: +/qt.core.stringalgorithms.compareStrings(lhs, rhs) >= 0; 2214 }+/ 2215 2216 /+ #if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) 2217 // QStringRef <> QByteArray 2218 inline QT_ASCII_CAST_WARN bool operator==(const QStringRef &lhs, const QByteArray &rhs) { return lhs.compare(rhs) == 0; } 2219 inline QT_ASCII_CAST_WARN bool operator!=(const QStringRef &lhs, const QByteArray &rhs) { return lhs.compare(rhs) != 0; } 2220 inline QT_ASCII_CAST_WARN bool operator< (const QStringRef &lhs, const QByteArray &rhs) { return lhs.compare(rhs) < 0; } 2221 inline QT_ASCII_CAST_WARN bool operator> (const QStringRef &lhs, const QByteArray &rhs) { return lhs.compare(rhs) > 0; } 2222 inline QT_ASCII_CAST_WARN bool operator<=(const QStringRef &lhs, const QByteArray &rhs) { return lhs.compare(rhs) <= 0; } 2223 inline QT_ASCII_CAST_WARN bool operator>=(const QStringRef &lhs, const QByteArray &rhs) { return lhs.compare(rhs) >= 0; } 2224 2225 inline QT_ASCII_CAST_WARN bool operator==(const QByteArray &lhs, const QStringRef &rhs) { return rhs.compare(lhs) == 0; } 2226 inline QT_ASCII_CAST_WARN bool operator!=(const QByteArray &lhs, const QStringRef &rhs) { return rhs.compare(lhs) != 0; } 2227 inline QT_ASCII_CAST_WARN bool operator< (const QByteArray &lhs, const QStringRef &rhs) { return rhs.compare(lhs) > 0; } 2228 inline QT_ASCII_CAST_WARN bool operator> (const QByteArray &lhs, const QStringRef &rhs) { return rhs.compare(lhs) < 0; } 2229 inline QT_ASCII_CAST_WARN bool operator<=(const QByteArray &lhs, const QStringRef &rhs) { return rhs.compare(lhs) >= 0; } 2230 inline QT_ASCII_CAST_WARN bool operator>=(const QByteArray &lhs, const QStringRef &rhs) { return rhs.compare(lhs) <= 0; } 2231 2232 // QStringRef <> const char * 2233 inline QT_ASCII_CAST_WARN bool QStringRef::operator==(const char *s) const 2234 { return QString::compare_helper(constData(), size(), s, -1) == 0; } 2235 inline QT_ASCII_CAST_WARN bool QStringRef::operator!=(const char *s) const 2236 { return QString::compare_helper(constData(), size(), s, -1) != 0; } 2237 inline QT_ASCII_CAST_WARN bool QStringRef::operator<(const char *s) const 2238 { return QString::compare_helper(constData(), size(), s, -1) < 0; } 2239 inline QT_ASCII_CAST_WARN bool QStringRef::operator<=(const char *s) const 2240 { return QString::compare_helper(constData(), size(), s, -1) <= 0; } 2241 inline QT_ASCII_CAST_WARN bool QStringRef::operator>(const char *s) const 2242 { return QString::compare_helper(constData(), size(), s, -1) > 0; } 2243 inline QT_ASCII_CAST_WARN bool QStringRef::operator>=(const char *s) const 2244 { return QString::compare_helper(constData(), size(), s, -1) >= 0; } 2245 2246 inline QT_ASCII_CAST_WARN bool operator==(const char *s1, const QStringRef &s2) 2247 { return QString::compare_helper(s2.constData(), s2.size(), s1, -1) == 0; } 2248 inline QT_ASCII_CAST_WARN bool operator!=(const char *s1, const QStringRef &s2) 2249 { return QString::compare_helper(s2.constData(), s2.size(), s1, -1) != 0; } 2250 inline QT_ASCII_CAST_WARN bool operator<(const char *s1, const QStringRef &s2) 2251 { return QString::compare_helper(s2.constData(), s2.size(), s1, -1) > 0; } 2252 inline QT_ASCII_CAST_WARN bool operator<=(const char *s1, const QStringRef &s2) 2253 { return QString::compare_helper(s2.constData(), s2.size(), s1, -1) >= 0; } 2254 inline QT_ASCII_CAST_WARN bool operator>(const char *s1, const QStringRef &s2) 2255 { return QString::compare_helper(s2.constData(), s2.size(), s1, -1) < 0; } 2256 inline QT_ASCII_CAST_WARN bool operator>=(const char *s1, const QStringRef &s2) 2257 { return QString::compare_helper(s2.constData(), s2.size(), s1, -1) <= 0; } 2258 #endif // !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) 2259 2260 #if QT_STRINGVIEW_LEVEL < 2 2261 #endif +/ 2262 2263 version(QT_USE_FAST_OPERATOR_PLUS){}else 2264 version(QT_USE_QSTRINGBUILDER){}else 2265 { 2266 /+pragma(inline, true) QString operator +(ref const(QString) s1, ref const(QStringRef) s2) 2267 { QString t; t.reserve(s1.size() + s2.size()); t ~= s1; t ~= s2; return t; }+/ 2268 /+pragma(inline, true) QString operator +(ref const(QStringRef) s1, ref const(QString) s2) 2269 { QString t; t.reserve(s1.size() + s2.size()); t ~= s1; t ~= s2; return t; }+/ 2270 /+pragma(inline, true) QString operator +(ref const(QStringRef) s1, QLatin1String s2) 2271 { QString t; t.reserve(s1.size() + s2.size()); t ~= s1; t ~= s2; return t; }+/ 2272 /+pragma(inline, true) QString operator +(QLatin1String s1, ref const(QStringRef) s2) 2273 { QString t; t.reserve(s1.size() + s2.size()); t ~= s1; t ~= s2; return t; }+/ 2274 /+pragma(inline, true) QString operator +(ref const(QStringRef) s1, ref const(QStringRef) s2) 2275 { QString t; t.reserve(s1.size() + s2.size()); t ~= s1; t ~= s2; return t; }+/ 2276 /+pragma(inline, true) QString operator +(ref const(QStringRef) s1, QChar s2) 2277 { QString t; t.reserve(s1.size() + 1); t ~= s1; t ~= s2; return t; }+/ 2278 /+pragma(inline, true) QString operator +(QChar s1, ref const(QStringRef) s2) 2279 { QString t; t.reserve(1 + s2.size()); t ~= s1; t ~= s2; return t; }+/ 2280 } 2281 2282 /+ namespace Qt { 2283 #if QT_DEPRECATED_SINCE(5, 0) 2284 QT_DEPRECATED inline QString escape(const QString &plain) { 2285 return plain.toHtmlEscaped(); 2286 } 2287 #endif 2288 } +/ 2289 2290 extern(C++, "QtPrivate") { 2291 // used by qPrintable() and qUtf8Printable() macros 2292 // pragma(inline, true) ref const(QString) asString(ref const(QString) s) { return s; } 2293 /+ inline QString &&asString(QString &&s) { return std::move(s); } +/ 2294 } 2295 2296 // 2297 // QStringView::arg() implementation 2298 // 2299 2300 extern(C++, "QtPrivate") { 2301 2302 struct ArgBase { 2303 enum Tag : uchar { L1, U8, U16 }Tag tag; 2304 } 2305 2306 /+struct QStringViewArg { 2307 ArgBase base0; 2308 alias base0 this; 2309 QStringView string; 2310 /+ QStringViewArg() = default; +/ 2311 /+ explicit +/this(QStringView v)/+ noexcept+/ 2312 { 2313 this.base0 = ArgBase(ArgBase(Tag.U16)); 2314 this.string = typeof(this.string)(QStringView(v)); 2315 } 2316 }+/ 2317 2318 /+struct QLatin1StringArg { 2319 ArgBase base0; 2320 alias base0 this; 2321 QLatin1String string; 2322 /+ QLatin1StringArg() = default; +/ 2323 /+ explicit +/this(QLatin1String v)/+ noexcept+/ 2324 { 2325 this.base0 = ArgBase(ArgBase(Tag.L1)); 2326 this.string = typeof(this.string)(QLatin1String(v)); 2327 } 2328 }+/ 2329 2330 /+ Q_REQUIRED_RESULT +/ /+ Q_CORE_EXPORT +/ QString argToQString(QStringView pattern, size_t n, const(ArgBase)** args); 2331 /+ Q_REQUIRED_RESULT +/ /+ Q_CORE_EXPORT +/ QString argToQString(QLatin1String pattern, size_t n, const(ArgBase)** args); 2332 2333 /+ 2334 /+ Q_REQUIRED_RESULT +/ /+ Q_ALWAYS_INLINE +/ pragma(inline, true) QString argToQStringDispatch(StringView, Args)(StringView pattern, ref const(Args) args) 2335 { 2336 /+ const(ArgBase)*[0] +/ auto argBases = mixin(buildStaticArray!(q{const(ArgBase)*}, q{cast(const(ArgBase)*)(&args)..., /* avoid zero-sized array */ null})); 2337 return /+ QtPrivate:: +/argToQString(pattern, sizeof...(Args), argBases.ptr); 2338 }+/ 2339 2340 /+ 2341 pragma(inline, true) QStringViewArg qStringLikeToArg(ref const(QString) s)/+ noexcept+/ { return QStringViewArg{qToStringViewIgnoringNull(s)}; } 2342 pragma(inline, true) QStringViewArg qStringLikeToArg(QStringView s)/+ noexcept+/ { return QStringViewArg{s}; } 2343 pragma(inline, true) QStringViewArg qStringLikeToArg(ref const(QChar) c)/+ noexcept+/ { return QStringViewArg{QStringView{&c, 1}}; } 2344 pragma(inline, true) QLatin1StringArg qStringLikeToArg(QLatin1String s)/+ noexcept+/ { return QLatin1StringArg{s}; } 2345 +/ 2346 } // namespace QtPrivate 2347 2348 /+ template <typename...Args> 2349 Q_ALWAYS_INLINE 2350 QString QStringView::arg(Args &&...args) const 2351 { 2352 return QtPrivate::argToQStringDispatch(*this, QtPrivate::qStringLikeToArg(args)...); 2353 } 2354 2355 template <typename...Args> 2356 Q_ALWAYS_INLINE 2357 QString QLatin1String::arg(Args &&...args) const 2358 { 2359 return QtPrivate::argToQStringDispatch(*this, QtPrivate::qStringLikeToArg(args)...); 2360 } 2361 2362 2363 #if defined(QT_USE_FAST_OPERATOR_PLUS) || defined(QT_USE_QSTRINGBUILDER) 2364 #endif +/ 2365