/
Boxapp
/
yadisk-helper
Обзор
Документация
Войти
/
Boxapp
/
yadisk-helper
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
parser.cpp
34 строки
1 KB
DebianCougar
test build 2026.02-beta
30 янв 2026, 21:25
30 янв 2026, 21:25
eb3551d
Код
Авторство
О чём код?
#include <fstream> #include "parser.hpp" #include "tokenizer.hpp" ConfigMap get_config(const std::string &filename) { std::ifstream reader(filename); Config conf = tokenize(reader); ConfigMap res; for (const Line &line : conf) { size_t n = line.size(); if (n < 3) throw std::length_error("Too few arguments"); if (n > 3) throw std::length_error("Too many arguments"); if (line[0].type == NAME_TOKEN && line[1].type == OPER_TOKEN && line[2].type == NAME_TOKEN) res[line[0].value] = line[2].value; else throw std::invalid_argument("Arguments must be param = value"); } return res; } ConfigLines parse(const std::string &filename) { std::ifstream reader(filename); Config conf = tokenize(reader); ConfigLines res; for (const Line &line : conf) { size_t n = line.size(); if (n < 3) throw std::length_error("Too few arguments"); if (n > 3) throw std::length_error("Too many arguments"); if (line[0].type == NAME_TOKEN && line[1].type == OPER_TOKEN && line[2].type == NAME_TOKEN) res.push_back({line[0].value, line[2].value}); else throw std::invalid_argument("Arguments must be param = value"); } return res; }