#include <array>
#include <cstdint>
+#include <iterator>
+#include <ranges>
#include <string_view>
-#include <atomic>
#include <unordered_map>
#include <fmt/format.h>
+
#include <boost/container/flat_map.hpp>
#include <boost/container/flat_set.hpp>
extern bool match_policy(const std::string& pattern, const std::string& input,
uint32_t flag);
-extern std::string camelcase_dash_http_attr(const std::string& orig, bool convert2dash = true);
-extern std::string lowercase_dash_http_attr(const std::string& orig, bool bidirection = false);
+/*
+ * Converts to lowercase with upper after a separator
+ *
+ * `THIS_KIND_OF_STRING` to `This_Kind_Of_String` and possibly
+ * `This-Kind-Of-String` if `convert2dash` is true. Not actually CamelCase
+ * as generally understood.
+ *
+ * \param[in] in Range to transform
+ * \param[out] out Output iterator
+ * \param[in] convert2dash Transform '_' to '-'
+ *
+ * \return A structure of input and output iterators, as with std::transform.
+ */
+inline auto
+camelcase_dash_transform(
+ std::ranges::input_range auto&& in,
+ std::output_iterator<char> auto out,
+ bool convert2dash = true)
+{
+ bool last_sep = true;
+ return std::ranges::transform(
+ std::forward<decltype(in)>(in), out, [&last_sep, convert2dash](char c) -> char {
+ switch (c) {
+ case '_':
+ case '-':
+ last_sep = true;
+ return convert2dash ? '-' : c;
+ default:
+ c = last_sep ? toupper(static_cast<unsigned char>(c)) : tolower(static_cast<unsigned char>(c));
+ last_sep = false;
+ return c;
+ }
+ });
+}
+
+/*
+ * Converts to lowercase with upper after a separator
+ *
+ * `THIS_KIND_OF_STRING` to `This_Kind_Of_String` and possibly
+ * `This-Kind-Of-String` if `convert2dash` is true. Not actually CamelCase
+ * as generally understood.
+ *
+ * \param[in] in Range to transform
+ * \param[in] convert2dash Transform '_' to '-'
+ *
+ * \return Transformed string
+ */
+inline std::string
+camelcase_dash_http_attr(const std::string& in, bool convert2dash = true)
+{
+ std::string out;
+ out.reserve(in.size());
+ camelcase_dash_transform(in, std::back_inserter(out), convert2dash);
+ return out;
+}
+
+/*
+ * Converts to lowercase with upper after a separator
+ *
+ * `THIS_KIND_OF_STRING` to `This_Kind_Of_String` and possibly
+ * `This-Kind-Of-String` if `convert2dash` is true. Not actually CamelCase
+ * as generally understood.
+ *
+ * \param[in] in Range to transform
+ * \param[in] convert2dash Transform '_' to '-'
+ *
+ * \return Transformed string move-constructed from 'in'.
+ */
+inline std::string
+camelcase_dash_http_attr(std::string&& in, bool convert2dash = true)
+{
+ camelcase_dash_transform(in, in.begin(), convert2dash);
+ return std::move(in);
+}
+
+/*
+ * Converts uppercase to lowercase and underscores to dashes
+ *
+ * `THIS_KIND_OF_STRING` to `this-kind-of-string`
+ *
+ * \param[in] in Range to transform
+ * \param[out] out Output iterator
+ * \param[in] bidirectional Transform '-' to '_'
+ *
+ * \return A structure of input and output iterators, as with std::transform.
+ */
+inline auto
+lowercase_dash_transform(
+ std::ranges::input_range auto&& in,
+ std::output_iterator<char> auto out,
+ bool bidirectional = false)
+{
+ return std::ranges::transform(
+ std::forward<decltype(in)>(in), out, [bidirectional](char c) -> char {
+ switch (c) {
+ case '_':
+ return '-';
+ case '-':
+ return bidirectional ? '_' : '-';
+ default:
+ return tolower(static_cast<unsigned char>(c));
+ }
+ });
+}
+
+/*
+ * Converts uppercase to lowercase and underscores to dashes
+ *
+ * `THIS_KIND_OF_STRING` to `this-kind-of-string`
+ *
+ * \param[in] in String to transform
+ * \param[in] bidirectional Transform '-' to '_'
+ *
+ * \return Transformed string
+ */
+inline std::string
+lowercase_dash_http_attr(const std::string& in, bool bidirectional = false)
+{
+ std::string out;
+ out.reserve(in.size());
+ lowercase_dash_transform(in, std::back_inserter(out), bidirectional);
+ return out;
+}
+
+/*
+ * Converts uppercase to lowercase and underscores to dashes
+ *
+ * `THIS_KIND_OF_STRING` to `this-kind-of-string`
+ *
+ * \param[in] in String to transform
+ * \param[in] bidirectional Transform '-' to '_'
+ *
+ * \return Transformed string move-constructed from 'in'.
+ */
+inline std::string
+lowercase_dash_http_attr(std::string&& in, bool bidirectional = false)
+{
+ lowercase_dash_transform(in, in.begin(), bidirectional);
+ return std::move(in);
+}
+
+/*
+ * Converts lower to upper and dashes to underscores
+ *
+ * 'this-kind-of-string' to 'THIS_KIND_OF_STRING'
+ *
+ * \param[in] in Range to transform
+ * \param[out] out Output iterator
+ * \param[in] bidirectional Transform '_' to '-'
+ *
+ * \return A structure of input and output iterators, as with std::transform.
+ */
+inline auto
+uppercase_dash_transform(
+ std::ranges::input_range auto&& in,
+ std::output_iterator<char> auto out,
+ bool bidirectional = false)
+{
+ return std::ranges::transform(
+ std::forward<decltype(in)>(in), out, [bidirectional](char c) -> char {
+ switch (c) {
+ case '-':
+ return '_';
+ case '_':
+ if (bidirectional)
+ return '-';
+ else
+ return toupper(static_cast<unsigned char>(c));
+ default:
+ return toupper(static_cast<unsigned char>(c));
+ }
+ });
+}
void rgw_setup_saved_curl_handles();
void rgw_release_all_curl_handles();