summaryrefslogtreecommitdiff
path: root/src/common/string_util.cpp
diff options
context:
space:
mode:
authorGravatar Lioncash2018-04-29 18:37:15 -0400
committerGravatar Lioncash2018-04-29 18:52:33 -0400
commit3abba08080c88c49359e91ab2688c23fa066110a (patch)
treec354d58817e230cc2ba1306e449628ef8dafeb3d /src/common/string_util.cpp
parentMerge pull request #421 from Subv/sh_pred3 (diff)
downloadyuzu-3abba08080c88c49359e91ab2688c23fa066110a.tar.gz
yuzu-3abba08080c88c49359e91ab2688c23fa066110a.tar.xz
yuzu-3abba08080c88c49359e91ab2688c23fa066110a.zip
string_util: Remove StringFromFormat() and related functions
Given we utilize fmt, we don't need to provide our own functions for formatting anymore
Diffstat (limited to 'src/common/string_util.cpp')
-rw-r--r--src/common/string_util.cpp70
1 files changed, 0 insertions, 70 deletions
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) {
46 return true; 46 return true;
47} 47}
48 48
49bool CharArrayFromFormatV(char* out, int outsize, const char* format, va_list args) {
50 int writtenCount;
51
52#ifdef _MSC_VER
53 // You would think *printf are simple, right? Iterate on each character,
54 // if it's a format specifier handle it properly, etc.
55 //
56 // Nooooo. Not according to the C standard.
57 //
58 // According to the C99 standard (7.19.6.1 "The fprintf function")
59 // The format shall be a multibyte character sequence
60 //
61 // Because some character encodings might have '%' signs in the middle of
62 // a multibyte sequence (SJIS for example only specifies that the first
63 // byte of a 2 byte sequence is "high", the second byte can be anything),
64 // printf functions have to decode the multibyte sequences and try their
65 // best to not screw up.
66 //
67 // Unfortunately, on Windows, the locale for most languages is not UTF-8
68 // as we would need. Notably, for zh_TW, Windows chooses EUC-CN as the
69 // locale, and completely fails when trying to decode UTF-8 as EUC-CN.
70 //
71 // On the other hand, the fix is simple: because we use UTF-8, no such
72 // multibyte handling is required as we can simply assume that no '%' char
73 // will be present in the middle of a multibyte sequence.
74 //
75 // This is why we lookup an ANSI (cp1252) locale here and use _vsnprintf_l.
76 static locale_t c_locale = nullptr;
77 if (!c_locale)
78 c_locale = _create_locale(LC_ALL, ".1252");
79 writtenCount = _vsnprintf_l(out, outsize, format, c_locale, args);
80#else
81 writtenCount = vsnprintf(out, outsize, format, args);
82#endif
83
84 if (writtenCount > 0 && writtenCount < outsize) {
85 out[writtenCount] = '\0';
86 return true;
87 } else {
88 out[outsize - 1] = '\0';
89 return false;
90 }
91}
92
93std::string StringFromFormat(const char* format, ...) {
94 va_list args;
95 char* buf = nullptr;
96#ifdef _WIN32
97 int required = 0;
98
99 va_start(args, format);
100 required = _vscprintf(format, args);
101 buf = new char[required + 1];
102 CharArrayFromFormatV(buf, required + 1, format, args);
103 va_end(args);
104
105 std::string temp = buf;
106 delete[] buf;
107#else
108 va_start(args, format);
109 if (vasprintf(&buf, format, args) < 0)
110 NGLOG_ERROR(Common, "Unable to allocate memory for string");
111 va_end(args);
112
113 std::string temp = buf;
114 free(buf);
115#endif
116 return temp;
117}
118
119// For Debugging. Read out an u8 array. 49// For Debugging. Read out an u8 array.
120std::string ArrayToString(const u8* data, size_t size, int line_len, bool spaces) { 50std::string ArrayToString(const u8* data, size_t size, int line_len, bool spaces) {
121 std::ostringstream oss; 51 std::ostringstream oss;