From 784f6b97de1d0b3e5d6fcd5c3671a36880cce63e Mon Sep 17 00:00:00 2001 From: Joshua Baker Date: Thu, 26 Dec 2024 20:35:25 -0600 Subject: [PATCH] Remove getNextLine function from class definition --- include/hyprlang.hpp | 7 ------- src/config.cpp | 47 ++++++++++++++++++++++---------------------- src/config.hpp | 8 ++++++++ 3 files changed, 32 insertions(+), 30 deletions(-) diff --git a/include/hyprlang.hpp b/include/hyprlang.hpp index 39ed97a..457feca 100644 --- a/include/hyprlang.hpp +++ b/include/hyprlang.hpp @@ -10,7 +10,6 @@ #include #include #include -#include class CConfigImpl; struct SConfigDefaultValue; @@ -447,12 +446,6 @@ namespace Hyprlang { CConfigImpl* impl; - enum eGetNextLineFailure : uint8_t { - GETNEXTLINEFAILURE_EOF = 0, - GETNEXTLINEFAILURE_BACKSLASH, - }; - - std::expected 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); diff --git a/src/config.cpp b/src/config.cpp index d2f60bf..d879c34 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -37,6 +37,30 @@ static size_t seekABIStructSize(const void* begin, size_t startOffset, size_t ma return 0; } +static std::expected 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 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); } diff --git a/src/config.hpp b/src/config.hpp index a2f2014..77815c8 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -4,6 +4,7 @@ #include #include #include +#include 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 getNextLine(std::istream& str, int &rawLineNum, int &lineNum); + class CConfigImpl { public: std::string path = "";