Parser: Take 'content' by const reference.

This commit is contained in:
Albert S. 2022-01-23 10:12:37 +01:00
父節點 1d5bf80710
當前提交 b2a7ea4031
共有 3 個文件被更改,包括 12 次插入12 次删除

查看文件

@ -8,10 +8,10 @@
class IParser
{
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::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::string extractCommand(std::string cmdname, const std::string &content) const = 0;
virtual std::vector<Headline> extractHeadlines(const std::string &content) const = 0;
virtual std::string parse(const PageDao &pagedao, UrlProvider &provider, const std::string &content) const = 0;
virtual std::vector<std::string> extractCategories(const std::string &content) const = 0;
virtual ~IParser(){};
};

查看文件

@ -27,7 +27,7 @@ SOFTWARE.
#include "parser.h"
#include "utils.h"
#include "htmllink.h"
std::vector<Headline> Parser::extractHeadlines(std::string content) const
std::vector<Headline> Parser::extractHeadlines(const std::string &content) const
{
std::vector<Headline> result;
std::string reg = R"(\[h(1|2|3)\](.*?)\[/h\1\])";
@ -46,7 +46,7 @@ std::vector<Headline> Parser::extractHeadlines(std::string content) const
return result;
}
std::vector<std::string> Parser::extractCategories(std::string content) const
std::vector<std::string> Parser::extractCategories(const std::string &content) const
{
std::vector<std::string> result;
std::string reg = R"(\[category\](.*?)\[/category\])";
@ -62,7 +62,7 @@ std::vector<std::string> Parser::extractCategories(std::string content) const
return result;
}
std::string Parser::extractCommand(std::string cmdname, std::string content) const
std::string Parser::extractCommand(std::string cmdname, const std::string &content) const
{
std::string cmd = "[cmd:" + cmdname + "]";
std::string cmdend = "[/cmd:" + cmdname + "]";
@ -116,7 +116,7 @@ std::string Parser::processLink(const PageDao &pageDao, UrlProvider &urlProvider
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, const std::string &content) const
{
std::string result;
// we don't care about commands, but we nevertheless replace them with empty strings

查看文件

@ -8,10 +8,10 @@ class Parser : public IParser
std::string processLink(const PageDao &pageDao, UrlProvider &urlProvider, std::smatch &match) const;
public:
std::string extractCommand(std::string cmdname, std::string content) const;
std::vector<Headline> extractHeadlines(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 extractCommand(std::string cmdname, const std::string &content) const;
std::vector<Headline> extractHeadlines(const std::string &content) const override;
std::vector<std::string> extractCategories(const std::string &content) const override;
std::string parse(const PageDao &pagedao, UrlProvider &provider, const std::string &content) const override;
using IParser::IParser;
~Parser(){};
};