| 35 | } |
| 36 | |
| 37 | void TextMapper::LoadTextFile(const std::string & language) |
| 38 | { |
| 39 | // 1. open file |
| 40 | std::ifstream textFile("data/" + textFileName); |
| 41 | if (!textFile) |
| 42 | std::cout << "[ERROR] No text file !"; |
| 43 | |
| 44 | // 2. find language section |
| 45 | std::string line; |
| 46 | bool found = false; |
| 47 | std::string token = "[" + language + "]"; |
| 48 | while (!found && std::getline(textFile, line)) |
| 49 | found = (trim(line) == token); |
| 50 | |
| 51 | if (!found) |
| 52 | { |
| 53 | std::string errMsg = "[ERROR] Language '" + language + "' NOT FOUND !"; |
| 54 | std::cout << errMsg.c_str(); |
| 55 | } |
| 56 | |
| 57 | // 3. load map |
| 58 | bool mustStop = false; |
| 59 | while (std::getline(textFile, line) && !mustStop) |
| 60 | { |
| 61 | std::string trimmed = trim(line); |
| 62 | if (trimmed[0] == '[') |
| 63 | mustStop = true; |
| 64 | else if (!trimmed.empty()) |
| 65 | textMap.insert(split(trimmed)); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | } // end namespace tools |
nothing calls this directly
no outgoing calls
no test coverage detected