diff options
Diffstat (limited to 'src')
| -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 | |||
| 162 | std::istringstream iss(str); | 162 | std::istringstream iss(str); |
| 163 | output.resize(1); | 163 | output.resize(1); |
| 164 | 164 | ||
| 165 | while (std::getline(iss, *output.rbegin(), delim)) | 165 | while (std::getline(iss, *output.rbegin(), delim)) { |
| 166 | output.push_back(""); | 166 | output.emplace_back(); |
| 167 | } | ||
| 167 | 168 | ||
| 168 | output.pop_back(); | 169 | output.pop_back(); |
| 169 | } | 170 | } |
| 170 | 171 | ||
| 171 | std::string TabsToSpaces(int tab_size, const std::string& in) { | 172 | std::string TabsToSpaces(int tab_size, std::string in) { |
| 172 | const std::string spaces(tab_size, ' '); | ||
| 173 | std::string out(in); | ||
| 174 | |||
| 175 | size_t i = 0; | 173 | size_t i = 0; |
| 176 | while (out.npos != (i = out.find('\t'))) | ||
| 177 | out.replace(i, 1, spaces); | ||
| 178 | 174 | ||
| 179 | return out; | 175 | while ((i = in.find('\t')) != std::string::npos) { |
| 176 | in.replace(i, 1, tab_size, ' '); | ||
| 177 | } | ||
| 178 | |||
| 179 | return in; | ||
| 180 | } | 180 | } |
| 181 | 181 | ||
| 182 | std::string ReplaceAll(std::string result, const std::string& src, const std::string& dest) { | 182 | 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) { | |||
| 220 | } | 220 | } |
| 221 | 221 | ||
| 222 | static std::wstring CPToUTF16(u32 code_page, const std::string& input) { | 222 | static std::wstring CPToUTF16(u32 code_page, const std::string& input) { |
| 223 | auto const size = | 223 | const auto size = |
| 224 | MultiByteToWideChar(code_page, 0, input.data(), static_cast<int>(input.size()), nullptr, 0); | 224 | MultiByteToWideChar(code_page, 0, input.data(), static_cast<int>(input.size()), nullptr, 0); |
| 225 | 225 | ||
| 226 | std::wstring output; | 226 | if (size == 0) { |
| 227 | output.resize(size); | 227 | return L""; |
| 228 | } | ||
| 229 | |||
| 230 | std::wstring output(size, L'\0'); | ||
| 228 | 231 | ||
| 229 | if (size == 0 || | 232 | if (size != MultiByteToWideChar(code_page, 0, input.data(), static_cast<int>(input.size()), |
| 230 | size != MultiByteToWideChar(code_page, 0, input.data(), static_cast<int>(input.size()), | 233 | &output[0], static_cast<int>(output.size()))) { |
| 231 | &output[0], static_cast<int>(output.size()))) | ||
| 232 | output.clear(); | 234 | output.clear(); |
| 235 | } | ||
| 233 | 236 | ||
| 234 | return output; | 237 | return output; |
| 235 | } | 238 | } |
| 236 | 239 | ||
| 237 | std::string UTF16ToUTF8(const std::wstring& input) { | 240 | std::string UTF16ToUTF8(const std::wstring& input) { |
| 238 | auto const size = WideCharToMultiByte(CP_UTF8, 0, input.data(), static_cast<int>(input.size()), | 241 | const auto size = WideCharToMultiByte(CP_UTF8, 0, input.data(), static_cast<int>(input.size()), |
| 239 | nullptr, 0, nullptr, nullptr); | 242 | nullptr, 0, nullptr, nullptr); |
| 243 | if (size == 0) { | ||
| 244 | return ""; | ||
| 245 | } | ||
| 240 | 246 | ||
| 241 | std::string output; | 247 | std::string output(size, '\0'); |
| 242 | output.resize(size); | ||
| 243 | 248 | ||
| 244 | if (size == 0 || | 249 | if (size != WideCharToMultiByte(CP_UTF8, 0, input.data(), static_cast<int>(input.size()), |
| 245 | size != WideCharToMultiByte(CP_UTF8, 0, input.data(), static_cast<int>(input.size()), | 250 | &output[0], static_cast<int>(output.size()), nullptr, |
| 246 | &output[0], static_cast<int>(output.size()), nullptr, nullptr)) | 251 | nullptr)) { |
| 247 | output.clear(); | 252 | output.clear(); |
| 253 | } | ||
| 248 | 254 | ||
| 249 | return output; | 255 | return output; |
| 250 | } | 256 | } |
| @@ -265,8 +271,6 @@ std::string CP1252ToUTF8(const std::string& input) { | |||
| 265 | 271 | ||
| 266 | template <typename T> | 272 | template <typename T> |
| 267 | static std::string CodeToUTF8(const char* fromcode, const std::basic_string<T>& input) { | 273 | static std::string CodeToUTF8(const char* fromcode, const std::basic_string<T>& input) { |
| 268 | std::string result; | ||
| 269 | |||
| 270 | iconv_t const conv_desc = iconv_open("UTF-8", fromcode); | 274 | iconv_t const conv_desc = iconv_open("UTF-8", fromcode); |
| 271 | if ((iconv_t)(-1) == conv_desc) { | 275 | if ((iconv_t)(-1) == conv_desc) { |
| 272 | LOG_ERROR(Common, "Iconv initialization failure [{}]: {}", fromcode, strerror(errno)); | 276 | 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>& | |||
| 278 | // Multiply by 4, which is the max number of bytes to encode a codepoint | 282 | // Multiply by 4, which is the max number of bytes to encode a codepoint |
| 279 | const size_t out_buffer_size = 4 * in_bytes; | 283 | const size_t out_buffer_size = 4 * in_bytes; |
| 280 | 284 | ||
| 281 | std::string out_buffer; | 285 | std::string out_buffer(out_buffer_size, '\0'); |
| 282 | out_buffer.resize(out_buffer_size); | ||
| 283 | 286 | ||
| 284 | auto src_buffer = &input[0]; | 287 | auto src_buffer = &input[0]; |
| 285 | size_t src_bytes = in_bytes; | 288 | size_t src_bytes = in_bytes; |
| @@ -304,6 +307,7 @@ static std::string CodeToUTF8(const char* fromcode, const std::basic_string<T>& | |||
| 304 | } | 307 | } |
| 305 | } | 308 | } |
| 306 | 309 | ||
| 310 | std::string result; | ||
| 307 | out_buffer.resize(out_buffer_size - dst_bytes); | 311 | out_buffer.resize(out_buffer_size - dst_bytes); |
| 308 | out_buffer.swap(result); | 312 | out_buffer.swap(result); |
| 309 | 313 | ||
| @@ -313,8 +317,6 @@ static std::string CodeToUTF8(const char* fromcode, const std::basic_string<T>& | |||
| 313 | } | 317 | } |
| 314 | 318 | ||
| 315 | std::u16string UTF8ToUTF16(const std::string& input) { | 319 | std::u16string UTF8ToUTF16(const std::string& input) { |
| 316 | std::u16string result; | ||
| 317 | |||
| 318 | iconv_t const conv_desc = iconv_open("UTF-16LE", "UTF-8"); | 320 | iconv_t const conv_desc = iconv_open("UTF-16LE", "UTF-8"); |
| 319 | if ((iconv_t)(-1) == conv_desc) { | 321 | if ((iconv_t)(-1) == conv_desc) { |
| 320 | LOG_ERROR(Common, "Iconv initialization failure [UTF-8]: {}", strerror(errno)); | 322 | LOG_ERROR(Common, "Iconv initialization failure [UTF-8]: {}", strerror(errno)); |
| @@ -326,8 +328,7 @@ std::u16string UTF8ToUTF16(const std::string& input) { | |||
| 326 | // Multiply by 4, which is the max number of bytes to encode a codepoint | 328 | // Multiply by 4, which is the max number of bytes to encode a codepoint |
| 327 | const size_t out_buffer_size = 4 * sizeof(char16_t) * in_bytes; | 329 | const size_t out_buffer_size = 4 * sizeof(char16_t) * in_bytes; |
| 328 | 330 | ||
| 329 | std::u16string out_buffer; | 331 | std::u16string out_buffer(out_buffer_size, char16_t{}); |
| 330 | out_buffer.resize(out_buffer_size); | ||
| 331 | 332 | ||
| 332 | char* src_buffer = const_cast<char*>(&input[0]); | 333 | char* src_buffer = const_cast<char*>(&input[0]); |
| 333 | size_t src_bytes = in_bytes; | 334 | size_t src_bytes = in_bytes; |
| @@ -352,6 +353,7 @@ std::u16string UTF8ToUTF16(const std::string& input) { | |||
| 352 | } | 353 | } |
| 353 | } | 354 | } |
| 354 | 355 | ||
| 356 | std::u16string result; | ||
| 355 | out_buffer.resize(out_buffer_size - dst_bytes); | 357 | out_buffer.resize(out_buffer_size - dst_bytes); |
| 356 | out_buffer.swap(result); | 358 | out_buffer.swap(result); |
| 357 | 359 | ||
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) { | |||
| 57 | return false; | 57 | return false; |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | std::string TabsToSpaces(int tab_size, const std::string& in); | 60 | std::string TabsToSpaces(int tab_size, std::string in); |
| 61 | 61 | ||
| 62 | void SplitString(const std::string& str, char delim, std::vector<std::string>& output); | 62 | void SplitString(const std::string& str, char delim, std::vector<std::string>& output); |
| 63 | 63 | ||
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 @@ | |||
| 11 | 11 | ||
| 12 | namespace Service::Set { | 12 | namespace Service::Set { |
| 13 | 13 | ||
| 14 | constexpr std::array<LanguageCode, 17> available_language_codes = {{ | ||
| 15 | LanguageCode::JA, | ||
| 16 | LanguageCode::EN_US, | ||
| 17 | LanguageCode::FR, | ||
| 18 | LanguageCode::DE, | ||
| 19 | LanguageCode::IT, | ||
| 20 | LanguageCode::ES, | ||
| 21 | LanguageCode::ZH_CN, | ||
| 22 | LanguageCode::KO, | ||
| 23 | LanguageCode::NL, | ||
| 24 | LanguageCode::PT, | ||
| 25 | LanguageCode::RU, | ||
| 26 | LanguageCode::ZH_TW, | ||
| 27 | LanguageCode::EN_GB, | ||
| 28 | LanguageCode::FR_CA, | ||
| 29 | LanguageCode::ES_419, | ||
| 30 | LanguageCode::ZH_HANS, | ||
| 31 | LanguageCode::ZH_HANT, | ||
| 32 | }}; | ||
| 33 | |||
| 14 | void SET::GetAvailableLanguageCodes(Kernel::HLERequestContext& ctx) { | 34 | void SET::GetAvailableLanguageCodes(Kernel::HLERequestContext& ctx) { |
| 15 | static constexpr std::array<LanguageCode, 17> available_language_codes = {{ | ||
| 16 | LanguageCode::JA, | ||
| 17 | LanguageCode::EN_US, | ||
| 18 | LanguageCode::FR, | ||
| 19 | LanguageCode::DE, | ||
| 20 | LanguageCode::IT, | ||
| 21 | LanguageCode::ES, | ||
| 22 | LanguageCode::ZH_CN, | ||
| 23 | LanguageCode::KO, | ||
| 24 | LanguageCode::NL, | ||
| 25 | LanguageCode::PT, | ||
| 26 | LanguageCode::RU, | ||
| 27 | LanguageCode::ZH_TW, | ||
| 28 | LanguageCode::EN_GB, | ||
| 29 | LanguageCode::FR_CA, | ||
| 30 | LanguageCode::ES_419, | ||
| 31 | LanguageCode::ZH_HANS, | ||
| 32 | LanguageCode::ZH_HANT, | ||
| 33 | }}; | ||
| 34 | ctx.WriteBuffer(available_language_codes); | 35 | ctx.WriteBuffer(available_language_codes); |
| 35 | 36 | ||
| 36 | IPC::ResponseBuilder rb{ctx, 4}; | 37 | IPC::ResponseBuilder rb{ctx, 3}; |
| 38 | rb.Push(RESULT_SUCCESS); | ||
| 39 | rb.Push(static_cast<u32>(available_language_codes.size())); | ||
| 40 | |||
| 41 | LOG_DEBUG(Service_SET, "called"); | ||
| 42 | } | ||
| 43 | |||
| 44 | void SET::GetAvailableLanguageCodeCount(Kernel::HLERequestContext& ctx) { | ||
| 45 | IPC::ResponseBuilder rb{ctx, 3}; | ||
| 37 | rb.Push(RESULT_SUCCESS); | 46 | rb.Push(RESULT_SUCCESS); |
| 38 | rb.Push(static_cast<u64>(available_language_codes.size())); | 47 | rb.Push(static_cast<u32>(available_language_codes.size())); |
| 39 | 48 | ||
| 40 | LOG_DEBUG(Service_SET, "called"); | 49 | LOG_DEBUG(Service_SET, "called"); |
| 41 | } | 50 | } |
| @@ -45,10 +54,10 @@ SET::SET() : ServiceFramework("set") { | |||
| 45 | {0, nullptr, "GetLanguageCode"}, | 54 | {0, nullptr, "GetLanguageCode"}, |
| 46 | {1, &SET::GetAvailableLanguageCodes, "GetAvailableLanguageCodes"}, | 55 | {1, &SET::GetAvailableLanguageCodes, "GetAvailableLanguageCodes"}, |
| 47 | {2, nullptr, "MakeLanguageCode"}, | 56 | {2, nullptr, "MakeLanguageCode"}, |
| 48 | {3, nullptr, "GetAvailableLanguageCodeCount"}, | 57 | {3, &SET::GetAvailableLanguageCodeCount, "GetAvailableLanguageCodeCount"}, |
| 49 | {4, nullptr, "GetRegionCode"}, | 58 | {4, nullptr, "GetRegionCode"}, |
| 50 | {5, &SET::GetAvailableLanguageCodes, "GetAvailableLanguageCodes2"}, | 59 | {5, &SET::GetAvailableLanguageCodes, "GetAvailableLanguageCodes2"}, |
| 51 | {6, nullptr, "GetAvailableLanguageCodeCount2"}, | 60 | {6, &SET::GetAvailableLanguageCodeCount, "GetAvailableLanguageCodeCount2"}, |
| 52 | {7, nullptr, "GetKeyCodeMap"}, | 61 | {7, nullptr, "GetKeyCodeMap"}, |
| 53 | {8, nullptr, "GetQuestFlag"}, | 62 | {8, nullptr, "GetQuestFlag"}, |
| 54 | }; | 63 | }; |
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: | |||
| 36 | 36 | ||
| 37 | private: | 37 | private: |
| 38 | void GetAvailableLanguageCodes(Kernel::HLERequestContext& ctx); | 38 | void GetAvailableLanguageCodes(Kernel::HLERequestContext& ctx); |
| 39 | void GetAvailableLanguageCodeCount(Kernel::HLERequestContext& ctx); | ||
| 39 | }; | 40 | }; |
| 40 | 41 | ||
| 41 | } // namespace Service::Set | 42 | } // namespace Service::Set |