From 1bb8e7ee49c2f638beb7165a51be1c35eaa820d7 Mon Sep 17 00:00:00 2001 From: DRAGONTOS Date: Mon, 21 Oct 2024 23:02:11 +0200 Subject: [PATCH] Regex: removed output file and instead used a string --- line-count | 6 +- src/Regex.cpp | 116 +++++++++++++++++------------------ src/includes/Regex.hpp | 8 ++- src/includes/maincommand.hpp | 5 ++ src/main.cpp | 19 +----- src/maincommand.cpp | 102 ++++++++++++++++++++++++++++++ 6 files changed, 175 insertions(+), 81 deletions(-) create mode 100644 src/includes/maincommand.hpp create mode 100644 src/maincommand.cpp diff --git a/line-count b/line-count index 7dab676..8649f46 100644 --- a/line-count +++ b/line-count @@ -1,8 +1,8 @@ =============================================================================== Language Files Lines Code Comments Blanks =============================================================================== - C++ 3 299 225 26 48 - C++ Header 3 51 43 1 7 + C++ 4 383 308 26 49 + C++ Header 4 67 56 1 10 =============================================================================== - Total 6 350 268 27 55 + Total 8 450 364 27 59 =============================================================================== diff --git a/src/Regex.cpp b/src/Regex.cpp index a74858c..e0a447a 100644 --- a/src/Regex.cpp +++ b/src/Regex.cpp @@ -1,77 +1,73 @@ -#include -#include -#include -#include #include -#include #include -#include #include +#include #include "regex" #include "includes/Regex.hpp" // regex and stuff (collectionid) void Regex(cmd *inputCmd) { - if (!inputCmd->collectionid.empty()) { - // Input and output file paths - std::string inputFilePath = inputCmd->cachesc; - std::string outputFilePath = inputCmd->cacheid; + if (!inputCmd->collectionid.empty()) { + // Input and output file paths + std::string inputFilePath = inputCmd->cachesc; // Path to the input file - // Open the input file (source.html) - std::ifstream inputFile(inputFilePath); - std::ofstream outputFile(outputFilePath, std::ios::app); + // Open the input file + std::ifstream inputFile(inputFilePath); - if (!inputFile.is_open() && !outputFile.is_open()) { - throw("Unable to open file\n"); + // Check if the input file is open + if (!inputFile.is_open()) { + throw std::runtime_error("Unable to open file: " + inputFilePath); + } + + // Regex to search for the desired pattern + std::regex grepRegex(R"(