1 | // Copyright (C) 2016 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 |
3 | |
4 | #ifndef UTILS_H |
5 | #define UTILS_H |
6 | |
7 | #include <QtCore/qglobal.h> |
8 | #include <private/qtools_p.h> |
9 | |
10 | #include <algorithm> |
11 | |
12 | QT_BEGIN_NAMESPACE |
13 | |
14 | inline bool is_whitespace(char s) |
15 | { |
16 | return (s == ' ' || s == '\t' || s == '\n'); |
17 | } |
18 | |
19 | inline bool is_space(char s) |
20 | { |
21 | return (s == ' ' || s == '\t'); |
22 | } |
23 | |
24 | inline bool is_ident_start(char s) |
25 | { |
26 | using namespace QtMiscUtils; |
27 | return isAsciiLower(c: s) || isAsciiUpper(c: s) || s == '_' || s == '$'; |
28 | } |
29 | |
30 | inline bool is_ident_char(char s) |
31 | { |
32 | return QtMiscUtils::isAsciiLetterOrNumber(c: s) || s == '_' || s == '$'; |
33 | } |
34 | |
35 | inline bool is_identifier(const char *s, qsizetype len) |
36 | { |
37 | if (len < 1) |
38 | return false; |
39 | return std::all_of(first: s, last: s + len, pred: is_ident_char); |
40 | } |
41 | |
42 | inline const char *skipQuote(const char *data) |
43 | { |
44 | while (*data && (*data != '\"')) { |
45 | if (*data == '\\') { |
46 | ++data; |
47 | if (!*data) break; |
48 | } |
49 | ++data; |
50 | } |
51 | |
52 | if (*data) //Skip last quote |
53 | ++data; |
54 | return data; |
55 | } |
56 | |
57 | QT_END_NAMESPACE |
58 | |
59 | #endif // UTILS_H |
60 |