[core] Compile time string (#346)
This commit is contained in:
parent
04620f525e
commit
1de629f6e8
|
|
@ -20,9 +20,6 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#pragma clang diagnostic push
|
|
||||||
#pragma clang diagnostic ignored "-Wgnu-string-literal-operator-template"
|
|
||||||
|
|
||||||
#include "macros.h"
|
#include "macros.h"
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
|
@ -199,13 +196,6 @@ namespace lspd {
|
||||||
template<typename This, typename Return, typename...Args>
|
template<typename This, typename Return, typename...Args>
|
||||||
MemberFunction(Return(This::*f)(Args...)) -> MemberFunction<Return(Args...), This>;
|
MemberFunction(Return(This::*f)(Args...)) -> MemberFunction<Return(Args...), This>;
|
||||||
|
|
||||||
template<char... chars> using tstring = std::integer_sequence<char, chars...>;
|
|
||||||
|
|
||||||
template<typename T, T... chars>
|
|
||||||
constexpr tstring<chars...> operator ""_tstr() {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename, typename>
|
template<typename, typename>
|
||||||
struct Hooker;
|
struct Hooker;
|
||||||
|
|
||||||
|
|
@ -259,5 +249,3 @@ namespace lspd {
|
||||||
} // namespace lspd
|
} // namespace lspd
|
||||||
|
|
||||||
using lspd::operator ""_tstr;
|
using lspd::operator ""_tstr;
|
||||||
|
|
||||||
#pragma clang diagnostic pop
|
|
||||||
|
|
|
||||||
|
|
@ -48,19 +48,19 @@ inline constexpr bool is64 = Is64();
|
||||||
# define LP_SELECT(lp32, lp64) lp32
|
# define LP_SELECT(lp32, lp64) lp32
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const auto kEntryClassName = "org.lsposed.lspd.core.Main"s;
|
static constexpr auto kEntryClassName = "org.lsposed.lspd.core.Main"_tstr;
|
||||||
static const auto kClassLinkerClassName = "org.lsposed.lspd.nativebridge.ClassLinker"s;
|
static constexpr auto kClassLinkerClassName = "org.lsposed.lspd.nativebridge.ClassLinker"_tstr;
|
||||||
static const auto kBridgeServiceClassName = "org.lsposed.lspd.service.BridgeService"s;
|
static constexpr auto kBridgeServiceClassName = "org.lsposed.lspd.service.BridgeService"_tstr;
|
||||||
static const auto kDexPath = "framework/lspd.dex"s;
|
static constexpr auto kDexPath = "framework/lspd.dex"_tstr;
|
||||||
|
|
||||||
static const auto kLibArtName = "libart.so"s;
|
static constexpr auto kLibArtName = "libart.so"_tstr;
|
||||||
static const auto kLibFwName = "libandroidfw.so"s;
|
static constexpr auto kLibFwName = "libandroidfw.so"_tstr;
|
||||||
|
|
||||||
static const auto kLibBasePath =
|
static constexpr auto kLibBasePath =
|
||||||
LP_SELECT("/system/lib/"s,
|
LP_SELECT("/system/lib/"_tstr,
|
||||||
"/system/lib64/"s);
|
"/system/lib64/"_tstr);
|
||||||
static const auto kLibArtLegacyPath = kLibBasePath + kLibArtName;
|
static constexpr auto kLibArtLegacyPath = kLibBasePath + kLibArtName;
|
||||||
static const auto kLibFwPath = kLibBasePath + kLibFwName;
|
static constexpr auto kLibFwPath = kLibBasePath + kLibFwName;
|
||||||
|
|
||||||
inline constexpr const char *const BoolToString(bool b) {
|
inline constexpr const char *const BoolToString(bool b) {
|
||||||
return b ? "true" : "false";
|
return b ? "true" : "false";
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,9 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#pragma clang diagnostic push
|
||||||
|
#pragma clang diagnostic ignored "-Wgnu-string-literal-operator-template"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <sys/system_properties.h>
|
#include <sys/system_properties.h>
|
||||||
|
|
@ -35,4 +38,42 @@ namespace lspd {
|
||||||
__system_property_get("ro.build.version.sdk", prop_value);
|
__system_property_get("ro.build.version.sdk", prop_value);
|
||||||
return atoi(prop_value);
|
return atoi(prop_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<char... chars>
|
||||||
|
struct tstring : public std::integer_sequence<char, chars...> {
|
||||||
|
const char *c_str() const {
|
||||||
|
return str_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
operator std::string_view() const {
|
||||||
|
return c_str();
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
constexpr static char str_[]{chars..., '\0'};
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T, T... chars>
|
||||||
|
inline constexpr tstring<chars...> operator ""_tstr() {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<char... as, char... bs>
|
||||||
|
inline constexpr tstring<as..., bs...>
|
||||||
|
operator+(const tstring<as...> &, const tstring<bs...> &) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
template<char... as>
|
||||||
|
inline constexpr auto operator+(const std::string &a, const tstring<as...> &) {
|
||||||
|
return a + std::string{as..., '\0'};
|
||||||
|
}
|
||||||
|
|
||||||
|
template<char... as>
|
||||||
|
inline constexpr auto operator+(const tstring<as...> &, const std::string &b) {
|
||||||
|
return std::string{as..., '\0'} + b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma clang diagnostic pop
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue