-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheloadtexthelper.cpp
executable file
·36 lines (32 loc) · 1.14 KB
/
eloadtexthelper.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "eloadtexthelper.h"
#include <fstream>
#include <algorithm>
bool eLoadTextHelper::load(const std::string& path, eMap& map) {
std::ifstream file(path);
if(!file.good()) {
printf("File missing %s\n", path.c_str());
return false;
}
std::string str;
while(std::getline(file, str)) {
if(str.empty()) continue;
if(str.front() == '\r') continue;
if(str.front() == '\t') continue;
if(str.front() == ';') {
if(str.size() < 7) continue;
if(str.substr(1, 6) != "PHRASE") continue;
}
const auto keyEnd1 = str.find(' ');
const auto keyEnd2 = str.find('\t');
const auto keyEnd = std::min(keyEnd1, keyEnd2);
if(keyEnd == std::string::npos) continue;
const auto key = str.substr(0, keyEnd);
const auto valueStart = str.find('"');
if(valueStart == std::string::npos) continue;
const auto valueEnd = str.find('"', valueStart + 1);
const auto valueLen = valueEnd - valueStart;
const auto value = str.substr(valueStart + 1, valueLen - 1);
map[key] = value;
}
return true;
}