7 #ifndef _FCITX_UTILS_METASTRING_H_ 8 #define _FCITX_UTILS_METASTRING_H_ 16 #include <string_view> 23 using array_type =
char const (&)[
sizeof...(c) + 1];
25 static constexpr std::size_t size() {
return size_; }
26 static constexpr
const char *data() {
return str_; }
27 static constexpr
bool empty() {
return size_ == 0; }
29 static constexpr array_type str() {
return str_; }
32 static constexpr
const char str_[
sizeof...(c) + 1] = {c...,
'\0'};
33 static const std::size_t size_ =
sizeof...(c);
36 template <
int N,
int M>
37 constexpr
char __getChar(
char const (&str)[M]) noexcept {
38 if constexpr (N < M) {
45 constexpr
char __getChar(std::string_view str) noexcept {
52 template <
typename... T>
65 template <
char... c,
typename... Rem>
69 template <
char... c,
char c2,
typename... Rem>
74 template <
typename...>
87 template <
char... c1s,
char... c2s,
typename... _Rem>
93 template <
typename... Args>
101 template <
char first,
char... next>
104 ConcatMetaStringType<MetaString<first>,
105 RemoveMetaStringTailType<
MetaString<next...>>>;
107 template <
char first>
112 template <
typename... T>
115 template <
typename... T>
116 using MetaStringBasenameHelperType =
131 using type = MetaStringBasenameHelperType<
MetaString<c...>>;
134 template <
char... c,
char c2,
typename... Rem>
136 using type = MetaStringBasenameHelperType<
MetaString<c..., c2>, Rem...>;
139 template <
char... c,
typename... Rem>
141 using type = MetaStringBasenameHelperType<Rem...>;
144 template <
typename T>
149 using type = MetaStringBasenameHelperType<MetaString<c>...>;
152 template <
typename T>
163 #define FCITX_METASTRING_TEMPLATE_16(N, S) \ 164 ::fcitx::__getChar<0x##N##0>(S), ::fcitx::__getChar<0x##N##1>(S), \ 165 ::fcitx::__getChar<0x##N##2>(S), ::fcitx::__getChar<0x##N##3>(S), \ 166 ::fcitx::__getChar<0x##N##4>(S), ::fcitx::__getChar<0x##N##5>(S), \ 167 ::fcitx::__getChar<0x##N##6>(S), ::fcitx::__getChar<0x##N##7>(S), \ 168 ::fcitx::__getChar<0x##N##8>(S), ::fcitx::__getChar<0x##N##9>(S), \ 169 ::fcitx::__getChar<0x##N##A>(S), ::fcitx::__getChar<0x##N##B>(S), \ 170 ::fcitx::__getChar<0x##N##C>(S), ::fcitx::__getChar<0x##N##D>(S), \ 171 ::fcitx::__getChar<0x##N##E>(S), ::fcitx::__getChar<0x##N##F>(S) 173 #define FCITX_METASTRING_TEMPLATE_256(N, S) \ 174 FCITX_METASTRING_TEMPLATE_16(N##0, S) \ 175 , FCITX_METASTRING_TEMPLATE_16(N##1, S), \ 176 FCITX_METASTRING_TEMPLATE_16(N##2, S), \ 177 FCITX_METASTRING_TEMPLATE_16(N##3, S), \ 178 FCITX_METASTRING_TEMPLATE_16(N##4, S), \ 179 FCITX_METASTRING_TEMPLATE_16(N##5, S), \ 180 FCITX_METASTRING_TEMPLATE_16(N##6, S), \ 181 FCITX_METASTRING_TEMPLATE_16(N##7, S), \ 182 FCITX_METASTRING_TEMPLATE_16(N##8, S), \ 183 FCITX_METASTRING_TEMPLATE_16(N##9, S), \ 184 FCITX_METASTRING_TEMPLATE_16(N##A, S), \ 185 FCITX_METASTRING_TEMPLATE_16(N##B, S), \ 186 FCITX_METASTRING_TEMPLATE_16(N##C, S), \ 187 FCITX_METASTRING_TEMPLATE_16(N##D, S), \ 188 FCITX_METASTRING_TEMPLATE_16(N##E, S), \ 189 FCITX_METASTRING_TEMPLATE_16(N##F, S) 192 #define fcitxMakeMetaString(STRING) \ 193 ::fcitx::MetaStringTrimType<FCITX_METASTRING_TEMPLATE_256(, STRING)> 196 #endif // _FCITX_UTILS_METASTRING_H_