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