www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Deprecation of toUTF16

reply Andre Pany <andre s-e-a-p.de> writes:
Hi,

I have some problems to find out what to use instead of the 
deprecated toUTF16 function.

I am calling a shared library written in Delphi.
While this coding is working fine (with german ü)

import std.utf: toUTF16;
wstring ws = toUTF16(s);
BSTR bStr = SysAllocStringLen(ws.ptr, cast(UINT) ws.length);

This coding fails to display the german ü correctly:

import std.utf: encode;
wchar[] ws;
s.each!(c => encode(ws, c));
BSTR bStr = SysAllocStringLen(ws.ptr, cast(UINT) ws.length);


Variable s is of type string. On delphi side WideString is used 
as type for the string.
Where is the error?

Kind regards
André
Aug 31
next sibling parent reply Kagamin <spam here.lot> writes:
import std.conv;
auto ws=s.to!wstring;
Aug 31
parent Andre Pany <andre s-e-a-p.de> writes:
On Thursday, 31 August 2017 at 17:22:51 UTC, Kagamin wrote:
 import std.conv;
 auto ws=s.to!wstring;
Thank you! Kind regards André
Aug 31
prev sibling parent Steven Schveighoffer <schveiguy yahoo.com> writes:
On 8/31/17 12:12 PM, Andre Pany wrote:
 Hi,
 
 I have some problems to find out what to use instead of the deprecated 
 toUTF16 function.
 
 I am calling a shared library written in Delphi.
 While this coding is working fine (with german ü)
 
 import std.utf: toUTF16;
 wstring ws = toUTF16(s);
 BSTR bStr = SysAllocStringLen(ws.ptr, cast(UINT) ws.length);
 
 This coding fails to display the german ü correctly:
 
 import std.utf: encode;
 wchar[] ws;
 s.each!(c => encode(ws, c));
 BSTR bStr = SysAllocStringLen(ws.ptr, cast(UINT) ws.length);
 
 
 Variable s is of type string. On delphi side WideString is used as type 
 for the string.
 Where is the error?
 
The error is actually in the compiler -- the toUTF16 function you are calling is NOT being deprecated. But the compiler mistakenly is marking it as deprecated. See here: https://issues.dlang.org/show_bug.cgi?id=17193 -Steve
Aug 31