10
10
#include " vtr_util.h"
11
11
#include " vtr_memory.h"
12
12
13
- enum e_token_type GetTokenTypeFromChar (const enum e_token_type cur_token_type,
14
- const char cur);
15
-
16
- bool IsWhitespace (char c);
17
-
18
- // /@brief Returns true if character is whatspace between tokens
19
- bool IsWhitespace (char c) {
20
- switch (c) {
21
- case ' ' :
22
- case ' \t ' :
23
- case ' \r ' :
24
- case ' \n ' :
25
- return true ;
26
- default :
27
- return false ;
28
- }
29
- }
13
+ #include < cctype>
14
+
15
+ // / @brief Returns a token type of the given char
16
+ static e_token_type get_token_type_from_char ( e_token_type cur_token_type, char cur);
30
17
31
18
const t_token Tokens::null_token_{e_token_type::NULL_TOKEN, " " };
32
19
@@ -40,7 +27,7 @@ Tokens::Tokens(std::string_view inString) {
40
27
size_t prev_in_string_index = 0 ;
41
28
42
29
for (char cur : inString) {
43
- e_token_type new_token_type = GetTokenTypeFromChar (cur_token_type, cur);
30
+ e_token_type new_token_type = get_token_type_from_char (cur_token_type, cur);
44
31
if (new_token_type != cur_token_type) {
45
32
if (cur_token_type != e_token_type::NULL_TOKEN) {
46
33
// Finalize the current token
@@ -76,10 +63,8 @@ const t_token& Tokens::operator[](size_t idx) const {
76
63
}
77
64
}
78
65
79
- // /@brief Returns a token type of the given char
80
- enum e_token_type GetTokenTypeFromChar (const enum e_token_type cur_token_type,
81
- const char cur) {
82
- if (IsWhitespace (cur)) {
66
+ static e_token_type get_token_type_from_char ( e_token_type cur_token_type, char cur) {
67
+ if (std::isspace (cur)) {
83
68
return e_token_type::NULL_TOKEN;
84
69
} else {
85
70
if (cur == ' [' ) {
@@ -102,7 +87,6 @@ enum e_token_type GetTokenTypeFromChar(const enum e_token_type cur_token_type,
102
87
}
103
88
}
104
89
105
- // /@brief Returns a 2D array representing the atof result of all the input string entries seperated by whitespace
106
90
void my_atof_2D (float ** matrix, const int max_i, const int max_j, const char * instring) {
107
91
int i, j;
108
92
char *cur, *cur2, *copy, *final ;
@@ -116,7 +100,7 @@ void my_atof_2D(float** matrix, const int max_i, const int max_j, const char* in
116
100
cur = copy;
117
101
i = j = 0 ;
118
102
while (cur != final ) {
119
- while (IsWhitespace (*cur) && cur != final ) {
103
+ while (std::isspace (*cur) && cur != final ) {
120
104
if (j == max_j) {
121
105
i++;
122
106
j = 0 ;
@@ -127,7 +111,7 @@ void my_atof_2D(float** matrix, const int max_i, const int max_j, const char* in
127
111
break ;
128
112
}
129
113
cur2 = cur;
130
- while (!IsWhitespace (*cur2) && cur2 != final ) {
114
+ while (!std::isspace (*cur2) && cur2 != final ) {
131
115
cur2++;
132
116
}
133
117
*cur2 = ' \0 ' ;
@@ -143,11 +127,6 @@ void my_atof_2D(float** matrix, const int max_i, const int max_j, const char* in
143
127
free (copy);
144
128
}
145
129
146
- /* *
147
- * @brief Checks if the number of entries (separated by whitespace) matches the the expected number (max_i * max_j)
148
- *
149
- * can be used before calling my_atof_2D
150
- */
151
130
bool check_my_atof_2D (const int max_i, const int max_j, const char * instring, int * num_entries) {
152
131
/* Check if max_i * max_j matches number of entries in instring */
153
132
const char * cur = instring;
@@ -156,10 +135,10 @@ bool check_my_atof_2D(const int max_i, const int max_j, const char* instring, in
156
135
157
136
/* First count number of entries in instring */
158
137
while (*cur != ' \0 ' ) {
159
- if (!IsWhitespace (*cur) && !in_str) {
138
+ if (!std::isspace (*cur) && !in_str) {
160
139
in_str = true ;
161
140
entry_count++;
162
- } else if (IsWhitespace (*cur)) {
141
+ } else if (std::isspace (*cur)) {
163
142
in_str = false ;
164
143
}
165
144
cur++;
0 commit comments