| 36 | } |
| 37 | |
| 38 | void Bundle::load(const std::string& path) { |
| 39 | std::string untranslated; |
| 40 | std::string translated; |
| 41 | char buffer[1024]; |
| 42 | |
| 43 | std::ifstream poStrm(path.c_str()); |
| 44 | if (!poStrm.good()) { |
| 45 | return; |
| 46 | } |
| 47 | |
| 48 | poStrm.getline(buffer, 1024); |
| 49 | while (poStrm.good()) { |
| 50 | std::string line = buffer; |
| 51 | std::string data; |
| 52 | TLineType type = parseLine(line, data); |
| 53 | if (type == tMSGID) { |
| 54 | if (untranslated.length() > 0) { |
| 55 | mappings.erase(untranslated); |
| 56 | mappings.insert(std::pair<std::string, std::string>(untranslated, translated)); |
| 57 | } |
| 58 | untranslated = data; |
| 59 | translated.resize(0); |
| 60 | } |
| 61 | else if (type == tMSGSTR) { |
| 62 | if (untranslated.length() > 0) { |
| 63 | translated = data; |
| 64 | } |
| 65 | } |
| 66 | else if (type == tAPPEND) { |
| 67 | if (untranslated.length() > 0) { |
| 68 | translated += data; |
| 69 | } |
| 70 | } |
| 71 | else if (type == tERROR) { |
| 72 | |
| 73 | } |
| 74 | |
| 75 | |
| 76 | poStrm.getline(buffer, 1024); |
| 77 | } |
| 78 | |
| 79 | if ((untranslated.length() > 0) && (translated.length() > 0)) { |
| 80 | mappings.erase(untranslated); |
| 81 | mappings.insert(std::pair<std::string, std::string>(untranslated, translated)); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | Bundle::TLineType Bundle::parseLine(const std::string& line, std::string& data) const { |
| 86 | int startPos, endPos; |