* Save the city under a new name (?) * @param filename Name of the file to use for storing the game. * @todo String normalization code is duplicated in Micropolis::loadCity(). * Extract to a sub-function. * @bug Function fails if \c lastDot<lastSlash (ie with \c "x.y/bla" ) */
| 613 | * @bug Function fails if \c lastDot<lastSlash (ie with \c "x.y/bla" ) |
| 614 | */ |
| 615 | void Micropolis::saveCityAs(const char *filename) |
| 616 | { |
| 617 | cityFileName = filename; |
| 618 | |
| 619 | if (saveFile(cityFileName.c_str())) { |
| 620 | |
| 621 | unsigned int lastDot = cityFileName.find_last_of('.'); |
| 622 | unsigned int lastSlash = cityFileName.find_last_of('/'); |
| 623 | |
| 624 | unsigned int pos = |
| 625 | (lastSlash == std::string::npos) ? 0 : lastSlash + 1; |
| 626 | unsigned int last = |
| 627 | (lastDot == std::string::npos) ? cityFileName.length() : lastDot; |
| 628 | unsigned int len = |
| 629 | last - pos; |
| 630 | std::string newCityName = |
| 631 | cityFileName.substr(pos, len); |
| 632 | |
| 633 | setCityName(newCityName); |
| 634 | |
| 635 | didSaveCity(); |
| 636 | |
| 637 | } else { |
| 638 | |
| 639 | didntSaveCity(cityFileName.c_str()); |
| 640 | |
| 641 | } |
| 642 | } |
| 643 | |
| 644 | |
| 645 | //////////////////////////////////////////////////////////////////////// |
no outgoing calls
no test coverage detected