[core] Compile time string (#346)

This commit is contained in:
LoveSy 2021-03-13 03:57:21 +08:00 committed by GitHub
parent 04620f525e
commit 1de629f6e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 23 deletions

View File

@ -20,9 +20,6 @@
#pragma once
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wgnu-string-literal-operator-template"
#include "macros.h"
#include <dlfcn.h>
#include <sys/mman.h>
@ -199,13 +196,6 @@ namespace lspd {
template<typename This, typename Return, typename...Args>
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>
struct Hooker;
@ -259,5 +249,3 @@ namespace lspd {
} // namespace lspd
using lspd::operator ""_tstr;
#pragma clang diagnostic pop

View File

@ -48,19 +48,19 @@ inline constexpr bool is64 = Is64();
# define LP_SELECT(lp32, lp64) lp32
#endif
static const auto kEntryClassName = "org.lsposed.lspd.core.Main"s;
static const auto kClassLinkerClassName = "org.lsposed.lspd.nativebridge.ClassLinker"s;
static const auto kBridgeServiceClassName = "org.lsposed.lspd.service.BridgeService"s;
static const auto kDexPath = "framework/lspd.dex"s;
static constexpr auto kEntryClassName = "org.lsposed.lspd.core.Main"_tstr;
static constexpr auto kClassLinkerClassName = "org.lsposed.lspd.nativebridge.ClassLinker"_tstr;
static constexpr auto kBridgeServiceClassName = "org.lsposed.lspd.service.BridgeService"_tstr;
static constexpr auto kDexPath = "framework/lspd.dex"_tstr;
static const auto kLibArtName = "libart.so"s;
static const auto kLibFwName = "libandroidfw.so"s;
static constexpr auto kLibArtName = "libart.so"_tstr;
static constexpr auto kLibFwName = "libandroidfw.so"_tstr;
static const auto kLibBasePath =
LP_SELECT("/system/lib/"s,
"/system/lib64/"s);
static const auto kLibArtLegacyPath = kLibBasePath + kLibArtName;
static const auto kLibFwPath = kLibBasePath + kLibFwName;
static constexpr auto kLibBasePath =
LP_SELECT("/system/lib/"_tstr,
"/system/lib64/"_tstr);
static constexpr auto kLibArtLegacyPath = kLibBasePath + kLibArtName;
static constexpr auto kLibFwPath = kLibBasePath + kLibFwName;
inline constexpr const char *const BoolToString(bool b) {
return b ? "true" : "false";

View File

@ -20,6 +20,9 @@
#pragma once
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wgnu-string-literal-operator-template"
#include <string>
#include <filesystem>
#include <sys/system_properties.h>
@ -35,4 +38,42 @@ namespace lspd {
__system_property_get("ro.build.version.sdk", 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