diff include/core/strings.h @ 105:6d8da6e64d61

theme: add dark stylesheet, make it actually usable win32: make the titlebar black where available
author Paper <mrpapersonic@gmail.com>
date Sun, 05 Nov 2023 03:54:26 -0500
parents b315f3759c56
children ab191e28e69d
line wrap: on
line diff
--- a/include/core/strings.h	Sun Nov 05 02:35:27 2023 -0500
+++ b/include/core/strings.h	Sun Nov 05 03:54:26 2023 -0500
@@ -3,11 +3,73 @@
 
 #include <string>
 #include <vector>
+#include <array>
 
 class QString;
 
 namespace Strings {
 
+template<unsigned...>struct seq{using type=seq;};
+template<unsigned N, unsigned... Is>
+struct gen_seq_x : gen_seq_x<N-1, N-1, Is...>{};
+template<unsigned... Is>
+struct gen_seq_x<0, Is...> : seq<Is...>{};
+template<unsigned N>
+using gen_seq=typename gen_seq_x<N>::type;
+
+template<size_t S>
+using size=std::integral_constant<size_t, S>;
+
+template<class T, size_t N>
+constexpr size<N> length( T const(&)[N] ) { return {}; }
+template<class T, size_t N>
+constexpr size<N> length( std::array<T, N> const& ) { return {}; }
+
+template<class T>
+using length_t = decltype(length(std::declval<T>()));
+
+constexpr size_t string_size() { return 0; }
+template<class...Ts>
+constexpr size_t string_size( size_t i, Ts... ts ) {
+  return (i?i-1:0) + string_size(ts...);
+}
+template<class...Ts>
+using string_length=size< string_size( length_t<Ts>{}... )>;
+
+template<class...Ts>
+using combined_string = std::array<char, string_length<Ts...>{}+1>;
+
+template<class Lhs, class Rhs, unsigned...I1, unsigned...I2>
+constexpr const combined_string<Lhs,Rhs>
+concat_impl( Lhs const& lhs, Rhs const& rhs, seq<I1...>, seq<I2...>)
+{
+    return {{ lhs[I1]..., rhs[I2]..., '\0' }};
+}
+
+template<class Lhs, class Rhs>
+constexpr const combined_string<Lhs,Rhs>
+concat(Lhs const& lhs, Rhs const& rhs)
+{
+    return concat_impl(lhs, rhs, gen_seq<string_length<Lhs>{}>{}, gen_seq<string_length<Rhs>{}>{});
+}
+
+template<class T0, class T1, class... Ts>
+constexpr const combined_string<T0, T1, Ts...>
+concat(T0 const&t0, T1 const&t1, Ts const&...ts)
+{
+    return concat(t0, concat(t1, ts...));
+}
+
+template<class T>
+constexpr const combined_string<T>
+concat(T const&t) {
+    return concat(t, "");
+}
+constexpr const combined_string<>
+concat() {
+    return concat("");
+}
+
 /* Implode function: takes a vector of strings and turns it
    into a string, separated by delimiters. */
 std::string Implode(const std::vector<std::string>& vector, const std::string& delimiter);