diff options
-rw-r--r-- | inc/FileAssembler.h | 2 | ||||
-rw-r--r-- | src/FileAssembler.cpp | 28 |
2 files changed, 15 insertions, 15 deletions
diff --git a/inc/FileAssembler.h b/inc/FileAssembler.h index 1a37207..0ae61df 100644 --- a/inc/FileAssembler.h +++ b/inc/FileAssembler.h @@ -27,7 +27,7 @@ private: map<string, string> assemble_from_iterator(map<string, string>::iterator it, map<string, string>::iterator end, bool is_post); string parse(string title, string content, bool is_post); static string parse_arg(string to_parse){ - static std::regex rgx("\\w+\\((.*)\\)"); + static std::regex rgx("\\w+\\(([^\\)\\$]*)\\)"); std::smatch match; if (std::regex_search(to_parse, match, rgx)) return match[1]; 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; } |