From: Francesco Chemolli <5175948+kinkie@users.noreply.github.com> Date: Sun, 15 Oct 2023 04:08:29 +0000 (+0000) Subject: Upgrade AsList separators to support c-strings (#1519) X-Git-Tag: SQUID_7_0_1~329 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c328a2a48552ec4d2efbfabe3f7d662f44345da9;p=thirdparty%2Fsquid.git Upgrade AsList separators to support c-strings (#1519) --- diff --git a/src/base/IoManip.h b/src/base/IoManip.h index d8ac5287c6..53e17d94d2 100644 --- a/src/base/IoManip.h +++ b/src/base/IoManip.h @@ -13,7 +13,6 @@ #include #include -#include /// Safely prints an object pointed to by the given pointer: [label] /// Prints nothing at all if the pointer is nil. @@ -109,17 +108,17 @@ class AsList public: explicit AsList(const Container &c): container(c) {} - /// a character to print before the first item (if any) - auto &prefixedBy(const char ch) { prefix = ch; return *this; } + /// a c-string to print before the first item (if any). Caller must ensure lifetime. + auto &prefixedBy(const char * const p) { prefix = p; return *this; } - /// a character to print between consecutive items (if any) - auto &delimitedBy(const char ch) { delimiter = ch; return *this; } + /// a c-string to print between consecutive items (if any). Caller must ensure lifetime. + auto &delimitedBy(const char * const d) { delimiter = d; return *this; } public: const Container &container; ///< zero or more items to print - std::optional prefix; ///< \copydoc prefixedBy() - std::optional delimiter; ///< \copydoc delimitedBy() + const char *prefix = nullptr; ///< \copydoc prefixedBy() + const char *delimiter = nullptr; ///< \copydoc delimitedBy() }; template @@ -130,11 +129,11 @@ operator <<(std::ostream &os, const AsList &manipulator) for (const auto &item: manipulator.container) { if (!opened) { if (manipulator.prefix) - os << *manipulator.prefix; + os << manipulator.prefix; opened = true; } else { if (manipulator.delimiter) - os << *manipulator.delimiter; + os << manipulator.delimiter; } os << item; } diff --git a/src/error/Error.cc b/src/error/Error.cc index 6789474c72..339ee701a1 100644 --- a/src/error/Error.cc +++ b/src/error/Error.cc @@ -69,7 +69,7 @@ Error::update(const err_type recentCategory, const ErrorDetail::Pointer &recentD std::ostream & operator <<(std::ostream &os, const ErrorDetails &details) { - os << AsList(details).delimitedBy('+'); + os << AsList(details).delimitedBy("+"); return os; } @@ -77,7 +77,7 @@ std::ostream & operator <<(std::ostream &os, const Error &error) { os << errorTypeName(error.category); - os << AsList(error.details).prefixedBy('/').delimitedBy('+'); + os << AsList(error.details).prefixedBy("/").delimitedBy("+"); return os; }