| 351 | namespace { |
| 352 | |
| 353 | optional<QString> read_string (nbt::value& parent, const char * name) |
| 354 | { |
| 355 | try |
| 356 | { |
| 357 | auto &namedValue = parent.at(name); |
| 358 | if(namedValue.get_type() != nbt::tag_type::String) |
| 359 | { |
| 360 | return nullopt; |
| 361 | } |
| 362 | auto & tag_str = namedValue.as<nbt::tag_string>(); |
| 363 | return QString::fromStdString(tag_str.get()); |
| 364 | } |
| 365 | catch (const std::out_of_range &e) |
| 366 | { |
| 367 | // fallback for old world formats |
| 368 | qWarning() << "String NBT tag" << name << "could not be found."; |
| 369 | return nullopt; |
| 370 | } |
| 371 | catch (const std::bad_cast &e) |
| 372 | { |
| 373 | // type mismatch |
| 374 | qWarning() << "NBT tag" << name << "could not be converted to string."; |
| 375 | return nullopt; |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | optional<int64_t> read_long (nbt::value& parent, const char * name) |
| 380 | { |
no test coverage detected