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