use std::string literals in generated code

This commit is contained in:
Günter Obiltschnig 2020-02-10 09:24:18 +01:00
parent 646a80a1fb
commit 1be791a8aa
3 changed files with 13 additions and 13 deletions

View File

@ -68,7 +68,7 @@ void CodeWriter::writeImpl(std::ostream& ostr, const std::string& headerFileName
ostr << "#include \"Poco/StreamCopier.h\"\n";
ostr << "#include <sstream>\n";
}
ostr << "\n\n";
ostr << "\n\nusing namespace std::string_literals;\n\n";
std::string decls(_page.implDecls().str());
if (!decls.empty())
@ -328,24 +328,24 @@ void CodeWriter::writeResponse(std::ostream& ostr)
ostr << "\tresponse.setChunkedTransferEncoding(true);\n";
}
ostr << "\tresponse.setContentType(\"" << contentType << "\");\n";
ostr << "\tresponse.setContentType(\"" << contentType << "\"s);\n";
if (!contentLang.empty())
{
ostr << "\tif (request.has(\"Accept-Language\"))\n"
<< "\t\tresponse.set(\"Content-Language\", \"" << contentLang << "\");\n";
ostr << "\tif (request.has(\"Accept-Language\"s))\n"
<< "\t\tresponse.set(\"Content-Language\"s, \"" << contentLang << "\"s);\n";
}
if (!contentSecurityPolicy.empty())
{
ostr << "\tresponse.set(\"Content-Secure-Policy\", \"" << contentSecurityPolicy << "\");\n";
ostr << "\tresponse.set(\"Content-Secure-Policy\"s, \"" << contentSecurityPolicy << "\"s);\n";
}
if (compressed)
{
ostr << "\tbool _compressResponse(request.hasToken(\"Accept-Encoding\", \"gzip\"));\n"
<< "\tif (_compressResponse) response.set(\"Content-Encoding\", \"gzip\");\n";
ostr << "\tbool _compressResponse(request.hasToken(\"Accept-Encoding\"s, \"gzip\"s));\n"
<< "\tif (_compressResponse) response.set(\"Content-Encoding\"s, \"gzip\"s);\n";
}
if (!cacheControl.empty())
{
ostr << "\tresponse.set(\"Cache-Control\", \"" << cacheControl << "\");\n";
ostr << "\tresponse.set(\"Cache-Control\"s, \"" << cacheControl << "\"s);\n";
}
ostr << "\n";
}

View File

@ -107,14 +107,14 @@ void OSPCodeWriter::writeSession(std::ostream& ostr)
std::string sessionCode;
if (session.empty()) return;
if (session[0] == '@')
sessionCode = "context()->thisBundle()->properties().getString(\"" + session.substr(1) + "\")";
sessionCode = "context()->thisBundle()->properties().getString(\"" + session.substr(1) + "\"s)";
else
sessionCode = "\"" + session + "\"";
sessionCode = "\"" + session + "\"s";
std::string sessionTimeoutCode = page().get("page.sessionTimeout", "30");
int sessionTimeout;
if (!Poco::NumberParser::tryParse(sessionTimeoutCode, sessionTimeout))
{
sessionTimeoutCode = "context()->thisBundle()->properties().getInt(\"" + sessionTimeoutCode + "\")";
sessionTimeoutCode = "context()->thisBundle()->properties().getInt(\"" + sessionTimeoutCode + "\"s)";
}
ostr << "\tPoco::OSP::Web::WebSession::Ptr session;\n";
ostr << "\t{\n";

View File

@ -35,7 +35,7 @@ public:
~PageReader();
/// Destroys the PageReader.
void parse(std::istream& pageStream);
void parse(std::istream& pageStream);
/// Parses a HTML file containing server page directives,
/// converts the file into C++ code and adds the code
/// to the reader's Page object. Also parses page
@ -74,7 +74,7 @@ protected:
protected:
void generateLineDirective(std::ostream& ostr);
private:
PageReader();
PageReader(const PageReader&);