1 | // Copyright (C) 2016 The Qt Company Ltd. |
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 "qhashedstring_p.h" |
5 | |
6 | QT_BEGIN_NAMESPACE |
7 | |
8 | QHashedStringRef QHashedStringRef::mid(int offset, int length) const |
9 | { |
10 | Q_ASSERT(offset < m_length); |
11 | return QHashedStringRef(m_data + offset, |
12 | (length == -1 || (offset + length) > m_length)?(m_length - offset):length); |
13 | } |
14 | |
15 | QVector<QHashedStringRef> QHashedStringRef::split(const QChar sep) const |
16 | { |
17 | QVector<QHashedStringRef> ret; |
18 | auto curLength = 0; |
19 | auto curOffset = m_data; |
20 | for (int offset = 0; offset < m_length; ++offset) { |
21 | if (*(m_data + offset) == sep) { |
22 | ret.push_back(t: {curOffset, curLength}); |
23 | curOffset = m_data + offset + 1; |
24 | curLength = 0; |
25 | } else { |
26 | ++curLength; |
27 | } |
28 | } |
29 | if (curLength > 0) |
30 | ret.push_back(t: {curOffset, curLength}); |
31 | return ret; |
32 | } |
33 | |
34 | bool QHashedStringRef::endsWith(const QString &s) const |
35 | { |
36 | QStringView view {m_data, m_length}; |
37 | return view.endsWith(s); |
38 | } |
39 | |
40 | bool QHashedStringRef::startsWith(const QString &s) const |
41 | { |
42 | QStringView view {m_data, m_length}; |
43 | return view.startsWith(s); |
44 | } |
45 | |
46 | int QHashedStringRef::indexOf(const QChar &c, int from) const |
47 | { |
48 | QStringView view {m_data, m_length}; |
49 | return view.indexOf(c, from); |
50 | } |
51 | |
52 | QString QHashedStringRef::toString() const |
53 | { |
54 | if (m_length == 0) |
55 | return QString(); |
56 | return QString(m_data, m_length); |
57 | } |
58 | |
59 | QString QHashedCStringRef::toUtf16() const |
60 | { |
61 | if (m_length == 0) |
62 | return QString(); |
63 | |
64 | QString rv; |
65 | rv.resize(size: m_length); |
66 | writeUtf16(output: (quint16*)rv.data()); |
67 | return rv; |
68 | } |
69 | |
70 | QT_END_NAMESPACE |
71 | |