diff options
-rw-r--r-- | src/common/string_util.cpp | 60 | ||||
-rw-r--r-- | src/common/string_util.h | 2 | ||||
-rw-r--r-- | src/core/hle/service/set/set.cpp | 55 | ||||
-rw-r--r-- | src/core/hle/service/set/set.h | 1 |
4 files changed, 65 insertions, 53 deletions
diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp index f3ad3d68a..1f0456aee 100644 --- a/src/common/string_util.cpp +++ b/src/common/string_util.cpp @@ -162,21 +162,21 @@ void SplitString(const std::string& str, const char delim, std::vector<std::stri std::istringstream iss(str); output.resize(1); - while (std::getline(iss, *output.rbegin(), delim)) - output.push_back(""); + while (std::getline(iss, *output.rbegin(), delim)) { + output.emplace_back(); + } output.pop_back(); } -std::string TabsToSpaces(int tab_size, const std::string& in) { - const std::string spaces(tab_size, ' '); - std::string out(in); - +std::string TabsToSpaces(int tab_size, std::string in) { size_t i = 0; - while (out.npos != (i = out.find('\t'))) - out.replace(i, 1, spaces); - return out; + while ((i = in.find('\t')) != std::string::npos) { + in.replace(i, 1, tab_size, ' '); + } + + return in; } std::string ReplaceAll(std::string result, const std::string& src, const std::string& dest) { @@ -220,31 +220,37 @@ std::u16string UTF8ToUTF16(const std::string& input) { } static std::wstring CPToUTF16(u32 code_page, const std::string& input) { - auto const size = + const auto size = MultiByteToWideChar(code_page, 0, input.data(), static_cast<int>(input.size()), nullptr, 0); - std::wstring output; - output.resize(size); + if (size == 0) { + return L""; + } + + std::wstring output(size, L'\0'); - if (size == 0 || - size != MultiByteToWideChar(code_page, 0, input.data(), static_cast<int>(input.size()), - &output[0], static_cast<int>(output.size()))) + if (size != MultiByteToWideChar(code_page, 0, input.data(), static_cast<int>(input.size()), + &output[0], static_cast<int>(output.size()))) { output.clear(); + } return output; } std::string UTF16ToUTF8(const std::wstring& input) { - auto const size = WideCharToMultiByte(CP_UTF8, 0, input.data(), static_cast<int>(input.size()), + const auto size = WideCharToMultiByte(CP_UTF8, 0, input.data(), static_cast<int>(input.size()), nullptr, 0, nullptr, nullptr); + if (size == 0) { + return ""; + } - std::string output; - output.resize(size); + std::string output(size, '\0'); - if (size == 0 || - size != WideCharToMultiByte(CP_UTF8, 0, input.data(), static_cast<int>(input.size()), - &output[0], static_cast<int>(output.size()), nullptr, nullptr)) + if (size != WideCharToMultiByte(CP_UTF8, 0, input.data(), static_cast<int>(input.size()), + &output[0], static_cast<int>(output.size()), nullptr, + nullptr)) { output.clear(); + } return output; } @@ -265,8 +271,6 @@ std::string CP1252ToUTF8(const std::string& input) { template <typename T> static std::string CodeToUTF8(const char* fromcode, const std::basic_string<T>& input) { - std::string result; - iconv_t const conv_desc = iconv_open("UTF-8", fromcode); if ((iconv_t)(-1) == conv_desc) { LOG_ERROR(Common, "Iconv initialization failure [{}]: {}", fromcode, strerror(errno)); @@ -278,8 +282,7 @@ static std::string CodeToUTF8(const char* fromcode, const std::basic_string<T>& // Multiply by 4, which is the max number of bytes to encode a codepoint const size_t out_buffer_size = 4 * in_bytes; - std::string out_buffer; - out_buffer.resize(out_buffer_size); + std::string out_buffer(out_buffer_size, '\0'); auto src_buffer = &input[0]; size_t src_bytes = in_bytes; @@ -304,6 +307,7 @@ static std::string CodeToUTF8(const char* fromcode, const std::basic_string<T>& } } + std::string result; out_buffer.resize(out_buffer_size - dst_bytes); out_buffer.swap(result); @@ -313,8 +317,6 @@ static std::string CodeToUTF8(const char* fromcode, const std::basic_string<T>& } std::u16string UTF8ToUTF16(const std::string& input) { - std::u16string result; - iconv_t const conv_desc = iconv_open("UTF-16LE", "UTF-8"); if ((iconv_t)(-1) == conv_desc) { LOG_ERROR(Common, "Iconv initialization failure [UTF-8]: {}", strerror(errno)); @@ -326,8 +328,7 @@ std::u16string UTF8ToUTF16(const std::string& input) { // Multiply by 4, which is the max number of bytes to encode a codepoint const size_t out_buffer_size = 4 * sizeof(char16_t) * in_bytes; - std::u16string out_buffer; - out_buffer.resize(out_buffer_size); + std::u16string out_buffer(out_buffer_size, char16_t{}); char* src_buffer = const_cast<char*>(&input[0]); size_t src_bytes = in_bytes; @@ -352,6 +353,7 @@ std::u16string UTF8ToUTF16(const std::string& input) { } } + std::u16string result; out_buffer.resize(out_buffer_size - dst_bytes); out_buffer.swap(result); diff --git a/src/common/string_util.h b/src/common/string_util.h index daa071f83..4a2143b59 100644 --- a/src/common/string_util.h +++ b/src/common/string_util.h @@ -57,7 +57,7 @@ static bool TryParse(const std::string& str, N* const output) { return false; } -std::string TabsToSpaces(int tab_size, const std::string& in); +std::string TabsToSpaces(int tab_size, std::string in); void SplitString(const std::string& str, char delim, std::vector<std::string>& output); diff --git a/src/core/hle/service/set/set.cpp b/src/core/hle/service/set/set.cpp index 886133b74..1651f6122 100644 --- a/src/core/hle/service/set/set.cpp +++ b/src/core/hle/service/set/set.cpp @@ -11,31 +11,40 @@ namespace Service::Set { +constexpr std::array<LanguageCode, 17> available_language_codes = {{ + LanguageCode::JA, + LanguageCode::EN_US, + LanguageCode::FR, + LanguageCode::DE, + LanguageCode::IT, + LanguageCode::ES, + LanguageCode::ZH_CN, + LanguageCode::KO, + LanguageCode::NL, + LanguageCode::PT, + LanguageCode::RU, + LanguageCode::ZH_TW, + LanguageCode::EN_GB, + LanguageCode::FR_CA, + LanguageCode::ES_419, + LanguageCode::ZH_HANS, + LanguageCode::ZH_HANT, +}}; + void SET::GetAvailableLanguageCodes(Kernel::HLERequestContext& ctx) { - static constexpr std::array<LanguageCode, 17> available_language_codes = {{ - LanguageCode::JA, - LanguageCode::EN_US, - LanguageCode::FR, - LanguageCode::DE, - LanguageCode::IT, - LanguageCode::ES, - LanguageCode::ZH_CN, - LanguageCode::KO, - LanguageCode::NL, - LanguageCode::PT, - LanguageCode::RU, - LanguageCode::ZH_TW, - LanguageCode::EN_GB, - LanguageCode::FR_CA, - LanguageCode::ES_419, - LanguageCode::ZH_HANS, - LanguageCode::ZH_HANT, - }}; ctx.WriteBuffer(available_language_codes); - IPC::ResponseBuilder rb{ctx, 4}; + IPC::ResponseBuilder rb{ctx, 3}; + rb.Push(RESULT_SUCCESS); + rb.Push(static_cast<u32>(available_language_codes.size())); + + LOG_DEBUG(Service_SET, "called"); +} + +void SET::GetAvailableLanguageCodeCount(Kernel::HLERequestContext& ctx) { + IPC::ResponseBuilder rb{ctx, 3}; rb.Push(RESULT_SUCCESS); - rb.Push(static_cast<u64>(available_language_codes.size())); + rb.Push(static_cast<u32>(available_language_codes.size())); LOG_DEBUG(Service_SET, "called"); } @@ -45,10 +54,10 @@ SET::SET() : ServiceFramework("set") { {0, nullptr, "GetLanguageCode"}, {1, &SET::GetAvailableLanguageCodes, "GetAvailableLanguageCodes"}, {2, nullptr, "MakeLanguageCode"}, - {3, nullptr, "GetAvailableLanguageCodeCount"}, + {3, &SET::GetAvailableLanguageCodeCount, "GetAvailableLanguageCodeCount"}, {4, nullptr, "GetRegionCode"}, {5, &SET::GetAvailableLanguageCodes, "GetAvailableLanguageCodes2"}, - {6, nullptr, "GetAvailableLanguageCodeCount2"}, + {6, &SET::GetAvailableLanguageCodeCount, "GetAvailableLanguageCodeCount2"}, {7, nullptr, "GetKeyCodeMap"}, {8, nullptr, "GetQuestFlag"}, }; diff --git a/src/core/hle/service/set/set.h b/src/core/hle/service/set/set.h index ec0df0152..a2472ec4c 100644 --- a/src/core/hle/service/set/set.h +++ b/src/core/hle/service/set/set.h @@ -36,6 +36,7 @@ public: private: void GetAvailableLanguageCodes(Kernel::HLERequestContext& ctx); + void GetAvailableLanguageCodeCount(Kernel::HLERequestContext& ctx); }; } // namespace Service::Set |