| 394 | namespace { |
| 395 | |
| 396 | optional<QString> read_string (nbt::value& parent, const char * name) |
| 397 | { |
| 398 | try |
| 399 | { |
| 400 | auto &namedValue = parent.at(name); |
| 401 | if(namedValue.get_type() != nbt::tag_type::String) |
| 402 | { |
| 403 | return nullopt; |
| 404 | } |
| 405 | auto & tag_str = namedValue.as<nbt::tag_string>(); |
| 406 | return QString::fromStdString(tag_str.get()); |
| 407 | } |
| 408 | catch (const std::out_of_range &e) |
| 409 | { |
| 410 | // fallback for old world formats |
| 411 | qWarning() << "String NBT tag" << name << "could not be found."; |
| 412 | return nullopt; |
| 413 | } |
| 414 | catch (const std::bad_cast &e) |
| 415 | { |
| 416 | // type mismatch |
| 417 | qWarning() << "NBT tag" << name << "could not be converted to string."; |
| 418 | return nullopt; |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | optional<int64_t> read_long (nbt::value& parent, const char * name) |
| 423 | { |
no test coverage detected