I'm going to do shit

This commit is contained in:
Thomas 2022-01-02 15:56:30 +01:00
parent 51866120f2
commit ff258e6aeb
No known key found for this signature in database
GPG Key ID: E538821A6CDFDAD7
2 changed files with 18 additions and 6 deletions

View File

@ -41,6 +41,6 @@ points:
invader1: 600
grid:
- AAAAAAAAAA
- BBBB BBBBB
- CCCCCCCCCC
- "AAAAAAAAAA"
- " BBB BBB "
- "CCCCCCCCCC"

View File

@ -26,8 +26,20 @@ void trimSpaces(string& str){
str.erase(0, str.find_first_not_of(' '));
}
void sanitizeValue(string& val) {
trimSpaces(val);
for (char c: {'\'', '"'}) {
if (val[0] == c && val[val.size() - 1] == c) {
val.erase(val.begin());
val.pop_back();
break;
}
}
}
/*
* WARNING : This implementation of YAML is not meant to detect and report errors in a non YAML-compliant file
* WARNING : This implementation of YAML is not meant to be complete, but to work with our specific needs
* It also can't detect and report errors in a non YAML-compliant file
*/
void ConfigBuilder::parseFile(const string& fname) {
@ -48,7 +60,7 @@ void ConfigBuilder::parseFile(const string& fname) {
if(line[currentIndent]=='-'){
string value = line.substr(currentIndent+1);
trimSpaces(value);
sanitizeValue(value);
string fullKey;
for (unsigned i = 0; i < currentIndent; ++i) {
@ -66,7 +78,7 @@ void ConfigBuilder::parseFile(const string& fname) {
string key = line.substr(0, match);
string value = line.substr(match + 1);
trimSpaces(key);
trimSpaces(value);
sanitizeValue(value);
if (value.empty()) {
keyParts.resize(currentIndent);
keyParts.push_back(key);