Remove getNextLine function from class definition

This commit is contained in:
Joshua Baker 2024-12-26 20:35:25 -06:00
parent 8cade6ebc0
commit 784f6b97de
3 changed files with 32 additions and 30 deletions

View file

@ -10,7 +10,6 @@
#include <vector>
#include <print>
#include <cstdlib>
#include <expected>
class CConfigImpl;
struct SConfigDefaultValue;
@ -447,12 +446,6 @@ namespace Hyprlang {
CConfigImpl* impl;
enum eGetNextLineFailure : uint8_t {
GETNEXTLINEFAILURE_EOF = 0,
GETNEXTLINEFAILURE_BACKSLASH,
};
std::expected<std::string, eGetNextLineFailure> getNextLine(std::istream& str, int &rawLineNum, int &lineNum);
CParseResult parseLine(std::string line, bool dynamic = false);
CParseResult configSetValueSafe(const std::string& command, const std::string& value);
CParseResult parseVariable(const std::string& lhs, const std::string& rhs, bool dynamic = false);

View file

@ -37,6 +37,30 @@ static size_t seekABIStructSize(const void* begin, size_t startOffset, size_t ma
return 0;
}
static std::expected<std::string, eGetNextLineFailure> getNextLine(std::istream& str, int &rawLineNum, int &lineNum) {
std::string line = "";
std::string nextLine = "";
if (!std::getline(str, line))
return std::unexpected(GETNEXTLINEFAILURE_EOF);
lineNum = ++rawLineNum;
while (line.length() > 0 && line.at(line.length() - 1) == '\\') {
const auto lastNonSpace = line.length() < 2 ? -1 : line.find_last_not_of(MULTILINE_SPACE_CHARSET, line.length() - 2);
line = line.substr(0, lastNonSpace + 1);
if (!std::getline(str, nextLine))
return std::unexpected(GETNEXTLINEFAILURE_BACKSLASH);
++rawLineNum;
line += nextLine;
}
return line;
}
CConfig::CConfig(const char* path, const Hyprlang::SConfigOptions& options_) {
SConfigOptions options;
std::memcpy(&options, &options_, seekABIStructSize(&options_, 16, sizeof(SConfigOptions)));
@ -797,29 +821,6 @@ CParseResult CConfig::parseFile(const char* file) {
return result;
}
std::expected<std::string, CConfig::eGetNextLineFailure> CConfig::getNextLine(std::istream& str, int &rawLineNum, int &lineNum) {
std::string line = "";
std::string nextLine = "";
if (!std::getline(str, line))
return std::unexpected(GETNEXTLINEFAILURE_EOF);
lineNum = ++rawLineNum;
while (line.length() > 0 && line.at(line.length() - 1) == '\\') {
const auto lastNonSpace = line.length() < 2 ? -1 : line.find_last_not_of(MULTILINE_SPACE_CHARSET, line.length() - 2);
line = line.substr(0, lastNonSpace + 1);
if (!std::getline(str, nextLine))
return std::unexpected(GETNEXTLINEFAILURE_BACKSLASH);
++rawLineNum;
line += nextLine;
}
return line;
}
CParseResult CConfig::parseDynamic(const char* line) {
return parseLine(line, true);
}

View file

@ -4,6 +4,7 @@
#include <string>
#include <vector>
#include <memory>
#include <expected>
struct SHandler {
std::string name = "";
@ -65,6 +66,13 @@ struct SSpecialCategory {
size_t anonymousID = 0;
};
enum eGetNextLineFailure : uint8_t {
GETNEXTLINEFAILURE_EOF = 0,
GETNEXTLINEFAILURE_BACKSLASH,
};
static std::expected<std::string, eGetNextLineFailure> getNextLine(std::istream& str, int &rawLineNum, int &lineNum);
class CConfigImpl {
public:
std::string path = "";