MCPcopy Create free account
hub / github.com/Blizzard/s2client-api / LoadFile

Method LoadFile

src/sc2utils/sc2_property_reader.cc:25–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23}
24
25bool PropertyReader::LoadFile(const std::string& file_name) {
26 file_read_ = false;
27 properties_.clear();
28
29 std::ifstream file(file_name);
30 if (!file.is_open()) {
31 return false;
32 }
33 file_read_ = true;
34
35 std::string line;
36 while (std::getline(file, line)) {
37 // If first character on line is # assume comment, if it's blank assume malformed/incorrect/empty line and skip it
38 if (line[0] == '#' || line[0] == ' ' || line.empty() || line.length() < 2)
39 continue;
40
41 std::string key;
42 std::string value;
43 unsigned int index = 0;
44 size_t equal_index = line.find_first_of('=');
45 // Extract key
46 for (; index < equal_index; ++index) {
47 // Spaces are allowed in key except in the last character
48 if (index == equal_index - 1 && line[index] == ' ')
49 continue;
50
51 key += line[index];
52 }
53
54 // Extract value
55 for (index = (unsigned int) equal_index + 1; index < line.size(); ++index) {
56 // Spaces are allowed in value except in the first character
57 if (index == equal_index + 1 && line[index] == ' ')
58 continue;
59
60 value += line[index];
61 }
62
63 properties_[key] = value;
64 }
65 file.close();
66 return true;
67}
68
69void PropertyReader::Free() {
70 properties_.clear();

Callers 1

ParseFromFileFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected