1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtScxml module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #ifndef UTILS_H |
41 | #define UTILS_H |
42 | |
43 | #include <QtCore/qglobal.h> |
44 | |
45 | QT_BEGIN_NAMESPACE |
46 | |
47 | inline bool is_whitespace(char s) |
48 | { |
49 | return (s == ' ' || s == '\t' || s == '\n'); |
50 | } |
51 | |
52 | inline bool is_space(char s) |
53 | { |
54 | return (s == ' ' || s == '\t'); |
55 | } |
56 | |
57 | inline bool is_ident_start(char s) |
58 | { |
59 | return ((s >= 'a' && s <= 'z') |
60 | || (s >= 'A' && s <= 'Z') |
61 | || s == '_' || s == '$' |
62 | ); |
63 | } |
64 | |
65 | inline bool is_ident_char(char s) |
66 | { |
67 | return ((s >= 'a' && s <= 'z') |
68 | || (s >= 'A' && s <= 'Z') |
69 | || (s >= '0' && s <= '9') |
70 | || s == '_' || s == '$' |
71 | ); |
72 | } |
73 | |
74 | inline bool is_identifier(const char *s, int len) |
75 | { |
76 | if (len < 1) |
77 | return false; |
78 | if (!is_ident_start(s: *s)) |
79 | return false; |
80 | for (int i = 1; i < len; ++i) |
81 | if (!is_ident_char(s: s[i])) |
82 | return false; |
83 | return true; |
84 | } |
85 | |
86 | inline bool is_digit_char(char s) |
87 | { |
88 | return (s >= '0' && s <= '9'); |
89 | } |
90 | |
91 | inline bool is_octal_char(char s) |
92 | { |
93 | return (s >= '0' && s <= '7'); |
94 | } |
95 | |
96 | inline bool is_hex_char(char s) |
97 | { |
98 | return ((s >= 'a' && s <= 'f') |
99 | || (s >= 'A' && s <= 'F') |
100 | || (s >= '0' && s <= '9') |
101 | ); |
102 | } |
103 | |
104 | inline const char *skipQuote(const char *data) |
105 | { |
106 | while (*data && (*data != '\"')) { |
107 | if (*data == '\\') { |
108 | ++data; |
109 | if (!*data) break; |
110 | } |
111 | ++data; |
112 | } |
113 | |
114 | if (*data) //Skip last quote |
115 | ++data; |
116 | return data; |
117 | } |
118 | |
119 | QT_END_NAMESPACE |
120 | |
121 | #endif // UTILS_H |
122 | |