diff options
author | Max Kellermann <max@musicpd.org> | 2018-10-31 19:23:57 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2018-10-31 19:26:37 +0100 |
commit | 657ef4851829c594395c7807fdb1b73e54fbd041 (patch) | |
tree | 6b1bfc5794a85d5e530c60a6756444b039f2e457 /src/zeroconf | |
parent | b1d68fe995e47dd92703a6f2640d379cb84d12a8 (diff) |
zeroconf/glue: use strstr() and std::string::replace() instead of std::regex_replace()
std::regex_replace() is heavily bloated and overkill for this feature.
Diffstat (limited to 'src/zeroconf')
-rw-r--r-- | src/zeroconf/ZeroconfGlue.cxx | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/zeroconf/ZeroconfGlue.cxx b/src/zeroconf/ZeroconfGlue.cxx index 710154f72..2514e6b86 100644 --- a/src/zeroconf/ZeroconfGlue.cxx +++ b/src/zeroconf/ZeroconfGlue.cxx @@ -27,9 +27,10 @@ #include "util/Domain.hxx" #include "Log.hxx" #include "util/Compiler.h" + +#include <string.h> #include <unistd.h> #include <limits.h> -#include <regex> static constexpr Domain zeroconf_domain("zeroconf"); @@ -62,10 +63,17 @@ ZeroconfInit(const ConfigData &config, gcc_unused EventLoop &loop) serviceName = config.GetString(ConfigOption::ZEROCONF_NAME, SERVICE_NAME); - char hostname[HOST_NAME_MAX+1]; - gethostname(hostname, HOST_NAME_MAX); - std::string sName = std::regex_replace(serviceName, std::regex("%h"), hostname); - serviceName = sName.c_str(); + /* replace "%h" with the host name */ + const char *h = strstr(serviceName, "%h"); + std::string buffer; + if (h != nullptr) { + char hostname[HOST_NAME_MAX+1]; + if (gethostname(hostname, HOST_NAME_MAX) == 0) { + buffer = serviceName; + buffer.replace(h - serviceName, 2, hostname); + serviceName = buffer.c_str(); + } + } #ifdef HAVE_AVAHI AvahiInit(loop, serviceName); |