From 55ee4f59d0267e1d4d217f09ef58a6b95909f344 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 26 Jul 2023 13:56:11 +0100 Subject: Anonymous namespace over static --- icespider/compile/main.cpp | 28 ++++++++++++++------------- icespider/compile/routeCompiler.cpp | 24 ++++++++++++----------- icespider/core/core.cpp | 12 +++++++----- icespider/xslt/exslt-init.cpp | 34 +++++++++++++++++---------------- icespider/xslt/xsltStreamSerializer.cpp | 24 ++++++++++++----------- 5 files changed, 66 insertions(+), 56 deletions(-) diff --git a/icespider/compile/main.cpp b/icespider/compile/main.cpp index 3133006..fa679f9 100644 --- a/icespider/compile/main.cpp +++ b/icespider/compile/main.cpp @@ -17,22 +17,24 @@ namespace po = boost::program_options; using namespace AdHoc::literals; -static std::string -defaultPostProcessor() -{ - constexpr std::array, 1> pps {{ - {"clang-format", "-i"}, - }}; - const std::string_view path {getenv("PATH") ?: "/usr/bin"}; - const auto pathBegin = make_split_iterator(path, first_finder(":", boost::is_equal())); - for (const auto & [cmd, opts] : pps) { - for (auto p = pathBegin; p != decltype(pathBegin) {}; ++p) { - if (std::filesystem::exists(std::filesystem::path(p->begin(), p->end()) / cmd)) { - return "%? %?"_fmt(cmd, opts); +namespace { + std::string + defaultPostProcessor() + { + constexpr std::array, 1> pps {{ + {"clang-format", "-i"}, + }}; + const std::string_view path {getenv("PATH") ?: "/usr/bin"}; + const auto pathBegin = make_split_iterator(path, first_finder(":", boost::is_equal())); + for (const auto & [cmd, opts] : pps) { + for (auto p = pathBegin; p != decltype(pathBegin) {}; ++p) { + if (std::filesystem::exists(std::filesystem::path(p->begin(), p->end()) / cmd)) { + return "%? %?"_fmt(cmd, opts); + } } } + return {}; } - return ""; } int diff --git a/icespider/compile/routeCompiler.cpp b/icespider/compile/routeCompiler.cpp index a7a7695..4057158 100644 --- a/icespider/compile/routeCompiler.cpp +++ b/icespider/compile/routeCompiler.cpp @@ -272,19 +272,21 @@ namespace IceSpider::Compile { return Slicer::ModelPartForEnum::lookup(e); } - static std::string - outputSerializerClass(const IceSpider::OutputSerializers::value_type & os) - { - return boost::algorithm::replace_all_copy(os.second->serializer, ".", "::"); - } + namespace { + std::string + outputSerializerClass(const IceSpider::OutputSerializers::value_type & os) + { + return boost::algorithm::replace_all_copy(os.second->serializer, ".", "::"); + } - AdHocFormatter(MimePair, R"C({ "%?", "%?" })C"); + AdHocFormatter(MimePair, R"C({ "%?", "%?" })C"); - static std::string - outputSerializerMime(const IceSpider::OutputSerializers::value_type & os) - { - auto slash = os.first.find('/'); - return MimePair::get(os.first.substr(0, slash), os.first.substr(slash + 1)); + std::string + outputSerializerMime(const IceSpider::OutputSerializers::value_type & os) + { + auto slash = os.first.find('/'); + return MimePair::get(os.first.substr(0, slash), os.first.substr(slash + 1)); + } } void diff --git a/icespider/core/core.cpp b/icespider/core/core.cpp index 7aa1317..6aacb15 100644 --- a/icespider/core/core.cpp +++ b/icespider/core/core.cpp @@ -118,11 +118,13 @@ namespace IceSpider { defaultErrorReport(request, exception); } - auto - demangle(const char * const name) - { - return std::unique_ptr( - __cxxabiv1::__cxa_demangle(name, nullptr, nullptr, nullptr), std::free); + namespace { + auto + demangle(const char * const name) + { + return std::unique_ptr( + __cxxabiv1::__cxa_demangle(name, nullptr, nullptr, nullptr), std::free); + } } AdHocFormatter(LogExp, "Exception type: %?\nDetail: %?\n"); diff --git a/icespider/xslt/exslt-init.cpp b/icespider/xslt/exslt-init.cpp index 110a999..55b2407 100644 --- a/icespider/xslt/exslt-init.cpp +++ b/icespider/xslt/exslt-init.cpp @@ -2,23 +2,25 @@ #include #include -static void initLibXml() __attribute__((constructor(102))); +namespace { + void initLibXml() __attribute__((constructor(102))); -void -initLibXml() -{ - xmlInitParser(); - exsltRegisterAll(); -} + void + initLibXml() + { + xmlInitParser(); + exsltRegisterAll(); + } -// LCOV_EXCL_START lcov actually misses destructor functions -static void cleanupLibXml() __attribute__((destructor(102))); + // LCOV_EXCL_START lcov actually misses destructor functions + static void cleanupLibXml() __attribute__((destructor(102))); -void -cleanupLibXml() -{ - xsltCleanupGlobals(); - xmlCleanupParser(); -} + void + cleanupLibXml() + { + xsltCleanupGlobals(); + xmlCleanupParser(); + } -// LCOV_EXCL_STOP + // LCOV_EXCL_STOP +} diff --git a/icespider/xslt/xsltStreamSerializer.cpp b/icespider/xslt/xsltStreamSerializer.cpp index 6fb265c..6fbe8ed 100644 --- a/icespider/xslt/xsltStreamSerializer.cpp +++ b/icespider/xslt/xsltStreamSerializer.cpp @@ -16,18 +16,20 @@ #include namespace IceSpider { - static int - xmlstrmclosecallback(void * context) - { - static_cast(context)->flush(); - return 0; - } + namespace { + int + xmlstrmclosecallback(void * context) + { + static_cast(context)->flush(); + return 0; + } - static int - xmlstrmwritecallback(void * context, const char * buffer, int len) - { - static_cast(context)->write(buffer, len); - return len; + int + xmlstrmwritecallback(void * context, const char * buffer, int len) + { + static_cast(context)->write(buffer, len); + return len; + } } XsltStreamSerializer::IceSpiderFactory::IceSpiderFactory(const char * path) : -- cgit v1.2.3