Parser: Function to exstract 'commands'/attributes (e. g. visible, renaming)

This commit is contained in:
Albert S. 2018-11-04 19:33:06 +01:00
parent 667776e3d7
commit 6ec857cf86
3 changed files with 17 additions and 0 deletions

View File

@ -8,6 +8,7 @@
class IParser class IParser
{ {
public: public:
virtual std::string extractCommand(std::string cmdname, std::string content) const = 0 ;
virtual std::vector<Headline> extractHeadlines(std::string content) const = 0; virtual std::vector<Headline> extractHeadlines(std::string content) const = 0;
virtual std::string parse(const PageDao &pagedao, UrlProvider &provider, std::string content) const = 0; virtual std::string parse(const PageDao &pagedao, UrlProvider &provider, std::string content) const = 0;
virtual std::vector<std::string> extractCategories(std::string content) const = 0; virtual std::vector<std::string> extractCategories(std::string content) const = 0;

View File

@ -63,6 +63,19 @@ std::vector<std::string> Parser::extractCategories(std::string content) const
} }
return result; return result;
} }
std::string Parser::extractCommand(std::string cmdname, std::string content) const
{
std::string regstr = "(\\s|\\S)*\\[cmd\\:" + cmdname + "\\](.*?)\\[/cmd\\:" + cmdname + "\\](\\s|\\S)*";
std::regex reg { regstr };
std::smatch match;
if(std::regex_match(content, match, reg))
{
return match.str(2);
}
return "";
}
std::string Parser::processLink(const PageDao &pageDao, UrlProvider &urlProvider, std::smatch &match) const std::string Parser::processLink(const PageDao &pageDao, UrlProvider &urlProvider, std::smatch &match) const
{ {
std::string linktag = match.str(1); std::string linktag = match.str(1);
@ -98,6 +111,8 @@ std::string Parser::processLink(const PageDao &pageDao, UrlProvider &urlProvider
return htmllink.render(); return htmllink.render();
} }
std::string Parser::parse(const PageDao &pagedao, UrlProvider &provider, std::string content) const std::string Parser::parse(const PageDao &pagedao, UrlProvider &provider, std::string content) const
{ {
std::string result; std::string result;

View File

@ -9,6 +9,7 @@ class Parser : public IParser
private: private:
std::string processLink(const PageDao &pageDao, UrlProvider &urlProvider, std::smatch &match) const; std::string processLink(const PageDao &pageDao, UrlProvider &urlProvider, std::smatch &match) const;
public: public:
std::string extractCommand(std::string cmdname, std::string content) const ;
std::vector<Headline> extractHeadlines(std::string content) const override ; std::vector<Headline> extractHeadlines(std::string content) const override ;
std::vector<std::string> extractCategories(std::string content) const override; std::vector<std::string> extractCategories(std::string content) const override;
std::string parse(const PageDao &pagedao, UrlProvider &provider, std::string content) const override; std::string parse(const PageDao &pagedao, UrlProvider &provider, std::string content) const override;