/src/solidity/liblangutil/Common.h
Line  | Count  | Source  | 
1  |  | /*  | 
2  |  |   This file is part of solidity.  | 
3  |  |   solidity is free software: you can redistribute it and/or modify  | 
4  |  |   it under the terms of the GNU General Public License as published by  | 
5  |  |   the Free Software Foundation, either version 3 of the License, or  | 
6  |  |   (at your option) any later version.  | 
7  |  |   solidity is distributed in the hope that it will be useful,  | 
8  |  |   but WITHOUT ANY WARRANTY; without even the implied warranty of  | 
9  |  |   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  | 
10  |  |   GNU General Public License for more details.  | 
11  |  |   You should have received a copy of the GNU General Public License  | 
12  |  |   along with solidity.  If not, see <http://www.gnu.org/licenses/>.  | 
13  |  | */  | 
14  |  |  | 
15  |  | #pragma once  | 
16  |  |  | 
17  |  | namespace solidity::langutil  | 
18  |  | { | 
19  |  |  | 
20  |  | inline bool isDecimalDigit(char c)  | 
21  | 16.9M  | { | 
22  | 16.9M  |   return '0' <= c && c <= '9';  | 
23  | 16.9M  | }  | 
24  |  |  | 
25  |  | inline bool isHexDigit(char c)  | 
26  | 1.23M  | { | 
27  | 1.23M  |   return  | 
28  | 1.23M  |     isDecimalDigit(c) ||  | 
29  | 1.23M  |     ('a' <= c && c <= 'f') || | 
30  | 1.23M  |     ('A' <= c && c <= 'F'); | 
31  | 1.23M  | }  | 
32  |  |  | 
33  |  | inline bool isWhiteSpace(char c)  | 
34  | 26.0M  | { | 
35  | 26.0M  |   return c == ' ' || c == '\n' || c == '\t' || c == '\r';  | 
36  | 26.0M  | }  | 
37  |  |  | 
38  |  | inline bool isIdentifierStart(char c)  | 
39  | 50.7M  | { | 
40  | 50.7M  |   return c == '_' || c == '$' || ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'); | 
41  | 50.7M  | }  | 
42  |  |  | 
43  |  | inline bool isIdentifierPart(char c)  | 
44  | 37.2M  | { | 
45  | 37.2M  |   return isIdentifierStart(c) || isDecimalDigit(c);  | 
46  | 37.2M  | }  | 
47  |  |  | 
48  |  | inline int hexValue(char c)  | 
49  | 1.04M  | { | 
50  | 1.04M  |   if (c >= '0' && c <= '9')  | 
51  | 813k  |     return c - '0';  | 
52  | 234k  |   else if (c >= 'a' && c <= 'f')  | 
53  | 231k  |     return c - 'a' + 10;  | 
54  | 2.89k  |   else if (c >= 'A' && c <= 'F')  | 
55  | 2.30k  |     return c - 'A' + 10;  | 
56  | 596  |   else return -1;  | 
57  | 1.04M  | }  | 
58  |  | }  |