Skip to content

Commit

Permalink
fix windows string type
Browse files Browse the repository at this point in the history
  • Loading branch information
Yangff committed Jun 8, 2024
1 parent 98849c3 commit 1dd73a4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
31 changes: 14 additions & 17 deletions UE4SS/src/GUI/LiveView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,15 +319,15 @@ namespace RC::GUI
{
if constexpr (std::is_same_v<typename ContainerType::value_type, FName>)
{
values_array.new_string(to_string(value.ToString()));
values_array.new_string(to_system(value.ToString()));
}
else if constexpr (std::is_same_v<typename ContainerType::value_type, bool>)
{
values_array.new_bool(value);
}
else
{
values_array.new_string(to_string(value));
values_array.new_string(to_system(value));
}
}
}
Expand Down Expand Up @@ -358,7 +358,7 @@ namespace RC::GUI
File::OverwriteExistingFile::Yes,
File::CreateIfNonExistent::Yes);
int32_t json_indent_level{};
json_file.write_file_string_to_file(json.serialize(JSON::ShouldFormat::Yes, &json_indent_level));
json_file.write_file_string_to_file(to_file(json.serialize(JSON::ShouldFormat::Yes, &json_indent_level)));
}

static auto save_filters_to_disk() -> void
Expand All @@ -368,29 +368,26 @@ namespace RC::GUI
});
}

template <typename Dest, typename T>
static auto to_dest_string(T&& input) {
STRING_DISPATCH_NOERR(std::decay_t<Dest>, to_string, to_wstring, to_u16string)
else if constexpr(std::is_same_v<std::decay_t<Dest>, FName>) {
return to_ue(input);
}
STRING_DISPATCH_ERROR(Dest)
}

template <typename T>
static auto json_array_to_filters_list(JSON::Array& json_array, std::vector<T>& list, SystemStringType type, std::string& internal_value) -> void
{
list.clear();
internal_value.clear();
internal_value.clear();
json_array.for_each([&](JSON::Value& item) {
if (!item.is<JSON::String>())
{
throw std::runtime_error{std::format("Invalid {} in 'filters.meta.json'", to_string(type))};
}

if constexpr (std::is_same_v<T, SystemStringType>)
{
list.emplace_back(to_system(item.as<JSON::String>()->get_view()));
}
else if constexpr(std::is_same_v<T, UEStringType> || std::is_same_v<T, FName>)
{
list.emplace_back(to_ue(item.as<JSON::String>()->get_view()));
}
else
{
static_assert(false, "Unsupported string type");
}
list.emplace_back(to_dest_string<T>(item.as<JSON::String>()->get_view()));

return LoopAction::Continue;
});
Expand Down
11 changes: 9 additions & 2 deletions deps/first/Helpers/include/Helpers/String.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ namespace RC
/* explode_by_occurrence -> END */

// ----------------------------- //
#define STRING_DISPATCH(STRING_T, ts, tw, tu16) \
#define STRING_DISPATCH_NOERR(STRING_T, ts, tw, tu16) \
if constexpr (std::is_same_v<STRING_T, std::string>) \
{ \
return ts(std::forward<T>(input)); \
Expand All @@ -226,11 +226,18 @@ namespace RC
else if constexpr (std::is_same_v<STRING_T, std::u16string>) \
{ \
return tu16(std::forward<T>(input)); \
} \
}

#define STRING_DISPATCH_ERROR(STRING_T) \
else \
{ \
static_assert(dependent_false<T>::value, "Unsupported " #STRING_T "."); \
}

#define STRING_DISPATCH(STRING_T, ts, tw, tu16) \
STRING_DISPATCH_NOERR(STRING_T, ts, tw, tu16) \
STRING_DISPATCH_ERROR(STRING_T)

// ----------------------------- //
#define PATH_QUIRK(STRINGT) \
if constexpr (std::is_same_v<std::decay_t<T>, std::filesystem::path> || std::is_same_v<std::decay_t<T>, const std::filesystem::path>) \
Expand Down

0 comments on commit 1dd73a4

Please sign in to comment.