mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-09-02 15:45:58 +00:00
Merge branch 'master' of https://github.com/dolphin-emu/dolphin
This commit is contained in:
commit
69ef86856d
100 changed files with 40756 additions and 25691 deletions
|
@ -7,12 +7,6 @@
|
|||
|
||||
namespace Common
|
||||
{
|
||||
template <typename T>
|
||||
constexpr T AlignUp(T value, size_t size)
|
||||
{
|
||||
static_assert(std::is_unsigned<T>(), "T must be an unsigned value.");
|
||||
return static_cast<T>(value + (size - value % size) % size);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
constexpr T AlignDown(T value, size_t size)
|
||||
|
@ -21,4 +15,11 @@ constexpr T AlignDown(T value, size_t size)
|
|||
return static_cast<T>(value - value % size);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
constexpr T AlignUp(T value, size_t size)
|
||||
{
|
||||
static_assert(std::is_unsigned<T>(), "T must be an unsigned value.");
|
||||
return AlignDown<T>(static_cast<T>(value + (size - 1)), size);
|
||||
}
|
||||
|
||||
} // namespace Common
|
||||
|
|
|
@ -135,6 +135,8 @@ add_library(common
|
|||
WorkQueueThread.h
|
||||
)
|
||||
|
||||
add_dependencies(common dolphin_scmrev)
|
||||
|
||||
if(NOT MSVC AND _M_ARM_64)
|
||||
set_source_files_properties(
|
||||
Crypto/AES.cpp
|
||||
|
@ -145,16 +147,17 @@ endif()
|
|||
target_link_libraries(common
|
||||
PUBLIC
|
||||
${CMAKE_THREAD_LIBS_INIT}
|
||||
enet
|
||||
enet::enet
|
||||
fmt::fmt
|
||||
${MBEDTLS_LIBRARIES}
|
||||
minizip-ng
|
||||
MbedTLS::mbedtls
|
||||
minizip::minizip
|
||||
sfml-network
|
||||
|
||||
PRIVATE
|
||||
${CURL_LIBRARIES}
|
||||
CURL::libcurl
|
||||
FatFs
|
||||
Iconv::Iconv
|
||||
${spng_target}
|
||||
spng::spng
|
||||
${VTUNE_LIBRARIES}
|
||||
)
|
||||
|
||||
|
|
|
@ -90,7 +90,8 @@ bool IsTitlePath(const std::string& path, std::optional<FromWhichRoot> from, u64
|
|||
}
|
||||
|
||||
u32 title_id_high, title_id_low;
|
||||
if (!AsciiToHex(components[0], title_id_high) || !AsciiToHex(components[1], title_id_low))
|
||||
if (Common::FromChars(components[0], title_id_high, 16).ec != std::errc{} ||
|
||||
Common::FromChars(components[1], title_id_low, 16).ec != std::errc{})
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -155,8 +156,11 @@ std::string UnescapeFileName(const std::string& filename)
|
|||
{
|
||||
u32 character;
|
||||
if (pos + 6 <= result.size() && result[pos + 4] == '_' && result[pos + 5] == '_')
|
||||
if (AsciiToHex(result.substr(pos + 2, 2), character))
|
||||
if (Common::FromChars(std::string_view{result}.substr(pos + 2, 2), character, 16).ec ==
|
||||
std::errc{})
|
||||
{
|
||||
result.replace(pos, 6, {static_cast<char>(character)});
|
||||
}
|
||||
|
||||
++pos;
|
||||
}
|
||||
|
|
|
@ -85,25 +85,6 @@ std::string HexDump(const u8* data, size_t size)
|
|||
return out;
|
||||
}
|
||||
|
||||
// faster than sscanf
|
||||
bool AsciiToHex(const std::string& _szValue, u32& result)
|
||||
{
|
||||
// Set errno to a good state.
|
||||
errno = 0;
|
||||
|
||||
char* endptr = nullptr;
|
||||
const u32 value = strtoul(_szValue.c_str(), &endptr, 16);
|
||||
|
||||
if (!endptr || *endptr)
|
||||
return false;
|
||||
|
||||
if (errno == ERANGE)
|
||||
return false;
|
||||
|
||||
result = value;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CharArrayFromFormatV(char* out, int outsize, const char* format, va_list args)
|
||||
{
|
||||
int writtenCount;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <charconv>
|
||||
#include <cstdarg>
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
|
@ -17,6 +18,22 @@
|
|||
|
||||
#include "Common/CommonTypes.h"
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <typename T>
|
||||
constexpr bool IsBooleanEnum()
|
||||
{
|
||||
if constexpr (std::is_enum_v<T>)
|
||||
{
|
||||
return std::is_same_v<std::underlying_type_t<T>, bool>;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
std::string StringFromFormatV(const char* format, va_list args);
|
||||
|
||||
std::string StringFromFormat(const char* format, ...)
|
||||
|
@ -54,8 +71,10 @@ void TruncateToCString(std::string* s);
|
|||
|
||||
bool TryParse(const std::string& str, bool* output);
|
||||
|
||||
template <typename T, std::enable_if_t<std::is_integral_v<T> || std::is_enum_v<T>>* = nullptr>
|
||||
bool TryParse(const std::string& str, T* output, int base = 0)
|
||||
template <typename T>
|
||||
requires(std::is_integral_v<T> ||
|
||||
(std::is_enum_v<T> && !detail::IsBooleanEnum<T>())) bool TryParse(const std::string& str,
|
||||
T* output, int base = 0)
|
||||
{
|
||||
char* end_ptr = nullptr;
|
||||
|
||||
|
@ -92,6 +111,17 @@ bool TryParse(const std::string& str, T* output, int base = 0)
|
|||
return true;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
requires(detail::IsBooleanEnum<T>()) bool TryParse(const std::string& str, T* output)
|
||||
{
|
||||
bool value;
|
||||
if (!TryParse(str, &value))
|
||||
return false;
|
||||
|
||||
*output = static_cast<T>(value);
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename T, std::enable_if_t<std::is_floating_point_v<T>>* = nullptr>
|
||||
bool TryParse(std::string str, T* const output)
|
||||
{
|
||||
|
@ -147,8 +177,24 @@ std::string ValueToString(T value)
|
|||
// Generates an hexdump-like representation of a binary data blob.
|
||||
std::string HexDump(const u8* data, size_t size);
|
||||
|
||||
// TODO: kill this
|
||||
bool AsciiToHex(const std::string& _szValue, u32& result);
|
||||
namespace Common
|
||||
{
|
||||
template <typename T, typename std::enable_if_t<std::is_integral_v<T>>* = nullptr>
|
||||
std::from_chars_result FromChars(std::string_view sv, T& value, int base = 10)
|
||||
{
|
||||
const char* const first = sv.data();
|
||||
const char* const last = first + sv.size();
|
||||
return std::from_chars(first, last, value, base);
|
||||
}
|
||||
template <typename T, typename std::enable_if_t<std::is_floating_point_v<T>>* = nullptr>
|
||||
std::from_chars_result FromChars(std::string_view sv, T& value,
|
||||
std::chars_format fmt = std::chars_format::general)
|
||||
{
|
||||
const char* const first = sv.data();
|
||||
const char* const last = first + sv.size();
|
||||
return std::from_chars(first, last, value, fmt);
|
||||
}
|
||||
}; // namespace Common
|
||||
|
||||
std::string TabsToSpaces(int tab_size, std::string str);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue