summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLioncash <mathew1800@gmail.com>2018-04-30 00:37:15 +0200
committerLioncash <mathew1800@gmail.com>2018-04-30 00:52:33 +0200
commit3abba08080c88c49359e91ab2688c23fa066110a (patch)
treec354d58817e230cc2ba1306e449628ef8dafeb3d
parentMerge pull request #421 from Subv/sh_pred3 (diff)
downloadyuzu-3abba08080c88c49359e91ab2688c23fa066110a.tar
yuzu-3abba08080c88c49359e91ab2688c23fa066110a.tar.gz
yuzu-3abba08080c88c49359e91ab2688c23fa066110a.tar.bz2
yuzu-3abba08080c88c49359e91ab2688c23fa066110a.tar.lz
yuzu-3abba08080c88c49359e91ab2688c23fa066110a.tar.xz
yuzu-3abba08080c88c49359e91ab2688c23fa066110a.tar.zst
yuzu-3abba08080c88c49359e91ab2688c23fa066110a.zip
Diffstat (limited to '')
-rw-r--r--src/common/memory_util.cpp3
-rw-r--r--src/common/string_util.cpp70
-rw-r--r--src/common/string_util.h14
-rw-r--r--src/common/timer.cpp13
-rw-r--r--src/core/hle/kernel/svc.cpp2
-rw-r--r--src/core/hle/service/service.cpp5
-rw-r--r--src/yuzu/bootmanager.cpp6
-rw-r--r--src/yuzu_cmd/emu_window/emu_window_sdl2.cpp5
8 files changed, 19 insertions, 99 deletions
diff --git a/src/common/memory_util.cpp b/src/common/memory_util.cpp
index 79b7215d3..4d1ec8fb9 100644
--- a/src/common/memory_util.cpp
+++ b/src/common/memory_util.cpp
@@ -167,8 +167,7 @@ std::string MemUsage() {
return "MemUsage Error";
if (GetProcessMemoryInfo(hProcess, &pmc, sizeof(pmc)))
- Ret = Common::StringFromFormat(
- "%s K", Common::ThousandSeparate(pmc.WorkingSetSize / 1024, 7).c_str());
+ Ret = fmt::format("{} K", Common::ThousandSeparate(pmc.WorkingSetSize / 1024, 7));
CloseHandle(hProcess);
return Ret;
diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp
index 96c52e3ba..1d952874d 100644
--- a/src/common/string_util.cpp
+++ b/src/common/string_util.cpp
@@ -46,76 +46,6 @@ bool AsciiToHex(const char* _szValue, u32& result) {
return true;
}
-bool CharArrayFromFormatV(char* out, int outsize, const char* format, va_list args) {
- int writtenCount;
-
-#ifdef _MSC_VER
- // You would think *printf are simple, right? Iterate on each character,
- // if it's a format specifier handle it properly, etc.
- //
- // Nooooo. Not according to the C standard.
- //
- // According to the C99 standard (7.19.6.1 "The fprintf function")
- // The format shall be a multibyte character sequence
- //
- // Because some character encodings might have '%' signs in the middle of
- // a multibyte sequence (SJIS for example only specifies that the first
- // byte of a 2 byte sequence is "high", the second byte can be anything),
- // printf functions have to decode the multibyte sequences and try their
- // best to not screw up.
- //
- // Unfortunately, on Windows, the locale for most languages is not UTF-8
- // as we would need. Notably, for zh_TW, Windows chooses EUC-CN as the
- // locale, and completely fails when trying to decode UTF-8 as EUC-CN.
- //
- // On the other hand, the fix is simple: because we use UTF-8, no such
- // multibyte handling is required as we can simply assume that no '%' char
- // will be present in the middle of a multibyte sequence.
- //
- // This is why we lookup an ANSI (cp1252) locale here and use _vsnprintf_l.
- static locale_t c_locale = nullptr;
- if (!c_locale)
- c_locale = _create_locale(LC_ALL, ".1252");
- writtenCount = _vsnprintf_l(out, outsize, format, c_locale, args);
-#else
- writtenCount = vsnprintf(out, outsize, format, args);
-#endif
-
- if (writtenCount > 0 && writtenCount < outsize) {
- out[writtenCount] = '\0';
- return true;
- } else {
- out[outsize - 1] = '\0';
- return false;
- }
-}
-
-std::string StringFromFormat(const char* format, ...) {
- va_list args;
- char* buf = nullptr;
-#ifdef _WIN32
- int required = 0;
-
- va_start(args, format);
- required = _vscprintf(format, args);
- buf = new char[required + 1];
- CharArrayFromFormatV(buf, required + 1, format, args);
- va_end(args);
-
- std::string temp = buf;
- delete[] buf;
-#else
- va_start(args, format);
- if (vasprintf(&buf, format, args) < 0)
- NGLOG_ERROR(Common, "Unable to allocate memory for string");
- va_end(args);
-
- std::string temp = buf;
- free(buf);
-#endif
- return temp;
-}
-
// For Debugging. Read out an u8 array.
std::string ArrayToString(const u8* data, size_t size, int line_len, bool spaces) {
std::ostringstream oss;
diff --git a/src/common/string_util.h b/src/common/string_util.h
index ec0c31a24..65e4ea5d3 100644
--- a/src/common/string_util.h
+++ b/src/common/string_util.h
@@ -4,7 +4,6 @@
#pragma once
-#include <cstdarg>
#include <cstddef>
#include <iomanip>
#include <sstream>
@@ -20,19 +19,6 @@ std::string ToLower(std::string str);
/// Make a string uppercase
std::string ToUpper(std::string str);
-std::string StringFromFormat(const char* format, ...);
-// Cheap!
-bool CharArrayFromFormatV(char* out, int outsize, const char* format, va_list args);
-
-template <size_t Count>
-inline void CharArrayFromFormat(char (&out)[Count], const char* format, ...) {
- va_list args;
- va_start(args, format);
- CharArrayFromFormatV(out, Count, format, args);
- va_end(args);
-}
-
-// Good
std::string ArrayToString(const u8* data, size_t size, int line_len = 20, bool spaces = true);
std::string StripSpaces(const std::string& s);
diff --git a/src/common/timer.cpp b/src/common/timer.cpp
index c9803109e..f0c5b1a43 100644
--- a/src/common/timer.cpp
+++ b/src/common/timer.cpp
@@ -2,7 +2,10 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
-#include <time.h>
+#include <ctime>
+
+#include <fmt/format.h>
+
#ifdef _WIN32
#include <windows.h>
// windows.h needs to be included before other windows headers
@@ -104,8 +107,8 @@ std::string Timer::GetTimeElapsedFormatted() const {
// Hours
u32 Hours = Minutes / 60;
- std::string TmpStr = StringFromFormat("%02i:%02i:%02i:%03i", Hours, Minutes % 60, Seconds % 60,
- Milliseconds % 1000);
+ std::string TmpStr = fmt::format("{:02}:{:02}:{:02}:{:03}", Hours, Minutes % 60, Seconds % 60,
+ Milliseconds % 1000);
return TmpStr;
}
@@ -165,11 +168,11 @@ std::string Timer::GetTimeFormatted() {
#ifdef _WIN32
struct timeb tp;
(void)::ftime(&tp);
- return StringFromFormat("%s:%03i", tmp, tp.millitm);
+ return fmt::format("{}:{:03}", tmp, tp.millitm);
#else
struct timeval t;
(void)gettimeofday(&t, nullptr);
- return StringFromFormat("%s:%03d", tmp, (int)(t.tv_usec / 1000));
+ return fmt::format("{}:{:03}", tmp, static_cast<int>(t.tv_usec / 1000));
#endif
}
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index 4df38c977..e2da68227 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -510,7 +510,7 @@ static void ExitProcess() {
/// Creates a new thread
static ResultCode CreateThread(Handle* out_handle, VAddr entry_point, u64 arg, VAddr stack_top,
u32 priority, s32 processor_id) {
- std::string name = Common::StringFromFormat("unknown-%llx", entry_point);
+ std::string name = fmt::format("unknown-{:X}", entry_point);
if (priority > THREADPRIO_LOWEST) {
return ERR_OUT_OF_RANGE;
diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp
index 94de21ae1..7a5f08b24 100644
--- a/src/core/hle/service/service.cpp
+++ b/src/core/hle/service/service.cpp
@@ -58,10 +58,9 @@ static std::string MakeFunctionString(const char* name, const char* port_name,
// Number of params == bits 0-5 + bits 6-11
int num_params = (cmd_buff[0] & 0x3F) + ((cmd_buff[0] >> 6) & 0x3F);
- std::string function_string =
- Common::StringFromFormat("function '%s': port=%s", name, port_name);
+ std::string function_string = fmt::format("function '{}': port={}", name, port_name);
for (int i = 1; i <= num_params; ++i) {
- function_string += Common::StringFromFormat(", cmd_buff[%i]=0x%X", i, cmd_buff[i]);
+ function_string += fmt::format(", cmd_buff[{}]={:#X}", i, cmd_buff[i]);
}
return function_string;
}
diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp
index 469988d63..5c17cd0d9 100644
--- a/src/yuzu/bootmanager.cpp
+++ b/src/yuzu/bootmanager.cpp
@@ -4,6 +4,8 @@
#include <QScreen>
#include <QWindow>
+#include <fmt/format.h>
+
#include "common/microprofile.h"
#include "common/scm_rev.h"
#include "common/string_util.h"
@@ -102,8 +104,8 @@ private:
GRenderWindow::GRenderWindow(QWidget* parent, EmuThread* emu_thread)
: QWidget(parent), child(nullptr), emu_thread(emu_thread) {
- std::string window_title = Common::StringFromFormat("yuzu %s| %s-%s", Common::g_build_name,
- Common::g_scm_branch, Common::g_scm_desc);
+ std::string window_title = fmt::format("yuzu {} | {}-{}", Common::g_build_name,
+ Common::g_scm_branch, Common::g_scm_desc);
setWindowTitle(QString::fromStdString(window_title));
InputCommon::Init();
diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp
index b6ed0c498..e21de6f21 100644
--- a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp
+++ b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp
@@ -7,6 +7,7 @@
#include <string>
#define SDL_MAIN_HANDLED
#include <SDL.h>
+#include <fmt/format.h>
#include <glad/glad.h>
#include "common/logging/log.h"
#include "common/scm_rev.h"
@@ -97,8 +98,8 @@ EmuWindow_SDL2::EmuWindow_SDL2(bool fullscreen) {
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0);
- std::string window_title = Common::StringFromFormat("yuzu %s| %s-%s ", Common::g_build_name,
- Common::g_scm_branch, Common::g_scm_desc);
+ std::string window_title = fmt::format("yuzu {} | {}-{}", Common::g_build_name,
+ Common::g_scm_branch, Common::g_scm_desc);
render_window =
SDL_CreateWindow(window_title.c_str(),
SDL_WINDOWPOS_UNDEFINED, // x position