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
9#include <algorithm>
10
11QT_BEGIN_NAMESPACE
12
13inline bool is_whitespace(char s)
14{
15 return (s == ' ' || s == '\t' || s == '\n');
16}
17
18inline bool is_space(char s)
19{
20 return (s == ' ' || s == '\t');
21}
22
23inline bool is_ident_start(char s)
24{
25 return ((s >= 'a' && s <= 'z')
26 || (s >= 'A' && s <= 'Z')
27 || s == '_' || s == '$'
28 );
29}
30
31inline bool is_ident_char(char s)
32{
33 return ((s >= 'a' && s <= 'z')
34 || (s >= 'A' && s <= 'Z')
35 || (s >= '0' && s <= '9')
36 || s == '_' || s == '$'
37 );
38}
39
40inline bool is_identifier(const char *s, qsizetype len)
41{
42 if (len < 1)
43 return false;
44 return std::all_of(first: s, last: s + len, pred: is_ident_char);
45}
46
47inline bool is_digit_char(char s)
48{
49 return (s >= '0' && s <= '9');
50}
51
52inline bool is_octal_char(char s)
53{
54 return (s >= '0' && s <= '7');
55}
56
57inline bool is_hex_char(char s)
58{
59 return ((s >= 'a' && s <= 'f')
60 || (s >= 'A' && s <= 'F')
61 || (s >= '0' && s <= '9')
62 );
63}
64
65inline const char *skipQuote(const char *data)
66{
67 while (*data && (*data != '\"')) {
68 if (*data == '\\') {
69 ++data;
70 if (!*data) break;
71 }
72 ++data;
73 }
74
75 if (*data) //Skip last quote
76 ++data;
77 return data;
78}
79
80QT_END_NAMESPACE
81
82#endif // UTILS_H
83

source code of qtbase/src/tools/moc/utils.h