]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Upgrade AsList separators to support c-strings (#1519)
authorFrancesco Chemolli <5175948+kinkie@users.noreply.github.com>
Sun, 15 Oct 2023 04:08:29 +0000 (04:08 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Sun, 15 Oct 2023 08:33:45 +0000 (08:33 +0000)
src/base/IoManip.h
src/error/Error.cc

index d8ac5287c6500305591031f94ef8b054caab9385..53e17d94d2fcc88985c8b6e981b71676271b653c 100644 (file)
@@ -13,7 +13,6 @@
 
 #include <iostream>
 #include <iomanip>
-#include <optional>
 
 /// Safely prints an object pointed to by the given pointer: [label]<object>
 /// 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<char> prefix; ///< \copydoc prefixedBy()
-    std::optional<char> delimiter; ///< \copydoc delimitedBy()
+    const char *prefix = nullptr; ///< \copydoc prefixedBy()
+    const char *delimiter = nullptr; ///< \copydoc delimitedBy()
 };
 
 template <class Container>
@@ -130,11 +129,11 @@ operator <<(std::ostream &os, const AsList<Container> &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;
     }
index 6789474c72b2d8e53e060a70c4e67e6c1856a20c..339ee701a162e879bb2bf33109fe662e429f7b19 100644 (file)
@@ -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;
 }