1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
#include "stdafx.h"
#include "PSVitaStrings.h"
#include <ces.h>
uint8_t *mallocAndCreateUTF8ArrayFromString(int iID)
{
LPCWSTR wchString=app.GetString(iID);
size_t src_len,dst_len;
int iLen=wcslen(wchString);
src_len=sizeof(WCHAR)*(iLen);
SceCesUcsContext context;
int result = sceCesUcsContextInit( &context );
if( result != S_OK )
{
app.DebugPrintf("sceCesUcsContextInit failed\n");
return nullptr;
}
uint32_t utf16Len;
uint32_t utf8Len;
result = sceCesUtf16StrGetUtf8Len( &context,
(uint16_t *)wchString,
iLen,
&utf16Len,
&utf8Len
);
utf8Len += 1;
uint8_t *strUtf8=(uint8_t *)malloc(utf8Len);
memset(strUtf8,0,utf8Len);
result = sceCesUtf16StrToUtf8Str(
&context,
(uint16_t *)wchString,
iLen,
&utf16Len,
strUtf8,
utf8Len,
&utf8Len
);
if( result != SCE_OK )
{
app.DebugPrintf("sceCesUtf16StrToUtf8Str: conversion error : 0x%x\n", result);
return nullptr;
}
return strUtf8;
}
|