View previous topic :: View next topic |
Author |
Message |
sdv
Joined: 20 May 2006 Posts: 2
|
Posted: Sun Dec 04, 2011 12:48 pm Post subject: [bug] Wide character for Chinese |
|
|
string2OLESTR(mFilename)
"mFilename" Does not support Chinese |
|
Back to top |
|
|
sagitario
Joined: 03 Mar 2007 Posts: 292
|
Posted: Mon Dec 05, 2011 12:10 pm Post subject: |
|
|
I guess you mean that you cannot add a file with a chinese name to a project. As strings are UTF in D and OLESTR is a wide character string, I would expect it should be working. Could you give an example? |
|
Back to top |
|
|
sdv
Joined: 20 May 2006 Posts: 2
|
Posted: Thu Dec 08, 2011 2:17 am Post subject: |
|
|
Code: |
string str1;
// chinese for Ansi
//str1 = "\xd5\xe2\xca\xc7\xd6\xd0\xce\xc4";
// chinese for utf-8
str1 = "\xe8\xbf\x99\xe6\x98\xaf\xe4\xb8\xad\xe6\x96\x87";
wchar* string2OLESTR(string s)
{
wstring ws = toUTF16(s);
//UTF-8 error ws.length = 4
// Ansi Program exit.
int sz = (ws.length + 1) * 2;
wchar* p = cast(wchar*) CoTaskMemAlloc(sz);
//wchar p[];
p[0 .. s.length] = ws[0 .. $];
p[s.length] = 0;
return p;
}
|
"ws" the return value it not looking forward |
|
Back to top |
|
|
sagitario
Joined: 03 Mar 2007 Posts: 292
|
Posted: Thu Dec 08, 2011 3:21 pm Post subject: |
|
|
Thanks for pointing it out. The fix will be in the next release:
Code: |
wchar* string2OLESTR(string s)
{
wstring ws = toUTF16(s);
int sz = (ws.length + 1) * 2;
wchar* p = cast(wchar*) CoTaskMemAlloc(sz);
p[0 .. ws.length] = ws[0 .. $];
p[ws.length] = 0;
return p;
}
|
Your string after the comment "chinese for Ansi" is not a valid utf8 string. Did you mean it as a wstring? |
|
Back to top |
|
|
|