mirror of
				https://github.com/PabloMK7/citra.git
				synced 2025-10-31 05:40:04 +00:00 
			
		
		
		
	android: Use correct encoding when converting strings
The JNI functions that have "UTF" their name use "modified UTF-8" rather than the standard UTF-8 that Citra uses, at least according to Oracle's documentation, so it is incorrect for us to use them. This change fixes the problem by converting between UTF-8 and UTF-16 manually instead of letting JNI do it for us.
This commit is contained in:
		
							parent
							
								
									87677be921
								
							
						
					
					
						commit
						ce07ef1821
					
				
					 4 changed files with 25 additions and 14 deletions
				
			
		|  | @ -8,6 +8,8 @@ | |||
| #include <cstdlib> | ||||
| #include <locale> | ||||
| #include <sstream> | ||||
| #include <string> | ||||
| #include <string_view> | ||||
| #include "common/common_paths.h" | ||||
| #include "common/logging/log.h" | ||||
| #include "common/string_util.h" | ||||
|  | @ -135,14 +137,14 @@ std::string ReplaceAll(std::string result, const std::string& src, const std::st | |||
|     return result; | ||||
| } | ||||
| 
 | ||||
| std::string UTF16ToUTF8(const std::u16string& input) { | ||||
| std::string UTF16ToUTF8(std::u16string_view input) { | ||||
|     std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert; | ||||
|     return convert.to_bytes(input); | ||||
|     return convert.to_bytes(input.data(), input.data() + input.size()); | ||||
| } | ||||
| 
 | ||||
| std::u16string UTF8ToUTF16(const std::string& input) { | ||||
| std::u16string UTF8ToUTF16(std::string_view input) { | ||||
|     std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert; | ||||
|     return convert.from_bytes(input); | ||||
|     return convert.from_bytes(input.data(), input.data() + input.size()); | ||||
| } | ||||
| 
 | ||||
| #ifdef _WIN32 | ||||
|  |  | |||
|  | @ -7,6 +7,7 @@ | |||
| #include <algorithm> | ||||
| #include <cstddef> | ||||
| #include <string> | ||||
| #include <string_view> | ||||
| #include <vector> | ||||
| #include "common/common_types.h" | ||||
| #include "common/swap.h" | ||||
|  | @ -37,8 +38,8 @@ void BuildCompleteFilename(std::string& _CompleteFilename, const std::string& _P | |||
| [[nodiscard]] std::string ReplaceAll(std::string result, const std::string& src, | ||||
|                                      const std::string& dest); | ||||
| 
 | ||||
| [[nodiscard]] std::string UTF16ToUTF8(const std::u16string& input); | ||||
| [[nodiscard]] std::u16string UTF8ToUTF16(const std::string& input); | ||||
| [[nodiscard]] std::string UTF16ToUTF8(std::u16string_view input); | ||||
| [[nodiscard]] std::u16string UTF8ToUTF16(std::string_view input); | ||||
| 
 | ||||
| #ifdef _WIN32 | ||||
| [[nodiscard]] std::string UTF16ToUTF8(const std::wstring& input); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue