1 | // Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz <marc.mutz@kdab.com> |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #include "qstringview.h" |
5 | |
6 | QT_BEGIN_NAMESPACE |
7 | |
8 | /*! |
9 | \class QStringView |
10 | \inmodule QtCore |
11 | \since 5.10 |
12 | \brief The QStringView class provides a unified view on UTF-16 strings with a read-only subset of the QString API. |
13 | \reentrant |
14 | \ingroup tools |
15 | \ingroup string-processing |
16 | |
17 | A QStringView references a contiguous portion of a UTF-16 string it does |
18 | not own. It acts as an interface type to all kinds of UTF-16 string, |
19 | without the need to construct a QString first. |
20 | |
21 | The UTF-16 string may be represented as an array (or an array-compatible |
22 | data-structure such as QString, |
23 | std::basic_string, etc.) of QChar, \c ushort, \c char16_t or |
24 | (on platforms, such as Windows, where it is a 16-bit type) \c wchar_t. |
25 | |
26 | QStringView is designed as an interface type; its main use-case is |
27 | as a function parameter type. When QStringViews are used as automatic |
28 | variables or data members, care must be taken to ensure that the referenced |
29 | string data (for example, owned by a QString) outlives the QStringView on all code paths, |
30 | lest the string view ends up referencing deleted data. |
31 | |
32 | When used as an interface type, QStringView allows a single function to accept |
33 | a wide variety of UTF-16 string data sources. One function accepting QStringView |
34 | thus replaces three function overloads (taking QString and |
35 | \c{(const QChar*, qsizetype)}), while at the same time enabling even more string data |
36 | sources to be passed to the function, such as \c{u"Hello World"}, a \c char16_t |
37 | string literal. |
38 | |
39 | QStringViews should be passed by value, not by reference-to-const: |
40 | \snippet code/src_corelib_text_qstringview.cpp 0 |
41 | |
42 | If you want to give your users maximum freedom in what strings they can pass |
43 | to your function, accompany the QStringView overload with overloads for |
44 | |
45 | \list |
46 | \li \e QChar: this overload can delegate to the QStringView version: |
47 | \snippet code/src_corelib_text_qstringview.cpp 1 |
48 | even though, for technical reasons, QStringView cannot provide a |
49 | QChar constructor by itself. |
50 | \li \e QString: if you store an unmodified copy of the string and thus would |
51 | like to take advantage of QString's implicit sharing. |
52 | \li QLatin1StringView: if you can implement the function without converting the |
53 | QLatin1StringView to UTF-16 first; users expect a function overloaded on |
54 | QLatin1StringView to perform strictly less memory allocations than the |
55 | semantically equivalent call of the QStringView version, involving |
56 | construction of a QString from the QLatin1StringView. |
57 | \endlist |
58 | |
59 | QStringView can also be used as the return value of a function. If you call a |
60 | function returning QStringView, take extra care to not keep the QStringView |
61 | around longer than the function promises to keep the referenced string data alive. |
62 | If in doubt, obtain a strong reference to the data by calling toString() to convert |
63 | the QStringView into a QString. |
64 | |
65 | QStringView is a \e{Literal Type}, but since it stores data as \c{char16_t}, iteration |
66 | is not \c constexpr (casts from \c{const char16_t*} to \c{const QChar*}, which is not |
67 | allowed in \c constexpr functions). You can use an indexed loop and/or utf16() in |
68 | \c constexpr contexts instead. |
69 | |
70 | \sa QString |
71 | */ |
72 | |
73 | /*! |
74 | \typedef QStringView::storage_type |
75 | |
76 | Alias for \c{char16_t}. |
77 | */ |
78 | |
79 | /*! |
80 | \typedef QStringView::value_type |
81 | |
82 | Alias for \c{const QChar}. Provided for compatibility with the STL. |
83 | */ |
84 | |
85 | /*! |
86 | \typedef QStringView::difference_type |
87 | |
88 | Alias for \c{std::ptrdiff_t}. Provided for compatibility with the STL. |
89 | */ |
90 | |
91 | /*! |
92 | \typedef QStringView::size_type |
93 | |
94 | Alias for qsizetype. Provided for compatibility with the STL. |
95 | */ |
96 | |
97 | /*! |
98 | \typedef QStringView::reference |
99 | |
100 | Alias for \c{value_type &}. Provided for compatibility with the STL. |
101 | |
102 | QStringView does not support mutable references, so this is the same |
103 | as const_reference. |
104 | */ |
105 | |
106 | /*! |
107 | \typedef QStringView::const_reference |
108 | |
109 | Alias for \c{value_type &}. Provided for compatibility with the STL. |
110 | */ |
111 | |
112 | /*! |
113 | \typedef QStringView::pointer |
114 | |
115 | Alias for \c{value_type *}. Provided for compatibility with the STL. |
116 | |
117 | QStringView does not support mutable pointers, so this is the same |
118 | as const_pointer. |
119 | */ |
120 | |
121 | /*! |
122 | \typedef QStringView::const_pointer |
123 | |
124 | Alias for \c{value_type *}. Provided for compatibility with the STL. |
125 | */ |
126 | |
127 | /*! |
128 | \typedef QStringView::iterator |
129 | |
130 | This typedef provides an STL-style const iterator for QStringView. |
131 | |
132 | QStringView does not support mutable iterators, so this is the same |
133 | as const_iterator. |
134 | |
135 | \sa const_iterator, reverse_iterator |
136 | */ |
137 | |
138 | /*! |
139 | \typedef QStringView::const_iterator |
140 | |
141 | This typedef provides an STL-style const iterator for QStringView. |
142 | |
143 | \sa iterator, const_reverse_iterator |
144 | */ |
145 | |
146 | /*! |
147 | \typedef QStringView::reverse_iterator |
148 | |
149 | This typedef provides an STL-style const reverse iterator for QStringView. |
150 | |
151 | QStringView does not support mutable reverse iterators, so this is the |
152 | same as const_reverse_iterator. |
153 | |
154 | \sa const_reverse_iterator, iterator |
155 | */ |
156 | |
157 | /*! |
158 | \typedef QStringView::const_reverse_iterator |
159 | |
160 | This typedef provides an STL-style const reverse iterator for QStringView. |
161 | |
162 | \sa reverse_iterator, const_iterator |
163 | */ |
164 | |
165 | /*! |
166 | \fn size_t qHash(QStringView key, size_t seed) |
167 | \since 5.10 |
168 | \qhashold{QStringView} |
169 | */ |
170 | |
171 | /*! |
172 | \fn QStringView::QStringView() |
173 | |
174 | Constructs a null string view. |
175 | |
176 | \sa isNull() |
177 | */ |
178 | |
179 | /*! |
180 | \fn QStringView::QStringView(std::nullptr_t) |
181 | |
182 | Constructs a null string view. |
183 | |
184 | \sa isNull() |
185 | */ |
186 | |
187 | /*! |
188 | \fn template <typename Char, QStringView::if_compatible_char<Char> = true> QStringView::QStringView(const Char *str, qsizetype len) |
189 | |
190 | Constructs a string view on \a str with length \a len. |
191 | |
192 | The range \c{[str,len)} must remain valid for the lifetime of this string view object. |
193 | |
194 | Passing \nullptr as \a str is safe if \a len is 0, too, and results in a null string view. |
195 | |
196 | The behavior is undefined if \a len is negative or, when positive, if \a str is \nullptr. |
197 | |
198 | //! [compatible-char-types] |
199 | This constructor only participates in overload resolution if \c Char is a compatible |
200 | character type. The compatible character types are: \c QChar, \c ushort, \c char16_t and |
201 | (on platforms, such as Windows, where it is a 16-bit type) \c wchar_t. |
202 | //! [compatible-char-types] |
203 | */ |
204 | |
205 | /*! |
206 | \fn template <typename Char, QStringView::if_compatible_char<Char> = true> QStringView::QStringView(const Char *first, const Char *last) |
207 | |
208 | Constructs a string view on \a first with length (\a last - \a first). |
209 | |
210 | The range \c{[first,last)} must remain valid for the lifetime of |
211 | this string view object. |
212 | |
213 | Passing \c \nullptr as \a first is safe if \a last is \nullptr, too, |
214 | and results in a null string view. |
215 | |
216 | The behavior is undefined if \a last precedes \a first, or \a first |
217 | is \nullptr and \a last is not. |
218 | |
219 | \include qstringview.cpp compatible-char-types |
220 | */ |
221 | |
222 | /*! |
223 | \fn template <typename Char> QStringView::QStringView(const Char *str) |
224 | |
225 | Constructs a string view on \a str. The length is determined |
226 | by scanning for the first \c{Char(0)}. |
227 | |
228 | \a str must remain valid for the lifetime of this string view object. |
229 | |
230 | Passing \nullptr as \a str is safe and results in a null string view. |
231 | |
232 | \include qstringview.cpp compatible-char-types |
233 | */ |
234 | |
235 | /*! |
236 | \fn template <typename Char, size_t N> QStringView::QStringView(const Char (&string)[N]) |
237 | |
238 | Constructs a string view on the character string literal \a string. |
239 | The view covers the array until the first \c{Char(0)} is encountered, |
240 | or \c N, whichever comes first. |
241 | If you need the full array, use fromArray() instead. |
242 | |
243 | \a string must remain valid for the lifetime of this string view |
244 | object. |
245 | |
246 | \include qstringview.cpp compatible-char-types |
247 | |
248 | \sa fromArray |
249 | */ |
250 | |
251 | /*! |
252 | \fn QStringView::QStringView(const QString &str) |
253 | |
254 | Constructs a string view on \a str. |
255 | |
256 | \c{str.data()} must remain valid for the lifetime of this string view object. |
257 | |
258 | The string view will be null if and only if \c{str.isNull()}. |
259 | */ |
260 | |
261 | /*! |
262 | \fn template <typename Container, QStringView::if_compatible_container<Container>> QStringView::QStringView(const Container &str) |
263 | |
264 | Constructs a string view on \a str. The length is taken from \c{std::size(str)}. |
265 | |
266 | \c{std::data(str)} must remain valid for the lifetime of this string view object. |
267 | |
268 | This constructor only participates in overload resolution if \c Container is a |
269 | container with a compatible character type as \c{value_type}. The |
270 | compatible character types are: \c QChar, \c ushort, \c char16_t and |
271 | (on platforms, such as Windows, where it is a 16-bit type) \c wchar_t. |
272 | |
273 | The string view will be empty if and only if \c{std::size(str) == 0}. It is unspecified |
274 | whether this constructor can result in a null string view (\c{std::data(str)} would |
275 | have to return \nullptr for this). |
276 | |
277 | \sa isNull(), isEmpty() |
278 | */ |
279 | |
280 | /*! |
281 | \fn template <typename Char, size_t Size, QStringView::if_compatible_char<Char> = true> static QStringView QStringView::fromArray(const Char (&string)[Size]) noexcept |
282 | |
283 | Constructs a string view on the full character string literal \a string, |
284 | including any trailing \c{Char(0)}. If you don't want the |
285 | null-terminator included in the view then you can chop() it off |
286 | when you are certain it is at the end. Alternatively you can use |
287 | the constructor overload taking an array literal which will create |
288 | a view up to, but not including, the first null-terminator in the data. |
289 | |
290 | \a string must remain valid for the lifetime of this string view |
291 | object. |
292 | |
293 | This function will work with any array literal if \c Char is a |
294 | compatible character type. The compatible character types are: \c QChar, \c ushort, \c |
295 | char16_t and (on platforms, such as Windows, where it is a 16-bit |
296 | type) \c wchar_t. |
297 | */ |
298 | |
299 | /*! |
300 | \fn QString QStringView::toString() const |
301 | |
302 | Returns a deep copy of this string view's data as a QString. |
303 | |
304 | The return value will be the null QString if and only if this string view is null. |
305 | */ |
306 | |
307 | /*! |
308 | \fn const QChar *QStringView::data() const |
309 | |
310 | //! [const-pointer-to-first-ch] |
311 | Returns a const pointer to the first character in the string view. |
312 | |
313 | \note The character array represented by the return value is \e not null-terminated. |
314 | //! [const-pointer-to-first-ch] |
315 | |
316 | \sa begin(), end(), utf16() |
317 | */ |
318 | |
319 | /*! |
320 | \fn const QChar *QStringView::constData() const |
321 | \since 6.0 |
322 | |
323 | \include qstringview.cpp const-pointer-to-first-ch |
324 | |
325 | \sa data(), begin(), end(), utf16() |
326 | */ |
327 | |
328 | /*! |
329 | \fn const storage_type *QStringView::utf16() const |
330 | |
331 | \include qstringview.cpp const-pointer-to-first-ch |
332 | |
333 | \c{storage_type} is \c{char16_t}. |
334 | |
335 | \sa begin(), end(), data() |
336 | */ |
337 | |
338 | /*! |
339 | \fn QStringView::const_iterator QStringView::begin() const |
340 | |
341 | Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first character in |
342 | the string view. |
343 | |
344 | This function is provided for STL compatibility. |
345 | |
346 | \sa end(), constBegin(), cbegin(), rbegin(), data() |
347 | */ |
348 | |
349 | /*! |
350 | \fn QStringView::const_iterator QStringView::cbegin() const |
351 | |
352 | Same as begin(). |
353 | |
354 | This function is provided for STL compatibility. |
355 | |
356 | \sa cend(), begin(), constBegin(), crbegin(), data() |
357 | */ |
358 | |
359 | /*! |
360 | \fn QStringView::const_iterator QStringView::constBegin() const |
361 | \since 6.1 |
362 | |
363 | Same as begin(). |
364 | |
365 | \sa constEnd(), begin(), cbegin(), crbegin(), data() |
366 | */ |
367 | |
368 | /*! |
369 | \fn QStringView::const_iterator QStringView::end() const |
370 | |
371 | Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary |
372 | character after the last character in the list. |
373 | |
374 | This function is provided for STL compatibility. |
375 | |
376 | \sa begin(), constEnd(), cend(), rend() |
377 | */ |
378 | |
379 | /*! \fn QStringView::const_iterator QStringView::cend() const |
380 | |
381 | Same as end(). |
382 | |
383 | This function is provided for STL compatibility. |
384 | |
385 | \sa cbegin(), end(), constEnd(), crend() |
386 | */ |
387 | |
388 | /*! \fn QStringView::const_iterator QStringView::constEnd() const |
389 | \since 6.1 |
390 | |
391 | Same as end(). |
392 | |
393 | \sa constBegin(), end(), cend(), crend() |
394 | */ |
395 | |
396 | /*! |
397 | \fn QStringView::const_reverse_iterator QStringView::rbegin() const |
398 | |
399 | Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing to the first |
400 | character in the string view, in reverse order. |
401 | |
402 | This function is provided for STL compatibility. |
403 | |
404 | \sa rend(), crbegin(), begin() |
405 | */ |
406 | |
407 | /*! |
408 | \fn QStringView::const_reverse_iterator QStringView::crbegin() const |
409 | |
410 | Same as rbegin(). |
411 | |
412 | This function is provided for STL compatibility. |
413 | |
414 | \sa crend(), rbegin(), cbegin() |
415 | */ |
416 | |
417 | /*! |
418 | \fn QStringView::const_reverse_iterator QStringView::rend() const |
419 | |
420 | Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to one past |
421 | the last character in the string view, in reverse order. |
422 | |
423 | This function is provided for STL compatibility. |
424 | |
425 | \sa rbegin(), crend(), end() |
426 | */ |
427 | |
428 | /*! |
429 | \fn QStringView::const_reverse_iterator QStringView::crend() const |
430 | |
431 | Same as rend(). |
432 | |
433 | This function is provided for STL compatibility. |
434 | |
435 | \sa crbegin(), rend(), cend() |
436 | */ |
437 | |
438 | /*! |
439 | \fn bool QStringView::empty() const |
440 | |
441 | Returns whether this string view is empty - that is, whether \c{size() == 0}. |
442 | |
443 | This function is provided for STL compatibility. |
444 | |
445 | \sa isEmpty(), isNull(), size(), length() |
446 | */ |
447 | |
448 | /*! |
449 | \fn bool QStringView::isEmpty() const |
450 | |
451 | Returns whether this string view is empty - that is, whether \c{size() == 0}. |
452 | |
453 | This function is provided for compatibility with other Qt containers. |
454 | |
455 | \sa empty(), isNull(), size(), length() |
456 | */ |
457 | |
458 | /*! |
459 | \fn bool QStringView::isNull() const |
460 | |
461 | Returns whether this string view is null - that is, whether \c{data() == nullptr}. |
462 | |
463 | This functions is provided for compatibility with other Qt containers. |
464 | |
465 | \sa empty(), isEmpty(), size(), length() |
466 | */ |
467 | |
468 | /*! |
469 | \fn qsizetype QStringView::size() const |
470 | |
471 | Returns the size of this string view, in UTF-16 code units (that is, |
472 | surrogate pairs count as two for the purposes of this function, the same |
473 | as in QString). |
474 | |
475 | \sa empty(), isEmpty(), isNull(), length() |
476 | */ |
477 | |
478 | /*! |
479 | \fn QStringView::length() const |
480 | |
481 | Same as size(). |
482 | |
483 | This function is provided for compatibility with other Qt containers. |
484 | |
485 | \sa empty(), isEmpty(), isNull(), size() |
486 | */ |
487 | |
488 | /*! |
489 | \fn QChar QStringView::operator[](qsizetype n) const |
490 | |
491 | Returns the character at position \a n in this string view. |
492 | |
493 | The behavior is undefined if \a n is negative or not less than size(). |
494 | |
495 | \sa at(), front(), back() |
496 | */ |
497 | |
498 | /*! |
499 | \fn QChar QStringView::at(qsizetype n) const |
500 | |
501 | Returns the character at position \a n in this string view. |
502 | |
503 | The behavior is undefined if \a n is negative or not less than size(). |
504 | |
505 | \sa operator[](), front(), back() |
506 | */ |
507 | |
508 | /*! |
509 | \fn template <typename...Args> QString QStringView::arg(Args &&...args) const |
510 | \fn template <typename...Args> QString QLatin1StringView::arg(Args &&...args) const |
511 | \fn template <typename...Args> QString QString::arg(Args &&...args) const |
512 | \since 5.14 |
513 | |
514 | Replaces occurrences of \c{%N} in this string with the corresponding |
515 | argument from \a args. The arguments are not positional: the first of |
516 | the \a args replaces the \c{%N} with the lowest \c{N} (all of them), the |
517 | second of the \a args the \c{%N} with the next-lowest \c{N} etc. |
518 | |
519 | \c Args can consist of anything that implicitly converts to QString, |
520 | QStringView or QLatin1StringView. |
521 | |
522 | In addition, the following types are also supported: QChar, QLatin1Char. |
523 | |
524 | \sa QString::arg() |
525 | */ |
526 | |
527 | /*! |
528 | \fn QChar QStringView::front() const |
529 | |
530 | Returns the first character in the string view. Same as first(). |
531 | |
532 | This function is provided for STL compatibility. |
533 | |
534 | //! [calling-on-empty-is-UB] |
535 | \warning Calling this function on an empty string view constitutes |
536 | undefined behavior. |
537 | //! [calling-on-empty-is-UB] |
538 | |
539 | \sa back(), first(), last() |
540 | */ |
541 | |
542 | /*! |
543 | \fn QChar QStringView::back() const |
544 | |
545 | Returns the last character in the string view. Same as last(). |
546 | |
547 | This function is provided for STL compatibility. |
548 | |
549 | \include qstringview.cpp calling-on-empty-is-UB |
550 | |
551 | \sa front(), first(), last() |
552 | */ |
553 | |
554 | /*! |
555 | \fn QChar QStringView::first() const |
556 | |
557 | Returns the first character in the string view. Same as front(). |
558 | |
559 | This function is provided for compatibility with other Qt containers. |
560 | |
561 | \include qstringview.cpp calling-on-empty-is-UB |
562 | |
563 | \sa front(), back(), last() |
564 | */ |
565 | |
566 | /*! |
567 | \fn QChar QStringView::last() const |
568 | |
569 | Returns the last character in the string view. Same as back(). |
570 | |
571 | This function is provided for compatibility with other Qt containers. |
572 | |
573 | \include qstringview.cpp calling-on-empty-is-UB |
574 | |
575 | \sa back(), front(), first() |
576 | */ |
577 | |
578 | /*! |
579 | \fn QStringView QStringView::mid(qsizetype start, qsizetype length) const |
580 | |
581 | Returns the substring of length \a length starting at position |
582 | \a start in this object. |
583 | |
584 | \deprecated Use sliced() instead in new code. |
585 | |
586 | Returns an empty string view if \a start exceeds the |
587 | length of the string view. If there are less than \a length characters |
588 | available in the string view starting at \a start, or if |
589 | \a length is negative (default), the function returns all characters that |
590 | are available from \a start. |
591 | |
592 | \sa first(), last(), sliced(), chopped(), chop(), truncate(), slice() |
593 | */ |
594 | |
595 | /*! |
596 | \fn QStringView QStringView::left(qsizetype length) const |
597 | |
598 | \deprecated Use first() instead in new code. |
599 | |
600 | Returns the substring of length \a length starting at position |
601 | 0 in this object. |
602 | |
603 | The entire string view is returned if \a length is greater than or equal |
604 | to size(), or less than zero. |
605 | |
606 | \sa first(), last(), sliced(), startsWith(), chopped(), chop(), truncate(), slice() |
607 | */ |
608 | |
609 | /*! |
610 | \fn QStringView QStringView::right(qsizetype length) const |
611 | |
612 | \deprecated Use last() instead in new code. |
613 | |
614 | Returns the substring of length \a length starting at position |
615 | size() - \a length in this object. |
616 | |
617 | The entire string view is returned if \a length is greater than or equal |
618 | to size(), or less than zero. |
619 | |
620 | \sa first(), last(), sliced(), endsWith(), chopped(), chop(), truncate(), slice() |
621 | */ |
622 | |
623 | /*! |
624 | \fn QStringView QStringView::first(qsizetype n) const |
625 | \since 6.0 |
626 | |
627 | Returns a string view that points to the first \a n characters |
628 | of this string view. |
629 | |
630 | \note The behavior is undefined when \a n < 0 or \a n > size(). |
631 | |
632 | \sa last(), sliced(), startsWith(), chopped(), chop(), truncate(), slice() |
633 | */ |
634 | |
635 | /*! |
636 | \fn QStringView QStringView::last(qsizetype n) const |
637 | \since 6.0 |
638 | |
639 | Returns a string view that points to the last \a n characters of this string |
640 | view. |
641 | |
642 | \note The behavior is undefined when \a n < 0 or \a n > size(). |
643 | |
644 | \sa first(), sliced(), endsWith(), chopped(), chop(), truncate(), slice() |
645 | */ |
646 | |
647 | /*! |
648 | \fn QStringView QStringView::sliced(qsizetype pos, qsizetype n) const |
649 | \since 6.0 |
650 | |
651 | Returns a string view that points to \a n characters of this string view, |
652 | starting at position \a pos. |
653 | |
654 | //! [UB-sliced-index-length] |
655 | \note The behavior is undefined when \a pos < 0, \a n < 0, |
656 | or \a pos + \a n > size(). |
657 | //! [UB-sliced-index-length] |
658 | |
659 | \sa first(), last(), chopped(), chop(), truncate(), slice() |
660 | */ |
661 | |
662 | /*! |
663 | \fn QStringView QStringView::sliced(qsizetype pos) const |
664 | \since 6.0 |
665 | \overload |
666 | |
667 | Returns a string view starting at position \a pos in this object, |
668 | and extending to its end. |
669 | |
670 | //! [UB-sliced-index-only] |
671 | \note The behavior is undefined when \a pos < 0 or \a pos > size(). |
672 | //! [UB-sliced-index-only] |
673 | |
674 | \sa first(), last(), chopped(), chop(), truncate(), slice() |
675 | */ |
676 | |
677 | /*! |
678 | \fn QStringView &QStringView::slice(qsizetype pos, qsizetype n) |
679 | \since 6.8 |
680 | |
681 | Modifies this string view to start from position \a pos, extending |
682 | for \a n code points. |
683 | |
684 | \include qstringview.cpp UB-sliced-index-length |
685 | |
686 | \sa sliced(), first(), last(), chopped(), chop(), truncate() |
687 | */ |
688 | |
689 | /*! |
690 | \fn QStringView &QStringView::slice(qsizetype pos) |
691 | \since 6.8 |
692 | \overload |
693 | |
694 | Modifies this string view to start from position \a pos, extending |
695 | to its end. |
696 | |
697 | \include qstringview.cpp UB-sliced-index-only |
698 | |
699 | \sa sliced(), first(), last(), chopped(), chop(), truncate() |
700 | */ |
701 | |
702 | /*! |
703 | \fn QStringView QStringView::chopped(qsizetype length) const |
704 | |
705 | Returns the substring of length size() - \a length starting at the |
706 | beginning of this object. |
707 | |
708 | Same as \c{left(size() - length)}. |
709 | |
710 | \note The behavior is undefined when \a length < 0 or \a length > size(). |
711 | |
712 | \sa mid(), left(), right(), chop(), truncate(), slice() |
713 | */ |
714 | |
715 | /*! |
716 | \fn void QStringView::truncate(qsizetype length) |
717 | |
718 | Truncates this string view to length \a length. |
719 | |
720 | Same as \c{*this = left(length)}. |
721 | |
722 | \note The behavior is undefined when \a length < 0 or \a length > size(). |
723 | |
724 | \sa mid(), left(), right(), chopped(), chop() |
725 | */ |
726 | |
727 | /*! |
728 | \fn void QStringView::chop(qsizetype length) |
729 | |
730 | Truncates this string view by \a length characters. |
731 | |
732 | Same as \c{*this = left(size() - length)}. |
733 | |
734 | \note The behavior is undefined when \a length < 0 or \a length > size(). |
735 | |
736 | \sa mid(), left(), right(), chopped(), truncate(), slice() |
737 | */ |
738 | |
739 | /*! |
740 | \fn QStringView QStringView::trimmed() const |
741 | |
742 | Strips leading and trailing whitespace and returns the result. |
743 | |
744 | Whitespace means any character for which QChar::isSpace() returns |
745 | \c true. This includes the ASCII characters '\\t', '\\n', '\\v', |
746 | '\\f', '\\r', and ' '. |
747 | */ |
748 | |
749 | /*! |
750 | \fn int QStringView::compare(QStringView str, Qt::CaseSensitivity cs) const |
751 | \since 5.12 |
752 | |
753 | Compares this string view with string view \a str and returns a negative integer if |
754 | this string view is less than \a str, a positive integer if it is greater than |
755 | \a str, and zero if they are equal. |
756 | |
757 | \include qstring.qdocinc {search-comparison-case-sensitivity} {comparison} |
758 | |
759 | \sa operator==(), operator<(), operator>() |
760 | */ |
761 | |
762 | /*! |
763 | \fn int QStringView::compare(QUtf8StringView str, Qt::CaseSensitivity cs) const |
764 | \since 6.5 |
765 | |
766 | Compares this string view with QUtf8StringView \a str and returns a negative integer if |
767 | this string view is less than \a str, a positive integer if it is greater than |
768 | \a str, and zero if they are equal. |
769 | |
770 | \include qstring.qdocinc {search-comparison-case-sensitivity} {comparison} |
771 | |
772 | \sa operator==(), operator<(), operator>() |
773 | */ |
774 | |
775 | /*! |
776 | \fn int QStringView::compare(QLatin1StringView l1, Qt::CaseSensitivity cs) const |
777 | \fn int QStringView::compare(QChar ch) const |
778 | \fn int QStringView::compare(QChar ch, Qt::CaseSensitivity cs) const |
779 | \since 5.15 |
780 | |
781 | Compares this string view to the Latin-1 string view \a l1, or the character \a ch. |
782 | Returns a negative integer if this string view is less than \a l1 or \a ch, |
783 | a positive integer if it is greater than \a l1 or \a ch, and zero if they are equal. |
784 | |
785 | \include qstring.qdocinc {search-comparison-case-sensitivity} {comparison} |
786 | |
787 | \sa operator==(), operator<(), operator>() |
788 | */ |
789 | |
790 | /*! |
791 | \fn QStringView::operator==(const QStringView &lhs, const QStringView &rhs) |
792 | \fn QStringView::operator!=(const QStringView &lhs, const QStringView &rhs) |
793 | \fn QStringView::operator< (const QStringView &lhs, const QStringView &rhs) |
794 | \fn QStringView::operator<=(const QStringView &lhs, const QStringView &rhs) |
795 | \fn QStringView::operator> (const QStringView &lhs, const QStringView &rhs) |
796 | \fn QStringView::operator>=(const QStringView &lhs, const QStringView &rhs) |
797 | |
798 | Operators for comparing \a lhs to \a rhs. |
799 | |
800 | \sa compare() |
801 | */ |
802 | |
803 | /*! |
804 | \fn int QStringView::localeAwareCompare(QStringView other) const |
805 | \since 6.4 |
806 | |
807 | Compares this string view with the \a other string view and returns |
808 | an integer less than, equal to, or greater than zero if this string |
809 | view is less than, equal to, or greater than the \a other string view. |
810 | |
811 | The comparison is performed in a locale- and also platform-dependent |
812 | manner. Use this function to present sorted lists of strings to the |
813 | user. |
814 | |
815 | \sa {Comparing Strings} |
816 | */ |
817 | |
818 | /* |
819 | //! [utf16-or-latin1-or-ch] |
820 | the UTF-16 string viewed by \a str, the Latin-1 string viewed by \a l1, |
821 | or the character \a ch |
822 | //! [utf16-or-latin1-or-ch] |
823 | */ |
824 | |
825 | /*! |
826 | \fn bool QStringView::startsWith(QStringView str, Qt::CaseSensitivity cs) const |
827 | \fn bool QStringView::startsWith(QLatin1StringView l1, Qt::CaseSensitivity cs) const |
828 | \fn bool QStringView::startsWith(QChar ch) const |
829 | \fn bool QStringView::startsWith(QChar ch, Qt::CaseSensitivity cs) const |
830 | |
831 | Returns \c true if this string view starts with |
832 | \include qstringview.cpp utf16-or-latin1-or-ch |
833 | respectively; otherwise returns \c false. |
834 | |
835 | \include qstring.qdocinc {search-comparison-case-sensitivity} {search} |
836 | |
837 | \sa endsWith() |
838 | */ |
839 | |
840 | /*! |
841 | \fn bool QStringView::endsWith(QStringView str, Qt::CaseSensitivity cs) const |
842 | \fn bool QStringView::endsWith(QLatin1StringView l1, Qt::CaseSensitivity cs) const |
843 | \fn bool QStringView::endsWith(QChar ch) const |
844 | \fn bool QStringView::endsWith(QChar ch, Qt::CaseSensitivity cs) const |
845 | |
846 | Returns \c true if this string view ends with |
847 | \include qstringview.cpp utf16-or-latin1-or-ch |
848 | respectively; otherwise returns \c false. |
849 | |
850 | \include qstring.qdocinc {search-comparison-case-sensitivity} {search} |
851 | |
852 | \sa startsWith() |
853 | */ |
854 | |
855 | /*! |
856 | \fn qsizetype QStringView::indexOf(QStringView str, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
857 | \fn qsizetype QStringView::indexOf(QLatin1StringView l1, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
858 | \fn qsizetype QStringView::indexOf(QChar c, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
859 | \since 5.14 |
860 | |
861 | Returns the index position of the first occurrence of |
862 | \include qstringview.cpp utf16-or-latin1-or-ch |
863 | respectively, in this string view, searching forward from index position |
864 | \a from. Returns -1 if \a str, \a l1 or \a ch is not found, respectively. |
865 | |
866 | \include qstring.qdocinc {search-comparison-case-sensitivity} {search} |
867 | |
868 | \include qstring.qdocinc negative-index-start-search-from-end |
869 | |
870 | \sa QString::indexOf() |
871 | */ |
872 | |
873 | /*! |
874 | \fn bool QStringView::contains(QStringView str, Qt::CaseSensitivity cs) const |
875 | \fn bool QStringView::contains(QLatin1StringView l1, Qt::CaseSensitivity cs) const |
876 | \fn bool QStringView::contains(QChar c, Qt::CaseSensitivity cs) const |
877 | \since 5.14 |
878 | |
879 | Returns \c true if this string view contains an occurrence of |
880 | \include qstringview.cpp utf16-or-latin1-or-ch |
881 | respectively; otherwise returns \c false. |
882 | |
883 | \include qstring.qdocinc {search-comparison-case-sensitivity} {search} |
884 | |
885 | \sa indexOf() |
886 | */ |
887 | |
888 | /*! |
889 | \fn qsizetype QStringView::lastIndexOf(QStringView str, qsizetype from, Qt::CaseSensitivity cs) const |
890 | \fn qsizetype QStringView::lastIndexOf(QLatin1StringView l1, qsizetype from, Qt::CaseSensitivity cs) const |
891 | \fn qsizetype QStringView::lastIndexOf(QChar c, qsizetype from, Qt::CaseSensitivity cs) const |
892 | \since 5.14 |
893 | |
894 | Returns the index position of the last occurrence of |
895 | \include qstringview.cpp utf16-or-latin1-or-ch |
896 | respectively, in this string view, searching backward from index |
897 | position \a from. |
898 | |
899 | \include qstring.qdocinc negative-index-start-search-from-end |
900 | |
901 | Returns -1 if \a str, \a l1 or \a c is not found, respectively. |
902 | |
903 | \include qstring.qdocinc {search-comparison-case-sensitivity} {search} |
904 | |
905 | \note When searching for a 0-length \a str or \a l1, the match at |
906 | the end of the data is excluded from the search by a negative \a |
907 | from, even though \c{-1} is normally thought of as searching from |
908 | the end of the string view: the match at the end is \e after the |
909 | last character, so it is excluded. To include such a final empty |
910 | match, either give a positive value for \a from or omit the \a from |
911 | parameter entirely. |
912 | |
913 | \sa QString::lastIndexOf() |
914 | */ |
915 | |
916 | /*! |
917 | \fn qsizetype QStringView::lastIndexOf(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
918 | \fn qsizetype QStringView::lastIndexOf(QLatin1StringView l1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
919 | \since 6.2 |
920 | \overload lastIndexOf() |
921 | |
922 | Returns the index position of the last occurrence of the UTF-16 string viewed |
923 | by \a str or the Latin-1 string viewed by \a l1 respectively, in this string |
924 | view searching backward from the last character of this string view. Returns |
925 | -1 if \a str or \a l1 is not found, respectively. |
926 | |
927 | \include qstring.qdocinc {search-comparison-case-sensitivity} {search} |
928 | |
929 | \sa QString::lastIndexOf() |
930 | */ |
931 | |
932 | /*! |
933 | \fn QStringView::lastIndexOf(QChar c, Qt::CaseSensitivity cs) const |
934 | \since 6.3 |
935 | \overload lastIndexOf() |
936 | */ |
937 | |
938 | #if QT_CONFIG(regularexpression) |
939 | /*! |
940 | \fn qsizetype QStringView::indexOf(const QRegularExpression &re, qsizetype from, QRegularExpressionMatch *rmatch) const |
941 | \since 6.1 |
942 | |
943 | Returns the index position of the first match of the regular |
944 | expression \a re in the string view, searching forward from index |
945 | position \a from. Returns -1 if \a re didn't match anywhere. |
946 | |
947 | If the match is successful and \a rmatch is not \nullptr, it also |
948 | writes the results of the match into the QRegularExpressionMatch object |
949 | pointed to by \a rmatch. |
950 | |
951 | \note Due to how the regular expression matching algorithm works, |
952 | this function will actually match repeatedly from the beginning of |
953 | the string view until the position \a from is reached. |
954 | */ |
955 | |
956 | /*! |
957 | \fn qsizetype QStringView::lastIndexOf(const QRegularExpression &re, qsizetype from, QRegularExpressionMatch *rmatch) const |
958 | \since 6.1 |
959 | |
960 | Returns the index position of the last match of the regular |
961 | expression \a re in the string view, which starts before the index |
962 | position \a from. |
963 | |
964 | \include qstring.qdocinc negative-index-start-search-from-end |
965 | |
966 | Returns -1 if \a re didn't match anywhere. |
967 | |
968 | If the match is successful and \a rmatch is not \nullptr, it also |
969 | writes the results of the match into the QRegularExpressionMatch object |
970 | pointed to by \a rmatch. |
971 | |
972 | \note Due to how the regular expression matching algorithm works, |
973 | this function will actually match repeatedly from the beginning of |
974 | the string view until the position \a from is reached. |
975 | |
976 | \note When searching for a regular expression \a re that may match |
977 | 0 characters, the match at the end of the data is excluded from the |
978 | search by a negative \a from, even though \c{-1} is normally |
979 | thought of as searching from the end of the string view: the match |
980 | at the end is \e after the last character, so it is excluded. To |
981 | include such a final empty match, either give a positive value for |
982 | \a from or omit the \a from parameter entirely. |
983 | */ |
984 | |
985 | /*! |
986 | \fn qsizetype QStringView::lastIndexOf(const QRegularExpression &re, QRegularExpressionMatch *rmatch = nullptr) const |
987 | \since 6.2 |
988 | |
989 | Returns the index position of the last match of the regular |
990 | expression \a re in the string view. Returns -1 if \a re didn't match |
991 | anywhere. |
992 | |
993 | If the match is successful and \a rmatch is not \nullptr, it also |
994 | writes the results of the match into the QRegularExpressionMatch object |
995 | pointed to by \a rmatch. |
996 | |
997 | \note Due to how the regular expression matching algorithm works, |
998 | this function will actually match repeatedly from the beginning of |
999 | the string view until the end of the string view is reached. |
1000 | */ |
1001 | |
1002 | /*! |
1003 | \fn bool QStringView::contains(const QRegularExpression &re, QRegularExpressionMatch *rmatch) const |
1004 | \since 6.1 |
1005 | |
1006 | Returns \c true if the regular expression \a re matches somewhere in this |
1007 | string view; otherwise returns \c false. |
1008 | |
1009 | If the match is successful and \a rmatch is not \nullptr, it also |
1010 | writes the results of the match into the QRegularExpressionMatch object |
1011 | pointed to by \a rmatch. |
1012 | |
1013 | \sa QRegularExpression::match() |
1014 | */ |
1015 | |
1016 | /*! |
1017 | \fn qsizetype QStringView::count(const QRegularExpression &re) const |
1018 | \since 6.1 |
1019 | |
1020 | Returns the number of times the regular expression \a re matches |
1021 | in the string view. |
1022 | |
1023 | For historical reasons, this function counts overlapping matches. |
1024 | This behavior is different from simply iterating over the matches |
1025 | in the string view using QRegularExpressionMatchIterator. |
1026 | |
1027 | \sa QRegularExpression::globalMatch() |
1028 | |
1029 | */ |
1030 | #endif // QT_CONFIG(regularexpression) |
1031 | |
1032 | /*! |
1033 | \fn QByteArray QStringView::toLatin1() const |
1034 | |
1035 | Returns a Latin-1 representation of the string as a QByteArray. |
1036 | |
1037 | The behavior is undefined if the string contains non-Latin1 characters. |
1038 | |
1039 | \sa toUtf8(), toLocal8Bit(), QStringEncoder |
1040 | */ |
1041 | |
1042 | /*! |
1043 | \fn QByteArray QStringView::toLocal8Bit() const |
1044 | |
1045 | Returns a local 8-bit representation of the string as a QByteArray. |
1046 | |
1047 | On Unix systems this is equivalen to toUtf8(), on Windows the systems |
1048 | current code page is being used. |
1049 | |
1050 | The behavior is undefined if the string contains characters not |
1051 | supported by the locale's 8-bit encoding. |
1052 | |
1053 | \sa toLatin1(), toUtf8(), QStringEncoder |
1054 | */ |
1055 | |
1056 | /*! |
1057 | \fn QByteArray QStringView::toUtf8() const |
1058 | |
1059 | Returns a UTF-8 representation of the string view as a QByteArray. |
1060 | |
1061 | UTF-8 is a Unicode codec and can represent all characters in a Unicode |
1062 | string like QString. |
1063 | |
1064 | \sa toLatin1(), toLocal8Bit(), QStringEncoder |
1065 | */ |
1066 | |
1067 | /*! |
1068 | \fn QList<uint> QStringView::toUcs4() const |
1069 | |
1070 | Returns a UCS-4/UTF-32 representation of the string view as a QList<uint>. |
1071 | |
1072 | UCS-4 is a Unicode codec and therefore it is lossless. All characters from |
1073 | this string view will be encoded in UCS-4. Any invalid sequence of code units in |
1074 | this string view is replaced by the Unicode replacement character |
1075 | (QChar::ReplacementCharacter, which corresponds to \c{U+FFFD}). |
1076 | |
1077 | The returned list is not 0-terminated. |
1078 | |
1079 | \sa toUtf8(), toLatin1(), toLocal8Bit(), QStringEncoder |
1080 | */ |
1081 | |
1082 | /*! |
1083 | \fn template <typename QStringLike> qToStringViewIgnoringNull(const QStringLike &s); |
1084 | \since 5.10 |
1085 | \internal |
1086 | |
1087 | Convert \a s to a QStringView ignoring \c{s.isNull()}. |
1088 | |
1089 | Returns a string view that references \a{s}' data, but is never null. |
1090 | |
1091 | This is a faster way to convert a QString to a QStringView, |
1092 | if null QStrings can legitimately be treated as empty ones. |
1093 | |
1094 | \sa QString::isNull(), QStringView |
1095 | */ |
1096 | |
1097 | /*! |
1098 | \fn bool QStringView::isRightToLeft() const |
1099 | \since 5.11 |
1100 | |
1101 | Returns \c true if the string view is read right to left. |
1102 | |
1103 | \sa QString::isRightToLeft() |
1104 | */ |
1105 | |
1106 | /*! |
1107 | \fn bool QStringView::isValidUtf16() const |
1108 | \since 5.15 |
1109 | |
1110 | Returns \c true if the string view contains valid UTF-16 encoded data, |
1111 | or \c false otherwise. |
1112 | |
1113 | Note that this function does not perform any special validation of the |
1114 | data; it merely checks if it can be successfully decoded from UTF-16. |
1115 | The data is assumed to be in host byte order; the presence of a BOM |
1116 | is meaningless. |
1117 | |
1118 | \sa QString::isValidUtf16() |
1119 | */ |
1120 | |
1121 | /*! |
1122 | \fn bool QStringView::isLower() const |
1123 | \since 6.7 |
1124 | Returns \c true if this view is identical to its lowercase folding. |
1125 | |
1126 | Note that this does \e not mean that the string view does not contain |
1127 | uppercase letters (some uppercase letters do not have a lowercase |
1128 | folding; they are left unchanged by toString().toLower()). |
1129 | For more information, refer to the Unicode standard, section 3.13. |
1130 | |
1131 | \sa QChar::toLower(), isUpper() |
1132 | */ |
1133 | |
1134 | /*! |
1135 | \fn bool QStringView::isUpper() const |
1136 | \since 6.7 |
1137 | Returns \c true if this view is identical to its uppercase folding. |
1138 | |
1139 | Note that this does \e not mean that the the string view does not contain |
1140 | lowercase letters (some lowercase letters do not have a uppercase |
1141 | folding; they are left unchanged by toString().toUpper()). |
1142 | For more information, refer to the Unicode standard, section 3.13. |
1143 | |
1144 | \sa QChar::toUpper(), isLower() |
1145 | */ |
1146 | |
1147 | /*! |
1148 | \fn QStringView::toWCharArray(wchar_t *array) const |
1149 | \since 5.14 |
1150 | |
1151 | Transcribes this string view into the given \a array. |
1152 | |
1153 | The caller is responsible for ensuring \a array is large enough to hold the |
1154 | \c wchar_t encoding of this string view (allocating the array with the same length |
1155 | as the string view is always sufficient). The array is encoded in UTF-16 on |
1156 | platforms where \c wchar_t is 2 bytes wide (e.g. Windows); otherwise (Unix |
1157 | systems), \c wchar_t is assumed to be 4 bytes wide and the data is written |
1158 | in UCS-4. |
1159 | |
1160 | \note This function writes no null terminator to the end of \a array. |
1161 | |
1162 | Returns the number of \c wchar_t entries written to \a array. |
1163 | |
1164 | \sa QString::toWCharArray() |
1165 | */ |
1166 | |
1167 | /*! |
1168 | \fn qsizetype QStringView::count(QChar ch, Qt::CaseSensitivity cs) const noexcept |
1169 | |
1170 | \since 6.0 |
1171 | \overload count() |
1172 | |
1173 | Returns the number of occurrences of the character \a ch in the |
1174 | string view. |
1175 | |
1176 | \include qstring.qdocinc {search-comparison-case-sensitivity} {search} |
1177 | |
1178 | \sa QString::count(), contains(), indexOf() |
1179 | */ |
1180 | |
1181 | /*! |
1182 | \fn qsizetype QStringView::count(QStringView str, Qt::CaseSensitivity cs) const noexcept |
1183 | |
1184 | \since 6.0 |
1185 | \overload count() |
1186 | |
1187 | Returns the number of (potentially overlapping) occurrences of the |
1188 | string view \a str in this string view. |
1189 | |
1190 | \include qstring.qdocinc {search-comparison-case-sensitivity} {search} |
1191 | |
1192 | \sa QString::count(), contains(), indexOf() |
1193 | */ |
1194 | |
1195 | /*! |
1196 | \fn qsizetype QStringView::count(QLatin1StringView l1, Qt::CaseSensitivity cs) const noexcept |
1197 | |
1198 | \since 6.4 |
1199 | \overload count() |
1200 | |
1201 | Returns the number of (potentially overlapping) occurrences of the |
1202 | Latin-1 string viewed by \a l1 in this string view. |
1203 | |
1204 | \include qstring.qdocinc {search-comparison-case-sensitivity} {search} |
1205 | |
1206 | \sa QString::count(), contains(), indexOf() |
1207 | */ |
1208 | |
1209 | /*! |
1210 | \fn qint64 QStringView::toLongLong(bool *ok, int base) const |
1211 | |
1212 | Returns the string view converted to a \c{long long} using base \a |
1213 | base, which is 10 by default and must be between 2 and 36, or 0. |
1214 | Returns 0 if the conversion fails. |
1215 | |
1216 | If \a ok is not \nullptr, failure is reported by setting *\a{ok} |
1217 | to \c false, and success by setting *\a{ok} to \c true. |
1218 | |
1219 | If \a base is 0, the C language convention is used: if the string view |
1220 | begins with "0x", base 16 is used; otherwise, if the string view begins with "0", |
1221 | base 8 is used; otherwise, base 10 is used. |
1222 | |
1223 | The string conversion will always happen in the 'C' locale. For locale |
1224 | dependent conversion use QLocale::toLongLong() |
1225 | |
1226 | \sa QString::toLongLong() |
1227 | |
1228 | \since 6.0 |
1229 | */ |
1230 | |
1231 | /*! |
1232 | \fn quint64 QStringView::toULongLong(bool *ok, int base) const |
1233 | |
1234 | Returns the string view converted to an \c{unsigned long long} using base \a |
1235 | base, which is 10 by default and must be between 2 and 36, or 0. |
1236 | Returns 0 if the conversion fails. |
1237 | |
1238 | If \a ok is not \nullptr, failure is reported by setting *\a{ok} |
1239 | to \c false, and success by setting *\a{ok} to \c true. |
1240 | |
1241 | If \a base is 0, the C language convention is used: if the string view |
1242 | begins with "0x", base 16 is used; otherwise, if the string view begins with "0", |
1243 | base 8 is used; otherwise, base 10 is used. |
1244 | |
1245 | The string conversion will always happen in the 'C' locale. For locale |
1246 | dependent conversion use QLocale::toULongLong() |
1247 | |
1248 | \sa QString::toULongLong() |
1249 | |
1250 | \since 6.0 |
1251 | */ |
1252 | |
1253 | /*! |
1254 | \fn long QStringView::toLong(bool *ok, int base) const |
1255 | |
1256 | Returns the string view converted to a \c long using base \a |
1257 | base, which is 10 by default and must be between 2 and 36, or 0. |
1258 | Returns 0 if the conversion fails. |
1259 | |
1260 | If \a ok is not \nullptr, failure is reported by setting *\a{ok} |
1261 | to \c false, and success by setting *\a{ok} to \c true. |
1262 | |
1263 | If \a base is 0, the C language convention is used: if the string view |
1264 | begins with "0x", base 16 is used; otherwise, if the string view begins with "0", |
1265 | base 8 is used; otherwise, base 10 is used. |
1266 | |
1267 | The string conversion will always happen in the 'C' locale. For locale |
1268 | dependent conversion use QLocale::toLong() |
1269 | |
1270 | \sa QString::toLong() |
1271 | |
1272 | \since 6.0 |
1273 | */ |
1274 | |
1275 | /*! |
1276 | \fn ulong QStringView::toULong(bool *ok, int base) const |
1277 | |
1278 | Returns the string view converted to an \c{unsigned long} using base \a |
1279 | base, which is 10 by default and must be between 2 and 36, or 0. |
1280 | Returns 0 if the conversion fails. |
1281 | |
1282 | If \a ok is not \nullptr, failure is reported by setting *\a{ok} |
1283 | to \c false, and success by setting *\a{ok} to \c true. |
1284 | |
1285 | If \a base is 0, the C language convention is used: if the string view |
1286 | begins with "0x", base 16 is used; otherwise, if the string view begins with "0", |
1287 | base 8 is used; otherwise, base 10 is used. |
1288 | |
1289 | The string conversion will always happen in the 'C' locale. For locale |
1290 | dependent conversion use QLocale::toULongLong() |
1291 | |
1292 | \sa QString::toULong() |
1293 | |
1294 | \since 6.0 |
1295 | */ |
1296 | |
1297 | /*! |
1298 | \fn int QStringView::toInt(bool *ok, int base) const |
1299 | |
1300 | Returns the string view converted to an \c int using base \a |
1301 | base, which is 10 by default and must be between 2 and 36, or 0. |
1302 | Returns 0 if the conversion fails. |
1303 | |
1304 | If \a ok is not \nullptr, failure is reported by setting *\a{ok} |
1305 | to \c false, and success by setting *\a{ok} to \c true. |
1306 | |
1307 | If \a base is 0, the C language convention is used: if the string view |
1308 | begins with "0x", base 16 is used; otherwise, if the string view begins with "0", |
1309 | base 8 is used; otherwise, base 10 is used. |
1310 | |
1311 | The string conversion will always happen in the 'C' locale. For locale |
1312 | dependent conversion use QLocale::toInt() |
1313 | |
1314 | \sa QString::toInt() |
1315 | |
1316 | \since 6.0 |
1317 | */ |
1318 | |
1319 | /*! |
1320 | \fn uint QStringView::toUInt(bool *ok, int base) const |
1321 | |
1322 | Returns the string view converted to an \c{unsigned int} using base \a |
1323 | base, which is 10 by default and must be between 2 and 36, or 0. |
1324 | Returns 0 if the conversion fails. |
1325 | |
1326 | If \a ok is not \nullptr, failure is reported by setting *\a{ok} |
1327 | to \c false, and success by setting *\a{ok} to \c true. |
1328 | |
1329 | If \a base is 0, the C language convention is used: if the string view |
1330 | begins with "0x", base 16 is used; otherwise, if the string view begins with "0", |
1331 | base 8 is used; otherwise, base 10 is used. |
1332 | |
1333 | The string conversion will always happen in the 'C' locale. For locale |
1334 | dependent conversion use QLocale::toUInt() |
1335 | |
1336 | \sa QString::toUInt() |
1337 | |
1338 | \since 6.0 |
1339 | */ |
1340 | |
1341 | /*! |
1342 | \fn short QStringView::toShort(bool *ok, int base) const |
1343 | |
1344 | Returns the string view converted to a \c short using base \a |
1345 | base, which is 10 by default and must be between 2 and 36, or 0. |
1346 | Returns 0 if the conversion fails. |
1347 | |
1348 | If \a ok is not \nullptr, failure is reported by setting *\a{ok} |
1349 | to \c false, and success by setting *\a{ok} to \c true. |
1350 | |
1351 | If \a base is 0, the C language convention is used: if the string view |
1352 | begins with "0x", base 16 is used; otherwise, if the string view begins with "0", |
1353 | base 8 is used; otherwise, base 10 is used. |
1354 | |
1355 | The string conversion will always happen in the 'C' locale. For locale |
1356 | dependent conversion use QLocale::toShort() |
1357 | |
1358 | \sa QString::toShort() |
1359 | |
1360 | \since 6.0 |
1361 | */ |
1362 | |
1363 | /*! |
1364 | \fn ushort QStringView::toUShort(bool *ok, int base) const |
1365 | |
1366 | Returns the string view converted to an \c{unsigned short} using base \a |
1367 | base, which is 10 by default and must be between 2 and 36, or 0. |
1368 | Returns 0 if the conversion fails. |
1369 | |
1370 | If \a ok is not \nullptr, failure is reported by setting *\a{ok} |
1371 | to \c false, and success by setting *\a{ok} to \c true. |
1372 | |
1373 | If \a base is 0, the C language convention is used: if the string view |
1374 | begins with "0x", base 16 is used; otherwise, if the string view begins with "0", |
1375 | base 8 is used; otherwise, base 10 is used. |
1376 | |
1377 | The string conversion will always happen in the 'C' locale. For locale |
1378 | dependent conversion use QLocale::toUShort() |
1379 | |
1380 | \sa QString::toUShort() |
1381 | |
1382 | \since 6.0 |
1383 | */ |
1384 | |
1385 | /*! |
1386 | \fn double QStringView::toDouble(bool *ok) const |
1387 | |
1388 | Returns the string view converted to a \c double value. |
1389 | |
1390 | Returns an infinity if the conversion overflows or 0.0 if the |
1391 | conversion fails for other reasons (e.g. underflow). |
1392 | |
1393 | If \a ok is not \nullptr, failure is reported by setting *\a{ok} |
1394 | to \c false, and success by setting *\a{ok} to \c true. |
1395 | |
1396 | The string conversion will always happen in the 'C' locale. For locale |
1397 | dependent conversion use QLocale::toDouble() |
1398 | |
1399 | For historic reasons, this function does not handle |
1400 | thousands group separators. If you need to convert such numbers, |
1401 | use QLocale::toDouble(). |
1402 | |
1403 | \sa QString::toDouble() |
1404 | |
1405 | \since 6.0 |
1406 | */ |
1407 | |
1408 | /*! |
1409 | \fn float QStringView::toFloat(bool *ok) const |
1410 | |
1411 | Returns the string view converted to a \c float value. |
1412 | |
1413 | Returns an infinity if the conversion overflows or 0.0 if the |
1414 | conversion fails for other reasons (e.g. underflow). |
1415 | |
1416 | If \a ok is not \nullptr, failure is reported by setting *\a{ok} |
1417 | to \c false, and success by setting *\a{ok} to \c true. |
1418 | |
1419 | The string conversion will always happen in the 'C' locale. For locale |
1420 | dependent conversion use QLocale::toFloat() |
1421 | |
1422 | \sa QString::toFloat() |
1423 | |
1424 | \since 6.0 |
1425 | */ |
1426 | |
1427 | |
1428 | /*! |
1429 | \fn template <typename Needle, typename...Flags> auto QStringView::tokenize(Needle &&sep, Flags...flags) const |
1430 | \fn template <typename Needle, typename...Flags> auto QLatin1StringView::tokenize(Needle &&sep, Flags...flags) const |
1431 | \fn template <typename Needle, typename...Flags> auto QString::tokenize(Needle &&sep, Flags...flags) const & |
1432 | \fn template <typename Needle, typename...Flags> auto QString::tokenize(Needle &&sep, Flags...flags) const && |
1433 | \fn template <typename Needle, typename...Flags> auto QString::tokenize(Needle &&sep, Flags...flags) && |
1434 | |
1435 | Splits the string into substring views wherever \a sep occurs, and |
1436 | returns a lazy sequence of those strings. |
1437 | |
1438 | Equivalent to |
1439 | |
1440 | \code |
1441 | return QStringTokenizer{std::forward<Needle>(sep), flags...}; |
1442 | \endcode |
1443 | |
1444 | except it works without C++17 Class Template Argument Deduction (CTAD) |
1445 | enabled in the compiler. |
1446 | |
1447 | See QStringTokenizer for how \a sep and \a flags interact to form |
1448 | the result. |
1449 | |
1450 | \note While this function returns QStringTokenizer, you should never, |
1451 | ever, name its template arguments explicitly. If you can use C++17 Class |
1452 | Template Argument Deduction (CTAD), you may write |
1453 | \code |
1454 | QStringTokenizer result = sv.tokenize(sep); |
1455 | \endcode |
1456 | (without template arguments). If you can't use C++17 CTAD, you must store |
1457 | the return value only in \c{auto} variables: |
1458 | \code |
1459 | auto result = sv.tokenize(sep); |
1460 | \endcode |
1461 | This is because the template arguments of QStringTokenizer have a very |
1462 | subtle dependency on the specific tokenize() overload from which they are |
1463 | returned, and they don't usually correspond to the type used for the separator. |
1464 | |
1465 | \since 6.0 |
1466 | \sa QStringTokenizer, qTokenize() |
1467 | */ |
1468 | |
1469 | /*! |
1470 | \fn QStringView::operator std::u16string_view() const |
1471 | \since 6.7 |
1472 | |
1473 | Converts this QStringView object to a \c{std::u16string_view} object. |
1474 | The returned view will have the same data pointer and length of |
1475 | this view. |
1476 | */ |
1477 | |
1478 | /*! |
1479 | \fn QStringView::maxSize() |
1480 | \since 6.8 |
1481 | |
1482 | It returns the maximum number of elements that the view can |
1483 | theoretically represent. In practice, the number can be much smaller, |
1484 | limited by the amount of memory available to the system. |
1485 | */ |
1486 | |
1487 | /*! |
1488 | \fn QStringView::max_size() const |
1489 | \since 6.8 |
1490 | |
1491 | This function is provided for STL compatibility. |
1492 | |
1493 | Returns maxSize(). |
1494 | */ |
1495 | |
1496 | QT_END_NAMESPACE |
1497 | |