Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qv4stringtoarrayindex_p.h
Go to the documentation of this file.
1
// Copyright (C) 2019 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
// Qt-Security score:significant
4
5
#
ifndef
QV4STRINGTOARRAYINDEX_P_H
6
#
define
QV4STRINGTOARRAYINDEX_P_H
7
8
//
9
// W A R N I N G
10
// -------------
11
//
12
// This file is not part of the Qt API. It exists purely as an
13
// implementation detail. This header file may change from version to
14
// version without notice, or even be removed.
15
//
16
// We mean it.
17
//
18
19
#
include
<
QtCore
/
private
/
qnumeric_p
.
h
>
20
#
include
<
QtCore
/
qstring
.
h
>
21
#
include
<
limits
>
22
23
QT_BEGIN_NAMESPACE
24
25
namespace
QV4
{
26
27
inline
uint
charToUInt
(
const
QChar *ch) {
return
ch->unicode(); }
28
inline
uint
charToUInt
(
const
char
*ch) {
return
static_cast
<
unsigned
char
>(*ch); }
29
30
template
<
typename
T>
31
uint
stringToArrayIndex
(
const
T *ch,
const
T *end)
32
{
33
if
(ch == end)
34
return
std::numeric_limits<uint>::max();
35
uint i = charToUInt(ch) -
'0'
;
36
if
(i > 9)
37
return
std::numeric_limits<uint>::max();
38
++ch;
39
// reject "01", "001", ...
40
if
(i == 0 && ch != end)
41
return
std::numeric_limits<uint>::max();
42
43
while
(ch < end) {
44
uint x = charToUInt(ch) -
'0'
;
45
if
(x > 9)
46
return
std::numeric_limits<uint>::max();
47
if
(qMulOverflow(i, uint(10), &i) || qAddOverflow(i, x, &i))
// i = i * 10 + x
48
return
std::numeric_limits<uint>::max();
49
++ch;
50
}
51
return
i;
52
}
53
54
inline
uint
stringToArrayIndex
(
const
QString &str)
55
{
56
return
stringToArrayIndex(str.constData(), str.constData() + str.size());
57
}
58
59
}
// namespace QV4
60
61
QT_END_NAMESPACE
62
63
#
endif
// QV4STRINGTOARRAYINDEX_P_H
QV4
Definition
qjsvalue.h:24
QV4::stringToArrayIndex
uint stringToArrayIndex(const QString &str)
Definition
qv4stringtoarrayindex_p.h:54
QV4::stringToArrayIndex
uint stringToArrayIndex(const T *ch, const T *end)
Definition
qv4stringtoarrayindex_p.h:31
QV4::charToUInt
uint charToUInt(const char *ch)
Definition
qv4stringtoarrayindex_p.h:28
QV4::charToUInt
uint charToUInt(const QChar *ch)
Definition
qv4stringtoarrayindex_p.h:27
qtdeclarative
src
qml
common
qv4stringtoarrayindex_p.h
Generated on
for Qt by
1.18.0