From 60ea89a36e2a0258f060aabbcbe435ed1d33b33a Mon Sep 17 00:00:00 2001 From: Maƫl Gassmann Date: Wed, 2 Mar 2022 16:05:57 +0100 Subject: [~] Fixed date parsing issue --- src/FileAssembler.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/FileAssembler.cpp b/src/FileAssembler.cpp index cc8cc98..7a64846 100644 --- a/src/FileAssembler.cpp +++ b/src/FileAssembler.cpp @@ -122,13 +122,10 @@ string FileAssembler::parse(string title, string to_parse, bool is_post){ // Parsing variables and functions size_t pos_first = 0; size_t pos_second = 0; - while ((pos_first = parsed.find("$")) != string::npos){ - if((pos_second = parsed.find("$", pos_first+1)) == string::npos){ - cerr << "Error: swg: unclosed $ section in " << title << "." << endl; - } - string input = parsed.substr(pos_first+1, pos_second-pos_first-1); - //cout << pos_first << " + " << pos_second << "=" << input << endl; - + static std::regex r_expression("\\$([^\\$]*)\\$"); + std::smatch m_expression; + while (regex_search(parsed, m_expression, r_expression)){ + string input = m_expression[1]; //Group 1 ie. without the dollars string output = ""; if(input == "title") //TITLE @@ -168,12 +165,12 @@ string FileAssembler::parse(string title, string to_parse, bool is_post){ } else if(input.substr(0,5) == "list_"){ //LISTINGS string name = ""; int arg = -1; - static std::regex rgx("\\_([a-z]*)(\\((\\d*)\\))?"); - std::smatch match; - if (std::regex_search(input, match, rgx)){ - name = match[1]; - if(match[3] != "") - arg = stoi(match[3]); + static std::regex r_listing("\\_([a-z]*)(\\((\\d*)\\))?"); + std::smatch m_listing; + if (std::regex_search(input, m_listing, r_listing)){ + name = m_listing[1]; + if(m_listing[3] != "") + arg = stoi(m_listing[3]); } string list_template = name + "_listing.html"; @@ -223,7 +220,10 @@ string FileAssembler::parse(string title, string to_parse, bool is_post){ cerr << "Error: swg: Invalid swg text section: \"" << input << "\"." << endl; exit(4); } - parsed.replace(pos_first,pos_second-pos_first+1, output); + //cout << "BEFORE:" << endl << parsed << endl << endl; + parsed = regex_replace(parsed, r_expression, output, regex_constants::format_first_only); + //cout << "AFTER:" << endl << parsed << endl ; + //cout << endl << "----------------------------------------------------" << endl << endl; } return parsed; } -- cgit v1.2.3