| 186 | } |
| 187 | |
| 188 | Game_Message::ParseParamResult Game_Message::ParseParam( |
| 189 | char upper, |
| 190 | char lower, |
| 191 | const char* iter, |
| 192 | const char* end, |
| 193 | uint32_t escape_char, |
| 194 | bool skip_prefix, |
| 195 | int max_recursion) |
| 196 | { |
| 197 | if (!skip_prefix) { |
| 198 | const auto begin = iter; |
| 199 | if (iter == end) { |
| 200 | return { begin, 0 }; |
| 201 | } |
| 202 | auto ret = Utils::UTF8Next(iter, end); |
| 203 | // Invalid commands |
| 204 | if (ret.ch != escape_char) { |
| 205 | return { begin, 0 }; |
| 206 | } |
| 207 | iter = ret.next; |
| 208 | if (iter == end || (*iter != upper && *iter != lower)) { |
| 209 | return { begin, 0 }; |
| 210 | } |
| 211 | ++iter; |
| 212 | } |
| 213 | |
| 214 | // If no bracket, RPG_RT will return 0. |
| 215 | if (iter == end || *iter != '[') { |
| 216 | return { iter, 0 }; |
| 217 | } |
| 218 | |
| 219 | int value = 0; |
| 220 | ++iter; |
| 221 | bool stop_parsing = false; |
| 222 | bool got_valid_number = false; |
| 223 | |
| 224 | while (iter != end && *iter != ']') { |
| 225 | if (stop_parsing) { |
| 226 | ++iter; |
| 227 | continue; |
| 228 | } |
| 229 | |
| 230 | // Fast inline isdigit() |
| 231 | if (*iter >= '0' && *iter <= '9') { |
| 232 | value *= 10; |
| 233 | value += (*iter - '0'); |
| 234 | ++iter; |
| 235 | got_valid_number = true; |
| 236 | continue; |
| 237 | } |
| 238 | |
| 239 | if (max_recursion > 0) { |
| 240 | auto ret = Utils::UTF8Next(iter, end); |
| 241 | auto ch = ret.ch; |
| 242 | iter = ret.next; |
| 243 | |
| 244 | // Recursive variable case. |
| 245 | if (ch == escape_char) { |
nothing calls this directly
no test coverage detected