comparison 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
comparison
equal deleted inserted replaced
104:27455104ea37 105:6d8da6e64d61
1 #ifndef __core__strings_h 1 #ifndef __core__strings_h
2 #define __core__strings_h 2 #define __core__strings_h
3 3
4 #include <string> 4 #include <string>
5 #include <vector> 5 #include <vector>
6 #include <array>
6 7
7 class QString; 8 class QString;
8 9
9 namespace Strings { 10 namespace Strings {
11
12 template<unsigned...>struct seq{using type=seq;};
13 template<unsigned N, unsigned... Is>
14 struct gen_seq_x : gen_seq_x<N-1, N-1, Is...>{};
15 template<unsigned... Is>
16 struct gen_seq_x<0, Is...> : seq<Is...>{};
17 template<unsigned N>
18 using gen_seq=typename gen_seq_x<N>::type;
19
20 template<size_t S>
21 using size=std::integral_constant<size_t, S>;
22
23 template<class T, size_t N>
24 constexpr size<N> length( T const(&)[N] ) { return {}; }
25 template<class T, size_t N>
26 constexpr size<N> length( std::array<T, N> const& ) { return {}; }
27
28 template<class T>
29 using length_t = decltype(length(std::declval<T>()));
30
31 constexpr size_t string_size() { return 0; }
32 template<class...Ts>
33 constexpr size_t string_size( size_t i, Ts... ts ) {
34 return (i?i-1:0) + string_size(ts...);
35 }
36 template<class...Ts>
37 using string_length=size< string_size( length_t<Ts>{}... )>;
38
39 template<class...Ts>
40 using combined_string = std::array<char, string_length<Ts...>{}+1>;
41
42 template<class Lhs, class Rhs, unsigned...I1, unsigned...I2>
43 constexpr const combined_string<Lhs,Rhs>
44 concat_impl( Lhs const& lhs, Rhs const& rhs, seq<I1...>, seq<I2...>)
45 {
46 return {{ lhs[I1]..., rhs[I2]..., '\0' }};
47 }
48
49 template<class Lhs, class Rhs>
50 constexpr const combined_string<Lhs,Rhs>
51 concat(Lhs const& lhs, Rhs const& rhs)
52 {
53 return concat_impl(lhs, rhs, gen_seq<string_length<Lhs>{}>{}, gen_seq<string_length<Rhs>{}>{});
54 }
55
56 template<class T0, class T1, class... Ts>
57 constexpr const combined_string<T0, T1, Ts...>
58 concat(T0 const&t0, T1 const&t1, Ts const&...ts)
59 {
60 return concat(t0, concat(t1, ts...));
61 }
62
63 template<class T>
64 constexpr const combined_string<T>
65 concat(T const&t) {
66 return concat(t, "");
67 }
68 constexpr const combined_string<>
69 concat() {
70 return concat("");
71 }
10 72
11 /* Implode function: takes a vector of strings and turns it 73 /* Implode function: takes a vector of strings and turns it
12 into a string, separated by delimiters. */ 74 into a string, separated by delimiters. */
13 std::string Implode(const std::vector<std::string>& vector, const std::string& delimiter); 75 std::string Implode(const std::vector<std::string>& vector, const std::string& delimiter);
14 76