enh: #4216: use std::string literals

This commit is contained in:
Günter Obiltschnig 2024-01-30 09:35:35 +01:00
parent d3525945bd
commit 33638df51e
16 changed files with 215 additions and 177 deletions

View File

@ -32,6 +32,9 @@
#include "Poco/PatternFormatter.h"
using namespace std::string_literals;
namespace Poco {
@ -84,37 +87,37 @@ LoggingFactory& LoggingFactory::defaultFactory()
void LoggingFactory::registerBuiltins()
{
_channelFactory.registerClass("AsyncChannel", new Instantiator<AsyncChannel, Channel>);
_channelFactory.registerClass("AsyncChannel"s, new Instantiator<AsyncChannel, Channel>);
#if defined(POCO_OS_FAMILY_WINDOWS)
_channelFactory.registerClass("ConsoleChannel", new Instantiator<WindowsConsoleChannel, Channel>);
_channelFactory.registerClass("ColorConsoleChannel", new Instantiator<WindowsColorConsoleChannel, Channel>);
_channelFactory.registerClass("ConsoleChannel"s, new Instantiator<WindowsConsoleChannel, Channel>);
_channelFactory.registerClass("ColorConsoleChannel"s, new Instantiator<WindowsColorConsoleChannel, Channel>);
#else
_channelFactory.registerClass("ConsoleChannel", new Instantiator<ConsoleChannel, Channel>);
_channelFactory.registerClass("ColorConsoleChannel", new Instantiator<ColorConsoleChannel, Channel>);
_channelFactory.registerClass("ConsoleChannel"s, new Instantiator<ConsoleChannel, Channel>);
_channelFactory.registerClass("ColorConsoleChannel"s, new Instantiator<ColorConsoleChannel, Channel>);
#endif
#ifndef POCO_NO_FILECHANNEL
_channelFactory.registerClass("FileChannel", new Instantiator<FileChannel, Channel>);
_channelFactory.registerClass("SimpleFileChannel", new Instantiator<SimpleFileChannel, Channel>);
_channelFactory.registerClass("FileChannel"s, new Instantiator<FileChannel, Channel>);
_channelFactory.registerClass("SimpleFileChannel"s, new Instantiator<SimpleFileChannel, Channel>);
#endif
_channelFactory.registerClass("FormattingChannel", new Instantiator<FormattingChannel, Channel>);
_channelFactory.registerClass("FormattingChannel"s, new Instantiator<FormattingChannel, Channel>);
#ifndef POCO_NO_SPLITTERCHANNEL
_channelFactory.registerClass("SplitterChannel", new Instantiator<SplitterChannel, Channel>);
_channelFactory.registerClass("SplitterChannel"s, new Instantiator<SplitterChannel, Channel>);
#endif
_channelFactory.registerClass("NullChannel", new Instantiator<NullChannel, Channel>);
_channelFactory.registerClass("EventChannel", new Instantiator<EventChannel, Channel>);
_channelFactory.registerClass("NullChannel"s, new Instantiator<NullChannel, Channel>);
_channelFactory.registerClass("EventChannel"s, new Instantiator<EventChannel, Channel>);
#if defined(POCO_OS_FAMILY_UNIX)
#ifndef POCO_NO_SYSLOGCHANNEL
_channelFactory.registerClass("SyslogChannel", new Instantiator<SyslogChannel, Channel>);
_channelFactory.registerClass("SyslogChannel"s, new Instantiator<SyslogChannel, Channel>);
#endif
#endif
#if defined(POCO_OS_FAMILY_WINDOWS)
_channelFactory.registerClass("EventLogChannel", new Instantiator<EventLogChannel, Channel>);
_channelFactory.registerClass("EventLogChannel"s, new Instantiator<EventLogChannel, Channel>);
#endif
_formatterFactory.registerClass("PatternFormatter", new Instantiator<PatternFormatter, Formatter>);
_formatterFactory.registerClass("PatternFormatter"s, new Instantiator<PatternFormatter, Formatter>);
}

View File

@ -21,10 +21,12 @@
#include <sys/types.h>
#include <climits>
#if !defined(POCO_VXWORKS)
#include <pwd.h>
#endif
#if POCO_OS == POCO_OS_MAC_OS_X
#include <mach-o/dyld.h>
#elif POCO_OS == POCO_OS_FREE_BSD
@ -38,8 +40,13 @@
#define PATH_MAX 4096 // fallback
#endif
using namespace std::string_literals;
namespace Poco {
std::string PathImpl::selfImpl()
{
std::string path;
@ -115,9 +122,9 @@ std::string PathImpl::homeImpl()
else return "/";
#else
std::string path;
if (EnvironmentImpl::hasImpl("HOME"))
if (EnvironmentImpl::hasImpl("HOME"s))
{
path = EnvironmentImpl::getImpl("HOME");
path = EnvironmentImpl::getImpl("HOME"s);
}
else
{
@ -154,8 +161,8 @@ std::string PathImpl::configHomeImpl()
return path;
#else
std::string path;
if (EnvironmentImpl::hasImpl("XDG_CONFIG_HOME"))
path = EnvironmentImpl::getImpl("XDG_CONFIG_HOME");
if (EnvironmentImpl::hasImpl("XDG_CONFIG_HOME"s))
path = EnvironmentImpl::getImpl("XDG_CONFIG_HOME"s);
if (!path.empty())
return path;
@ -181,8 +188,8 @@ std::string PathImpl::dataHomeImpl()
return path;
#else
std::string path;
if (EnvironmentImpl::hasImpl("XDG_DATA_HOME"))
path = EnvironmentImpl::getImpl("XDG_DATA_HOME");
if (EnvironmentImpl::hasImpl("XDG_DATA_HOME"s))
path = EnvironmentImpl::getImpl("XDG_DATA_HOME"s);
if (!path.empty())
return path;
@ -208,8 +215,8 @@ std::string PathImpl::cacheHomeImpl()
return path;
#else
std::string path;
if (EnvironmentImpl::hasImpl("XDG_CACHE_HOME"))
path = EnvironmentImpl::getImpl("XDG_CACHE_HOME");
if (EnvironmentImpl::hasImpl("XDG_CACHE_HOME"s))
path = EnvironmentImpl::getImpl("XDG_CACHE_HOME"s);
if (!path.empty())
return path;

View File

@ -25,6 +25,9 @@
#include <memory>
using namespace std::string_literals;
namespace Poco {
namespace Net {
@ -73,7 +76,7 @@ void HTTPServerConnection::run()
response.setVersion(request.getVersion());
response.setKeepAlive(_pParams->getKeepAlive() && request.getKeepAlive() && session.canKeepAlive());
if (!server.empty())
response.set("Server", server);
response.set("Server"s, server);
try
{
session.requestTrailer().clear();

View File

@ -37,6 +37,7 @@ using Poco::StreamCopier;
using Poco::OpenFileException;
using Poco::DateTimeFormatter;
using Poco::DateTimeFormat;
using namespace std::string_literals;
namespace Poco {
@ -112,7 +113,7 @@ void HTTPServerResponseImpl::sendFile(const std::string& path, const std::string
File f(path);
Timestamp dateTime = f.getLastModified();
File::FileSize length = f.getSize();
set("Last-Modified", DateTimeFormatter::format(dateTime, DateTimeFormat::HTTP_FORMAT));
set("Last-Modified"s, DateTimeFormatter::format(dateTime, DateTimeFormat::HTTP_FORMAT));
#if defined(POCO_HAVE_INT64)
setContentLength64(length);
#else
@ -159,7 +160,7 @@ void HTTPServerResponseImpl::redirect(const std::string& uri, HTTPStatus status)
setChunkedTransferEncoding(false);
setStatusAndReason(status);
set("Location", uri);
set("Location"s, uri);
_pStream = new HTTPHeaderOutputStream(_session);
write(*_pStream);
@ -174,7 +175,7 @@ void HTTPServerResponseImpl::requireAuthentication(const std::string& realm)
std::string auth("Basic realm=\"");
auth.append(realm);
auth.append("\"");
set("WWW-Authenticate", auth);
set("WWW-Authenticate"s, auth);
}

View File

@ -32,6 +32,7 @@ using Poco::URIStreamFactory;
using Poco::URI;
using Poco::URIStreamOpener;
using Poco::UnbufferedStreamBuf;
using namespace std::string_literals;
namespace Poco {
@ -115,11 +116,11 @@ std::istream* HTTPStreamFactory::open(const URI& uri)
cred.authenticate(req, res);
}
req.set("User-Agent", Poco::format("poco/%d.%d.%d",
req.set("User-Agent"s, Poco::format("poco/%d.%d.%d"s,
(POCO_VERSION >> 24) & 0xFF,
(POCO_VERSION >> 16) & 0xFF,
(POCO_VERSION >> 8) & 0xFF));
req.set("Accept", "*/*");
req.set("Accept"s, "*/*"s);
pSession->sendRequest(req);
std::istream& rs = pSession->receiveResponse(res);
@ -129,7 +130,7 @@ std::istream* HTTPStreamFactory::open(const URI& uri)
res.getStatus() == HTTPResponse::HTTP_TEMPORARY_REDIRECT);
if (moved)
{
resolvedURI.resolve(res.get("Location"));
resolvedURI.resolve(res.get("Location"s));
if (!username.empty())
{
resolvedURI.setUserInfo(username + ":" + password);
@ -147,7 +148,7 @@ std::istream* HTTPStreamFactory::open(const URI& uri)
// URI of the proxy. The recipient is expected to repeat this
// single request via the proxy. 305 responses MUST only be generated by origin servers.
// only use for one single request!
proxyUri.resolve(res.get("Location"));
proxyUri.resolve(res.get("Location"s));
delete pSession;
pSession = 0;
retry = true; // only allow useproxy once
@ -174,13 +175,13 @@ std::istream* HTTPStreamFactory::open(const URI& uri)
void HTTPStreamFactory::registerFactory()
{
URIStreamOpener::defaultOpener().registerStreamFactory("http", new HTTPStreamFactory);
URIStreamOpener::defaultOpener().registerStreamFactory("http"s, new HTTPStreamFactory);
}
void HTTPStreamFactory::unregisterFactory()
{
URIStreamOpener::defaultOpener().unregisterStreamFactory("http");
URIStreamOpener::defaultOpener().unregisterStreamFactory("http"s);
}

View File

@ -30,6 +30,9 @@
#include <sstream>
using namespace std::string_literals;
namespace Poco {
namespace Net {
@ -192,19 +195,19 @@ int WebSocket::getMaxPayloadSize() const
WebSocketImpl* WebSocket::accept(HTTPServerRequest& request, HTTPServerResponse& response)
{
if (request.hasToken("Connection", "upgrade") && icompare(request.get("Upgrade", ""), "websocket") == 0)
if (request.hasToken("Connection"s, "upgrade"s) && icompare(request.get("Upgrade"s, ""s), "websocket"s) == 0)
{
std::string version = request.get("Sec-WebSocket-Version", "");
std::string version = request.get("Sec-WebSocket-Version"s, ""s);
if (version.empty()) throw WebSocketException("Missing Sec-WebSocket-Version in handshake request", WS_ERR_HANDSHAKE_NO_VERSION);
if (version != WEBSOCKET_VERSION) throw WebSocketException("Unsupported WebSocket version requested", version, WS_ERR_HANDSHAKE_UNSUPPORTED_VERSION);
std::string key = request.get("Sec-WebSocket-Key", "");
std::string key = request.get("Sec-WebSocket-Key"s, ""s);
Poco::trimInPlace(key);
if (key.empty()) throw WebSocketException("Missing Sec-WebSocket-Key in handshake request", WS_ERR_HANDSHAKE_NO_KEY);
response.setStatusAndReason(HTTPResponse::HTTP_SWITCHING_PROTOCOLS);
response.set("Upgrade", "websocket");
response.set("Connection", "Upgrade");
response.set("Sec-WebSocket-Accept", computeAccept(key));
response.set("Upgrade"s, "websocket"s);
response.set("Connection"s, "Upgrade"s);
response.set("Sec-WebSocket-Accept"s, computeAccept(key));
response.setContentLength(HTTPResponse::UNKNOWN_CONTENT_LENGTH);
response.send().flush();
@ -222,10 +225,10 @@ WebSocketImpl* WebSocket::connect(HTTPClientSession& cs, HTTPRequest& request, H
cs.proxyTunnel();
}
std::string key = createKey();
request.set("Connection", "Upgrade");
request.set("Upgrade", "websocket");
request.set("Sec-WebSocket-Version", WEBSOCKET_VERSION);
request.set("Sec-WebSocket-Key", key);
request.set("Connection"s, "Upgrade"s);
request.set("Upgrade"s, "websocket"s);
request.set("Sec-WebSocket-Version"s, WEBSOCKET_VERSION);
request.set("Sec-WebSocket-Key"s, key);
request.setChunkedTransferEncoding(false);
cs.setKeepAlive(true);
cs.sendRequest(request);
@ -272,13 +275,13 @@ WebSocketImpl* WebSocket::connect(HTTPClientSession& cs, HTTPRequest& request, H
WebSocketImpl* WebSocket::completeHandshake(HTTPClientSession& cs, HTTPResponse& response, const std::string& key)
{
std::string connection = response.get("Connection", "");
if (Poco::icompare(connection, "Upgrade") != 0)
std::string connection = response.get("Connection"s, ""s);
if (Poco::icompare(connection, "Upgrade"s) != 0)
throw WebSocketException("No Connection: Upgrade header in handshake response", WS_ERR_NO_HANDSHAKE);
std::string upgrade = response.get("Upgrade", "");
if (Poco::icompare(upgrade, "websocket") != 0)
std::string upgrade = response.get("Upgrade"s, ""s);
if (Poco::icompare(upgrade, "websocket"s) != 0)
throw WebSocketException("No Upgrade: websocket header in handshake response", WS_ERR_NO_HANDSHAKE);
std::string accept = response.get("Sec-WebSocket-Accept", "");
std::string accept = response.get("Sec-WebSocket-Accept"s, ""s);
if (accept != computeAccept(key))
throw WebSocketException("Invalid or missing Sec-WebSocket-Accept header in handshake response", WS_ERR_HANDSHAKE_ACCEPT);
return new WebSocketImpl(static_cast<StreamSocketImpl*>(cs.detachSocket().impl()), cs, true);

View File

@ -61,6 +61,9 @@ using Poco::AutoPtr;
using Poco::icompare;
using namespace std::string_literals;
namespace Poco {
namespace Util {
@ -72,7 +75,7 @@ Application::Application():
_pConfig(new LayeredConfiguration),
_initialized(false),
_unixOptions(true),
_pLogger(&Logger::get("ApplicationStartup")),
_pLogger(&Logger::get("ApplicationStartup"s)),
_stopOptionsProcessing(false)
{
setup();
@ -83,7 +86,7 @@ Application::Application(int argc, char* argv[]):
_pConfig(new LayeredConfiguration),
_initialized(false),
_unixOptions(true),
_pLogger(&Logger::get("ApplicationStartup")),
_pLogger(&Logger::get("ApplicationStartup"s)),
_stopOptionsProcessing(false)
{
setup();
@ -119,7 +122,7 @@ void Application::setup()
_pInstance = this;
AutoPtr<ConsoleChannel> pCC = new ConsoleChannel;
Logger::setChannel("", pCC);
Logger::setChannel(""s, pCC);
}
@ -164,14 +167,14 @@ void Application::init()
{
Path appPath;
getApplicationPath(appPath);
_pConfig->setString("application.path", appPath.toString());
_pConfig->setString("application.name", appPath.getFileName());
_pConfig->setString("application.baseName", appPath.getBaseName());
_pConfig->setString("application.dir", appPath.parent().toString());
_pConfig->setString("application.configDir", Path::configHome() + appPath.getBaseName() + Path::separator());
_pConfig->setString("application.cacheDir", Path::cacheHome() + appPath.getBaseName() + Path::separator());
_pConfig->setString("application.tempDir", Path::tempHome() + appPath.getBaseName() + Path::separator());
_pConfig->setString("application.dataDir", Path::dataHome() + appPath.getBaseName() + Path::separator());
_pConfig->setString("application.path"s, appPath.toString());
_pConfig->setString("application.name"s, appPath.getFileName());
_pConfig->setString("application.baseName"s, appPath.getBaseName());
_pConfig->setString("application.dir"s, appPath.parent().toString());
_pConfig->setString("application.configDir"s, Path::configHome() + appPath.getBaseName() + Path::separator());
_pConfig->setString("application.cacheDir"s, Path::cacheHome() + appPath.getBaseName() + Path::separator());
_pConfig->setString("application.tempDir"s, Path::tempHome() + appPath.getBaseName() + Path::separator());
_pConfig->setString("application.dataDir"s, Path::dataHome() + appPath.getBaseName() + Path::separator());
processOptions();
}
@ -186,7 +189,7 @@ void Application::initialize(Application& self)
{
for (auto& pSub: _subsystems)
{
_pLogger->debug(std::string("Initializing subsystem: ") + pSub->name());
_pLogger->debug("Initializing subsystem: "s + pSub->name());
pSub->initialize(self);
}
_initialized = true;
@ -199,7 +202,7 @@ void Application::uninitialize()
{
for (SubsystemVec::reverse_iterator it = _subsystems.rbegin(); it != _subsystems.rend(); ++it)
{
_pLogger->debug(std::string("Uninitializing subsystem: ") + (*it)->name());
_pLogger->debug("Uninitializing subsystem: "s + (*it)->name());
(*it)->uninitialize();
}
_initialized = false;
@ -211,7 +214,7 @@ void Application::reinitialize(Application& self)
{
for (auto& pSub: _subsystems)
{
_pLogger->debug(std::string("Re-initializing subsystem: ") + pSub->name());
_pLogger->debug("Re-initializing subsystem: "s + pSub->name());
pSub->reinitialize(self);
}
}
@ -229,27 +232,27 @@ int Application::loadConfiguration(int priority)
Path appPath;
getApplicationPath(appPath);
Path confPath;
if (findAppConfigFile(appPath.getBaseName(), "properties", confPath))
if (findAppConfigFile(appPath.getBaseName(), "properties"s, confPath))
{
_pConfig->add(new PropertyFileConfiguration(confPath.toString()), priority, false);
++n;
}
#ifndef POCO_UTIL_NO_INIFILECONFIGURATION
if (findAppConfigFile(appPath.getBaseName(), "ini", confPath))
if (findAppConfigFile(appPath.getBaseName(), "ini"s, confPath))
{
_pConfig->add(new IniFileConfiguration(confPath.toString()), priority, false);
++n;
}
#endif
#ifndef POCO_UTIL_NO_JSONCONFIGURATION
if (findAppConfigFile(appPath.getBaseName(), "json", confPath))
if (findAppConfigFile(appPath.getBaseName(), "json"s, confPath))
{
_pConfig->add(new JSONConfiguration(confPath.toString()), priority, false);
++n;
}
#endif
#ifndef POCO_UTIL_NO_XMLCONFIGURATION
if (findAppConfigFile(appPath.getBaseName(), "xml", confPath))
if (findAppConfigFile(appPath.getBaseName(), "xml"s, confPath))
{
_pConfig->add(new XMLConfiguration(confPath.toString()), priority, false);
++n;
@ -258,9 +261,9 @@ int Application::loadConfiguration(int priority)
if (n > 0)
{
if (!confPath.isAbsolute())
_pConfig->setString("application.configDir", confPath.absolute().parent().toString());
_pConfig->setString("application.configDir"s, confPath.absolute().parent().toString());
else
_pConfig->setString("application.configDir", confPath.parent().toString());
_pConfig->setString("application.configDir"s, confPath.parent().toString());
}
return n;
}
@ -299,25 +302,25 @@ void Application::loadConfiguration(const std::string& path, int priority)
#endif
else throw Poco::InvalidArgumentException("Unsupported configuration file type", ext);
if (n > 0 && !_pConfig->has("application.configDir"))
if (n > 0 && !_pConfig->has("application.configDir"s))
{
if (!confPath.isAbsolute())
_pConfig->setString("application.configDir", confPath.absolute().parent().toString());
_pConfig->setString("application.configDir"s, confPath.absolute().parent().toString());
else
_pConfig->setString("application.configDir", confPath.parent().toString());
_pConfig->setString("application.configDir"s, confPath.parent().toString());
}
}
std::string Application::commandName() const
{
return _pConfig->getString("application.baseName");
return _pConfig->getString("application.baseName"s);
}
std::string Application::commandPath() const
{
return _pConfig->getString("application.path");
return _pConfig->getString("application.path"s);
}
@ -371,7 +374,7 @@ int Application::run()
}
catch (...)
{
logger().fatal("system exception");
logger().fatal("system exception"s);
}
uninitialize();
@ -388,7 +391,7 @@ int Application::main(const ArgVec& args)
void Application::setArgs(int argc, char* argv[])
{
_command = argv[0];
_pConfig->setInt("application.argc", argc);
_pConfig->setInt("application.argc"s, argc);
_unprocessedArgs.reserve(argc);
std::string argvKey = "application.argv[";
for (int i = 0; i < argc; ++i)
@ -405,7 +408,7 @@ void Application::setArgs(const ArgVec& args)
poco_assert (!args.empty());
_command = args[0];
_pConfig->setInt("application.argc", (int) args.size());
_pConfig->setInt("application.argc"s, (int) args.size());
_unprocessedArgs = args;
std::string argvKey = "application.argv[";
for (int i = 0; i < args.size(); ++i)
@ -460,7 +463,7 @@ void Application::getApplicationPath(Poco::Path& appPath) const
}
else
{
if (!Path::find(Environment::get("PATH"), _command, appPath))
if (!Path::find(Environment::get("PATH"s), _command, appPath))
appPath = Path(_workingDirAtLaunch, _command);
appPath.makeAbsolute();
}

View File

@ -24,6 +24,7 @@ using Poco::Path;
using Poco::File;
using Poco::DirectoryIterator;
using Poco::StringTokenizer;
using namespace std::string_literals;
namespace Poco {
@ -52,7 +53,7 @@ void FilesystemConfiguration::clear()
bool FilesystemConfiguration::getRaw(const std::string& key, std::string& value) const
{
Path p(keyToPath(key));
p.setFileName("data");
p.setFileName("data"s);
File f(p);
if (f.exists())
{
@ -75,7 +76,7 @@ void FilesystemConfiguration::setRaw(const std::string& key, const std::string&
Path p(keyToPath(key));
File dir(p);
dir.createDirectories();
p.setFileName("data");
p.setFileName("data"s);
Poco::FileOutputStream ostr(p.toString());
ostr.write(value.data(), (std::streamsize) value.length());
}

View File

@ -27,6 +27,9 @@
#include "Poco/NumberParser.h"
using namespace std::string_literals;
namespace Poco {
namespace Util {
@ -109,7 +112,7 @@ void JSONConfiguration::getIndexes(std::string& name, std::vector<int>& indexes)
RegularExpression::MatchVec matches;
int firstOffset = -1;
int offset = 0;
RegularExpression regex("\\[([0-9]+)\\]");
RegularExpression regex("\\[([0-9]+)\\]"s);
while (regex.match(name, offset, matches) > 0)
{
if (firstOffset == -1)

View File

@ -32,6 +32,7 @@ using Poco::FormattingChannel;
using Poco::Logger;
using Poco::LoggingRegistry;
using Poco::LoggingFactory;
using namespace std::string_literals;
namespace Poco {
@ -52,13 +53,13 @@ void LoggingConfigurator::configure(AbstractConfiguration::Ptr pConfig)
{
poco_check_ptr (pConfig);
AbstractConfiguration::Ptr pFormattersConfig(pConfig->createView("logging.formatters"));
AbstractConfiguration::Ptr pFormattersConfig(pConfig->createView("logging.formatters"s));
configureFormatters(pFormattersConfig);
AbstractConfiguration::Ptr pChannelsConfig(pConfig->createView("logging.channels"));
AbstractConfiguration::Ptr pChannelsConfig(pConfig->createView("logging.channels"s));
configureChannels(pChannelsConfig);
AbstractConfiguration::Ptr pLoggersConfig(pConfig->createView("logging.loggers"));
AbstractConfiguration::Ptr pLoggersConfig(pConfig->createView("logging.loggers"s));
configureLoggers(pLoggersConfig);
}
@ -106,7 +107,7 @@ void LoggingConfigurator::configureLoggers(AbstractConfiguration::Ptr pConfig)
for (const auto& l: loggers)
{
AutoPtr<AbstractConfiguration> pLoggerConfig(pConfig->createView(l));
loggerMap[pLoggerConfig->getString("name", "")] = pLoggerConfig;
loggerMap[pLoggerConfig->getString("name"s, ""s)] = pLoggerConfig;
}
for (const auto& p: loggerMap)
{
@ -117,12 +118,12 @@ void LoggingConfigurator::configureLoggers(AbstractConfiguration::Ptr pConfig)
Formatter::Ptr LoggingConfigurator::createFormatter(AbstractConfiguration::Ptr pConfig)
{
Formatter::Ptr pFormatter(LoggingFactory::defaultFactory().createFormatter(pConfig->getString("class")));
Formatter::Ptr pFormatter(LoggingFactory::defaultFactory().createFormatter(pConfig->getString("class"s)));
AbstractConfiguration::Keys props;
pConfig->keys(props);
for (const auto& p: props)
{
if (p != "class")
if (p != "class"s)
pFormatter->setProperty(p, pConfig->getString(p));
}
return pFormatter;
@ -131,21 +132,21 @@ Formatter::Ptr LoggingConfigurator::createFormatter(AbstractConfiguration::Ptr p
Channel::Ptr LoggingConfigurator::createChannel(AbstractConfiguration::Ptr pConfig)
{
Channel::Ptr pChannel(LoggingFactory::defaultFactory().createChannel(pConfig->getString("class")));
Channel::Ptr pChannel(LoggingFactory::defaultFactory().createChannel(pConfig->getString("class"s)));
Channel::Ptr pWrapper(pChannel);
AbstractConfiguration::Keys props;
pConfig->keys(props);
for (const auto& p: props)
{
if (p == "pattern")
if (p == "pattern"s)
{
AutoPtr<Formatter> pPatternFormatter(new PatternFormatter(pConfig->getString(p)));
pWrapper = new FormattingChannel(pPatternFormatter, pChannel);
}
else if (p == "formatter")
else if (p == "formatter"s)
{
AutoPtr<FormattingChannel> pFormattingChannel(new FormattingChannel(0, pChannel));
if (pConfig->hasProperty("formatter.class"))
if (pConfig->hasProperty("formatter.class"s))
{
AutoPtr<AbstractConfiguration> pFormatterConfig(pConfig->createView(p));
AutoPtr<Formatter> pFormatter(createFormatter(pFormatterConfig));
@ -165,7 +166,7 @@ void LoggingConfigurator::configureChannel(Channel::Ptr pChannel, AbstractConfig
pConfig->keys(props);
for (const auto& p: props)
{
if (p != "pattern" && p != "formatter" && p != "class")
if (p != "pattern"s && p != "formatter"s && p != "class"s)
{
pChannel->setProperty(p, pConfig->getString(p));
}
@ -175,19 +176,19 @@ void LoggingConfigurator::configureChannel(Channel::Ptr pChannel, AbstractConfig
void LoggingConfigurator::configureLogger(AbstractConfiguration::Ptr pConfig)
{
Logger& logger = Logger::get(pConfig->getString("name", ""));
Logger& logger = Logger::get(pConfig->getString("name"s, ""s));
AbstractConfiguration::Keys props;
pConfig->keys(props);
for (const auto& p: props)
{
if (p == "channel" && pConfig->hasProperty("channel.class"))
if (p == "channel"s && pConfig->hasProperty("channel.class"s))
{
AutoPtr<AbstractConfiguration> pChannelConfig(pConfig->createView(p));
AutoPtr<Channel> pChannel(createChannel(pChannelConfig));
configureChannel(pChannel, pChannelConfig);
Logger::setChannel(logger.name(), pChannel);
}
else if (p != "name")
else if (p != "name"s)
{
Logger::setProperty(logger.name(), p, pConfig->getString(p));
}

View File

@ -19,6 +19,7 @@
using Poco::Logger;
using namespace std::string_literals;
namespace Poco {
@ -45,7 +46,7 @@ void LoggingSubsystem::initialize(Application& app)
{
LoggingConfigurator configurator;
configurator.configure(app.configPtr());
std::string logger = app.config().getString("application.logger", "Application");
std::string logger = app.config().getString("application.logger"s, "Application"s);
app.setLogger(Logger::get(logger));
}

View File

@ -46,6 +46,7 @@
using Poco::NumberFormatter;
using Poco::Exception;
using Poco::SystemException;
using namespace std::string_literals;
namespace Poco {
@ -79,7 +80,7 @@ ServerApplication::~ServerApplication()
bool ServerApplication::isInteractive() const
{
bool runsInBackground = config().getBool("application.runAsDaemon", false) || config().getBool("application.runAsService", false);
bool runsInBackground = config().getBool("application.runAsDaemon"s, false) || config().getBool("application.runAsService"s, false);
return !runsInBackground;
}
@ -143,7 +144,7 @@ void ServerApplication::ServiceMain(DWORD argc, LPWSTR* argv)
{
ServerApplication& app = static_cast<ServerApplication&>(Application::instance());
app.config().setBool("application.runAsService", true);
app.config().setBool("application.runAsService"s, true);
_serviceStatusHandle = RegisterServiceCtrlHandlerW(L"", ServiceControlHandler);
if (!_serviceStatusHandle)
@ -182,7 +183,7 @@ void ServerApplication::ServiceMain(DWORD argc, LPWSTR* argv)
}
catch (...)
{
app.logger().error("fatal error - aborting");
app.logger().error("fatal error - aborting"s);
_serviceStatus.dwWin32ExitCode = ERROR_SERVICE_SPECIFIC_ERROR;
_serviceStatus.dwServiceSpecificExitCode = EXIT_SOFTWARE;
}
@ -327,8 +328,8 @@ bool ServerApplication::hasConsole()
void ServerApplication::registerService()
{
std::string name = config().getString("application.baseName");
std::string path = Poco::format("\"%s\"", config().getString("application.path"));
std::string name = config().getString("application.baseName"s);
std::string path = Poco::format("\"%s\""s, config().getString("application.path"s));
WinService service(name);
if (_displayName.empty())
@ -347,11 +348,11 @@ void ServerApplication::registerService()
void ServerApplication::unregisterService()
{
std::string name = config().getString("application.baseName");
std::string name = config().getString("application.baseName"s);
WinService service(name);
service.unregisterService();
logger().information("The service has been successfully unregistered.");
logger().information("The service has been successfully unregistered."s);
}
@ -360,36 +361,36 @@ void ServerApplication::defineOptions(OptionSet& options)
Application::defineOptions(options);
options.addOption(
Option("registerService", "", "Register the application as a service.")
Option("registerService"s, ""s, "Register the application as a service."s)
.required(false)
.repeatable(false)
.callback(OptionCallback<ServerApplication>(this, &ServerApplication::handleRegisterService)));
options.addOption(
Option("unregisterService", "", "Unregister the application as a service.")
Option("unregisterService"s, ""s, "Unregister the application as a service."s)
.required(false)
.repeatable(false)
.callback(OptionCallback<ServerApplication>(this, &ServerApplication::handleUnregisterService)));
options.addOption(
Option("displayName", "", "Specify a display name for the service (only with /registerService).")
Option("displayName"s, ""s, "Specify a display name for the service (only with /registerService)."s)
.required(false)
.repeatable(false)
.argument("name")
.argument("name"s)
.callback(OptionCallback<ServerApplication>(this, &ServerApplication::handleDisplayName)));
options.addOption(
Option("description", "", "Specify a description for the service (only with /registerService).")
Option("description"s, ""s, "Specify a description for the service (only with /registerService)."s)
.required(false)
.repeatable(false)
.argument("text")
.argument("text"s)
.callback(OptionCallback<ServerApplication>(this, &ServerApplication::handleDescription)));
options.addOption(
Option("startup", "", "Specify the startup mode for the service (only with /registerService).")
Option("startup"s, ""s, "Specify the startup mode for the service (only with /registerService)."s)
.required(false)
.repeatable(false)
.argument("automatic|manual")
.argument("automatic|manual"s)
.callback(OptionCallback<ServerApplication>(this, &ServerApplication::handleStartup)));
}
@ -420,9 +421,9 @@ void ServerApplication::handleDescription(const std::string& name, const std::st
void ServerApplication::handleStartup(const std::string& name, const std::string& value)
{
if (Poco::icompare(value, 4, std::string("auto")) == 0)
if (Poco::icompare(value, 4, "auto"s) == 0)
_startup = "auto";
else if (Poco::icompare(value, std::string("manual")) == 0)
else if (Poco::icompare(value, "manual"s) == 0)
_startup = "manual";
else
throw InvalidArgumentException("argument to startup option must be 'auto[matic]' or 'manual'");
@ -561,7 +562,7 @@ int ServerApplication::run(const std::vector<std::string>& args)
bool ServerApplication::isDaemon(int argc, char** argv)
{
std::string option("--daemon");
std::string option("--daemon"s);
for (int i = 1; i < argc; ++i)
{
if (option == argv[i])
@ -604,20 +605,20 @@ void ServerApplication::defineOptions(OptionSet& options)
Application::defineOptions(options);
options.addOption(
Option("daemon", "", "Run application as a daemon.")
Option("daemon"s, ""s, "Run application as a daemon."s)
.required(false)
.repeatable(false)
.callback(OptionCallback<ServerApplication>(this, &ServerApplication::handleDaemon)));
options.addOption(
Option("umask", "", "Set the daemon's umask (octal, e.g. 027).")
Option("umask"s, ""s, "Set the daemon's umask (octal, e.g. 027)."s)
.required(false)
.repeatable(false)
.argument("mask")
.callback(OptionCallback<ServerApplication>(this, &ServerApplication::handleUMask)));
options.addOption(
Option("pidfile", "", "Write the process ID of the application to given file.")
Option("pidfile"s, ""s, "Write the process ID of the application to given file."s)
.required(false)
.repeatable(false)
.argument("path")
@ -627,7 +628,7 @@ void ServerApplication::defineOptions(OptionSet& options)
void ServerApplication::handleDaemon(const std::string& name, const std::string& value)
{
config().setBool("application.runAsDaemon", true);
config().setBool("application.runAsDaemon"s, true);
}

View File

@ -33,6 +33,7 @@
using Poco::Environment;
using Poco::Path;
using namespace std::string_literals;
namespace Poco {
@ -170,28 +171,28 @@ void SystemConfiguration::enumerate(const std::string& key, Keys& range) const
{
if (key.empty())
{
range.push_back("system");
range.push_back("system"s);
}
else if (key == "system")
{
range.push_back("osName");
range.push_back("osVersion");
range.push_back("osArchitecture");
range.push_back("nodeName");
range.push_back("nodeId");
range.push_back("currentDir");
range.push_back("homeDir");
range.push_back("configHomeDir");
range.push_back("cacheHomeDir");
range.push_back("dataHomeDir");
range.push_back("tempHomeDir");
range.push_back("tempDir");
range.push_back("configDir");
range.push_back("dateTime");
range.push_back("osName"s);
range.push_back("osVersion"s);
range.push_back("osArchitecture"s);
range.push_back("nodeName"s);
range.push_back("nodeId"s);
range.push_back("currentDir"s);
range.push_back("homeDir"s);
range.push_back("configHomeDir"s);
range.push_back("cacheHomeDir"s);
range.push_back("dataHomeDir"s);
range.push_back("tempHomeDir"s);
range.push_back("tempDir"s);
range.push_back("configDir"s);
range.push_back("dateTime"s);
#if !defined(POCO_VXWORKS)
range.push_back("pid");
range.push_back("pid"s);
#endif
range.push_back("env");
range.push_back("env"s);
}
}

View File

@ -19,6 +19,9 @@
#include "Poco/Exception.h"
using namespace std::string_literals;
namespace Poco {
namespace Util {
@ -95,12 +98,12 @@ void WinRegistryConfiguration::enumerate(const std::string& key, Keys& range) co
if (fullPath.empty())
{
// return all root level keys
range.push_back("HKEY_CLASSES_ROOT");
range.push_back("HKEY_CURRENT_CONFIG");
range.push_back("HKEY_CURRENT_USER");
range.push_back("HKEY_LOCAL_MACHINE");
range.push_back("HKEY_PERFORMANCE_DATA");
range.push_back("HKEY_USERS");
range.push_back("HKEY_CLASSES_ROOT"s);
range.push_back("HKEY_CURRENT_CONFIG"s);
range.push_back("HKEY_CURRENT_USER"s);
range.push_back("HKEY_LOCAL_MACHINE"s);
range.push_back("HKEY_PERFORMANCE_DATA"s);
range.push_back("HKEY_USERS"s);
}
else
{

View File

@ -30,6 +30,9 @@
#include <set>
using namespace std::string_literals;
namespace Poco {
namespace Util {
@ -37,14 +40,14 @@ namespace Util {
XMLConfiguration::XMLConfiguration():
_delim('.')
{
loadEmpty("config");
loadEmpty("config"s);
}
XMLConfiguration::XMLConfiguration(char delim):
_delim(delim)
{
loadEmpty("config");
loadEmpty("config"s);
}
@ -199,7 +202,7 @@ void XMLConfiguration::save(const std::string& path) const
AbstractConfiguration::ScopedLock lock(*this);
Poco::XML::DOMWriter writer;
writer.setNewLine("\n");
writer.setNewLine("\n"s);
writer.setOptions(Poco::XML::XMLWriter::PRETTY_PRINT);
writer.writeNode(path, _pDocument);
}
@ -210,7 +213,7 @@ void XMLConfiguration::save(std::ostream& ostr) const
AbstractConfiguration::ScopedLock lock(*this);
Poco::XML::DOMWriter writer;
writer.setNewLine("\n");
writer.setNewLine("\n"s);
writer.setOptions(Poco::XML::XMLWriter::PRETTY_PRINT);
writer.writeNode(ostr, _pDocument);
}

View File

@ -21,6 +21,9 @@
#include <sstream>
using namespace std::string_literals;
namespace Poco {
namespace XML {
@ -61,7 +64,7 @@ XMLWriter::XMLWriter(XMLByteOutputStream& str, int options):
_pInEncoding(new NATIVE_ENCODING),
_pOutEncoding(new Poco::UTF8Encoding),
_options(options),
_encoding("UTF-8"),
_encoding("UTF-8"s),
_depth(-1),
_elementCount(0),
_inFragment(false),
@ -302,7 +305,7 @@ void XMLWriter::emptyElement(const XMLString& namespaceURI, const XMLString& loc
else
writeStartElement(namespaceURI, localName, qname, attributes);
_contentWritten = false;
writeMarkup("/");
writeMarkup("/"s);
closeStartTag();
_namespaces.popContext();
}
@ -368,14 +371,14 @@ void XMLWriter::processingInstruction(const XMLString& target, const XMLString&
{
if (_unclosedStartTag) closeStartTag();
prettyPrint();
writeMarkup("<?");
writeMarkup("<?"s);
writeXML(target);
if (!data.empty())
{
writeMarkup(MARKUP_SPACE);
writeXML(data);
}
writeMarkup("?>");
writeMarkup("?>"s);
if (_depth == 0)
writeNewLine();
}
@ -383,7 +386,7 @@ void XMLWriter::processingInstruction(const XMLString& target, const XMLString&
namespace
{
static const XMLString CDATA = toXMLString("CDATA");
static const XMLString CDATA = toXMLString("CDATA"s);
}
@ -456,32 +459,32 @@ void XMLWriter::comment(const XMLChar ch[], int start, int length)
{
if (_unclosedStartTag) closeStartTag();
prettyPrint();
writeMarkup("<!--");
writeMarkup("<!--"s);
while (length-- > 0) writeXML(ch[start++]);
writeMarkup("-->");
writeMarkup("-->"s);
_contentWritten = false;
}
void XMLWriter::startDTD(const XMLString& name, const XMLString& publicId, const XMLString& systemId)
{
writeMarkup("<!DOCTYPE ");
writeMarkup("<!DOCTYPE "s);
writeXML(name);
if (!publicId.empty())
{
writeMarkup(" PUBLIC \"");
writeMarkup(" PUBLIC \""s);
writeXML(publicId);
writeMarkup("\"");
writeMarkup("\""s);
}
if (!systemId.empty())
{
if (publicId.empty())
{
writeMarkup(" SYSTEM");
writeMarkup(" SYSTEM"s);
}
writeMarkup(" \"");
writeMarkup(" \""s);
writeXML(systemId);
writeMarkup("\"");
writeMarkup("\""s);
}
_inDTD = true;
}
@ -493,10 +496,10 @@ void XMLWriter::endDTD()
if (_inInternalDTD)
{
writeNewLine();
writeMarkup("]");
writeMarkup("]"s);
_inInternalDTD = false;
}
writeMarkup(">");
writeMarkup(">"s);
writeNewLine();
_inDTD = false;
}
@ -517,7 +520,7 @@ void XMLWriter::notationDecl(const XMLString& name, const XMLString* publicId, c
if (!_inDTD) throw XMLException("Notation declaration not within DTD");
if (!_inInternalDTD)
{
writeMarkup(" [");
writeMarkup(" ["s);
_inInternalDTD = true;
}
if (_options & PRETTY_PRINT)
@ -525,21 +528,21 @@ void XMLWriter::notationDecl(const XMLString& name, const XMLString* publicId, c
writeNewLine();
writeMarkup(_indent);
}
writeMarkup("<!NOTATION ");
writeMarkup("<!NOTATION "s);
writeXML(name);
if (systemId && !systemId->empty())
{
writeMarkup(" SYSTEM \"");
writeMarkup(" SYSTEM \""s);
writeXML(*systemId);
writeMarkup("\"");
writeMarkup("\""s);
}
if (publicId && !publicId->empty())
{
writeMarkup(" PUBLIC \"");
writeMarkup(" PUBLIC \""s);
writeXML(*publicId);
writeMarkup("\"");
writeMarkup("\""s);
}
writeMarkup(">");
writeMarkup(">"s);
}
@ -548,7 +551,7 @@ void XMLWriter::unparsedEntityDecl(const XMLString& name, const XMLString* publi
if (!_inDTD) throw XMLException("Entity declaration not within DTD");
if (!_inInternalDTD)
{
writeMarkup(" [");
writeMarkup(" ["s);
_inInternalDTD = true;
}
if (_options & PRETTY_PRINT)
@ -556,26 +559,26 @@ void XMLWriter::unparsedEntityDecl(const XMLString& name, const XMLString* publi
writeNewLine();
writeMarkup(_indent);
}
writeMarkup("<!ENTITY ");
writeMarkup("<!ENTITY "s);
writeXML(name);
if (!systemId.empty())
{
writeMarkup(" SYSTEM \"");
writeMarkup(" SYSTEM \""s);
writeXML(systemId);
writeMarkup("\"");
writeMarkup("\""s);
}
if (publicId && !publicId->empty())
{
writeMarkup(" PUBLIC \"");
writeMarkup(" PUBLIC \""s);
writeXML(*publicId);
writeMarkup("\"");
writeMarkup("\""s);
}
if (!notationName.empty())
{
writeMarkup(" NDATA ");
writeMarkup(" NDATA "s);
writeXML(notationName);
}
writeMarkup(">");
writeMarkup(">"s);
}
@ -1029,14 +1032,14 @@ void XMLWriter::writeIndent(int depth) const
void XMLWriter::writeXMLDeclaration()
{
writeMarkup("<?xml version=\"1.0\"");
writeMarkup("<?xml version=\"1.0\""s);
if (!_encoding.empty())
{
writeMarkup(" encoding=\"");
writeMarkup(" encoding=\""s);
writeMarkup(_encoding);
writeMarkup("\"");
writeMarkup("\""s);
}
writeMarkup("?>");
writeMarkup("?>"s);
writeNewLine();
}