| 213 | } |
| 214 | |
| 215 | std::optional<int> GetIntAttribute(tinyxml2::XMLElement* ele, char const* name) |
| 216 | { |
| 217 | char const* value{ nullptr }; |
| 218 | auto e = ele->QueryStringAttribute(name, &value); |
| 219 | if (e != tinyxml2::XML_SUCCESS) { |
| 220 | return {}; |
| 221 | } |
| 222 | |
| 223 | std::size_t readSize{ 0 }; |
| 224 | int parsed; |
| 225 | try { |
| 226 | parsed = std::stoi(value, &readSize, 0); |
| 227 | } catch (std::exception const& e) { |
| 228 | ERR("Invalid int value in XML attribute '%s': '%s' (%s)", name, value, e.what()); |
| 229 | return {}; |
| 230 | } |
| 231 | |
| 232 | if (readSize != strlen(value)) { |
| 233 | ERR("Invalid int value in XML attribute '%s': '%s' (garbage found at end of string)", name, value); |
| 234 | } |
| 235 | |
| 236 | return parsed; |
| 237 | } |
| 238 | |
| 239 | std::optional<int> GetOffsetAttribute(tinyxml2::XMLElement* ele, Pattern const& pattern, char const* name) |
| 240 | { |