Fix OSK on Android, wchar_t is not always 16 bits.

Fixes #2073.
This commit is contained in:
Unknown W. Brackets 2013-06-04 22:39:42 -07:00
parent a26b48fc0b
commit fc51cf2e5e
2 changed files with 28 additions and 9 deletions

View File

@ -124,7 +124,7 @@ PSPOskDialog::PSPOskDialog() : PSPDialog() {
PSPOskDialog::~PSPOskDialog() {
}
void PSPOskDialog::ConvertUCS2ToUTF8(std::string& _string, const PSPPointer<wchar_t> em_address)
void PSPOskDialog::ConvertUCS2ToUTF8(std::string& _string, const PSPPointer<u16> em_address)
{
if (!em_address.Valid())
{
@ -132,10 +132,29 @@ void PSPOskDialog::ConvertUCS2ToUTF8(std::string& _string, const PSPPointer<wcha
return;
}
ConvertUCS2ToUTF8(_string, &em_address[0]);
char stringBuffer[2048];
char *string = stringBuffer;
auto input = em_address;
int c;
while ((c = *input++) != 0)
{
if (c < 0x80)
*string++ = c;
else if (c < 0x800) {
*string++ = 0xC0 | (c >> 6);
*string++ = 0x80 | (c & 0x3F);
} else {
*string++ = 0xE0 | (c >> 12);
*string++ = 0x80 | ((c >> 6) & 0x3F);
*string++ = 0x80 | (c & 0x3F);
}
}
*string++ = '\0';
_string = stringBuffer;
}
void PSPOskDialog::ConvertUCS2ToUTF8(std::string& _string, wchar_t* input)
void PSPOskDialog::ConvertUCS2ToUTF8(std::string& _string, const wchar_t *input)
{
char stringBuffer[2048];
char *string = stringBuffer;
@ -809,7 +828,7 @@ int PSPOskDialog::Update()
status = SCE_UTILITY_STATUS_SHUTDOWN;
}
wchar_t *outText = oskParams->fields[0].outtext;
u16 *outText = oskParams->fields[0].outtext;
for (u32 i = 0, end = oskParams->fields[0].outtextlength; i < end; ++i)
{
u16 value = 0;

View File

@ -111,13 +111,13 @@ struct SceUtilityOskData
/** Unknown. Pass 0. */
int unk_24;
/** Description text */
PSPPointer<wchar_t> desc;
PSPPointer<u16> desc;
/** Initial text */
PSPPointer<wchar_t> intext;
PSPPointer<u16> intext;
// Length, in unsigned shorts, including the terminator.
u32 outtextlength;
/** Pointer to the output text */
PSPPointer<wchar_t> outtext;
PSPPointer<u16> outtext;
/** Result. One of ::SceUtilityOskResult */
int result;
// Number of characters to allow, not including terminator (if less than outtextlength - 1.)
@ -163,8 +163,8 @@ public:
virtual int Shutdown(bool force = false);
virtual void DoState(PointerWrap &p);
private:
void ConvertUCS2ToUTF8(std::string& _string, const PSPPointer<wchar_t> em_address);
void ConvertUCS2ToUTF8(std::string& _string, wchar_t* input);
void ConvertUCS2ToUTF8(std::string& _string, const PSPPointer<u16> em_address);
void ConvertUCS2ToUTF8(std::string& _string, const wchar_t *input);
void RenderKeyboard();
std::wstring CombinationString(bool isInput); // for Japanese, Korean