| 135 | }; |
| 136 | |
| 137 | String remove_comments(const String &script_text) { |
| 138 | // gdscripts have comments starting with #, remove them |
| 139 | auto lines = script_text.split("\n", true); |
| 140 | auto new_lines = Vector<String>(); |
| 141 | for (int i = 0; i < lines.size(); i++) { |
| 142 | auto &line = lines.write[i]; |
| 143 | auto comment_pos = line.find("#"); |
| 144 | if (comment_pos != -1) { |
| 145 | if (line.contains("\"") || line.contains("'")) { |
| 146 | bool in_quote = false; |
| 147 | char32_t quote_char = '"'; |
| 148 | comment_pos = -1; |
| 149 | for (int j = 0; j < line.length(); j++) { |
| 150 | if (line[j] == '"' || line[j] == '\'') { |
| 151 | if (in_quote) { |
| 152 | if (quote_char == line[j]) { |
| 153 | in_quote = false; |
| 154 | } |
| 155 | } else { |
| 156 | in_quote = true; |
| 157 | quote_char = line[j]; |
| 158 | } |
| 159 | } else if (!in_quote && line[j] == '#') { |
| 160 | comment_pos = j; |
| 161 | break; |
| 162 | } |
| 163 | } |
| 164 | } |
| 165 | if (comment_pos != -1) { |
| 166 | line = line.substr(0, comment_pos).strip_edges(false, true); |
| 167 | } |
| 168 | } |
| 169 | new_lines.push_back(line); |
| 170 | } |
| 171 | String new_text; |
| 172 | for (int i = 0; i < new_lines.size() - 1; i++) { |
| 173 | new_text += new_lines[i] + "\n"; |
| 174 | } |
| 175 | new_text += new_lines[new_lines.size() - 1]; |
| 176 | return new_text; |
| 177 | } |
| 178 | |
| 179 | REGISTER_LISTENER("GDRETestListener", 2, GDRETestListener); |