LangBuilder/src/LocalizationFile.cpp

38 lines
1.1 KiB
C++

#include "LocalizationFile.hpp"
#include <fstream>
#include <iostream>
void LocalizationFile::LoadFile(const std::filesystem::path& path) {
if (!std::filesystem::exists(path)) {
std::stringstream ss;
ss << "File at path " << path << " does not exist.";
throw std::logic_error(ss.str());
}
std::ifstream file;
file.open(path, std::ios::in);
if (!file.is_open()) {
std::stringstream ss;
ss << "Something went wrong opening file at path " << path;
throw std::logic_error(ss.str());
}
std::string line;
char sep = ',';
bool firstLine = true;
while (std::getline(file, line)) {
if (firstLine) {
firstLine = false;
if (line.substr(0, 4) == "sep=") {
sep = line[4];
continue;
}
}
std::string key;
std::string value;
std::stringstream linestream(line);
std::getline(linestream, key, sep);
std::getline(linestream, value, sep);
_map[key] = value;
}
file.close();
}