On Sunday, 10 July 2016 at 20:31:34 UTC, Lodovico Giaretta wrote:
On Sunday, 10 July 2016 at 19:50:28 UTC, Adam Sansier wrote:
On Sunday, 10 July 2016 at 19:44:01 UTC, Adam D. Ruppe wrote:
On Sunday, 10 July 2016 at 19:19:57 UTC, Adam Sansier wrote:
Is it possible to turn temporary char/wchar buffer in to a string to be used by string functions rather than having to convert?

What string functions in particular? If they are written correctly, it should just work.... mutable char[] can be passed as a char* or const char* with the .ptr property.


I could use C strcmp etc but then I might as well just write the code in C.

meh D rox over C even if you just use C functions

I'm trying to use windows registry functions. This requires passing a char(sometimes a TCHAR) buffer.

But I need to compare the results, case insensitive, to a string(since that is what D uses). It's being a real pain in the butt to deal with the mixture.

I tried using slices, which works for char but not wchar as string is not a immutable(wchar). I don't want to use wide strings because that doesn't seem to be a "thing" in d.

This whole char vs wchar vs dchar is a big confusing, not in what they are but how they all interrelate between D and windows and their doesn't seem to be an easy way to convert between them all unless one wants to litter their code with to!'s.

Well, the main problem I always faced is Windows having quite a bad string handling...

That said, if you want char[] -> string or wchar[] -> wstring you can use assumeUnique, which casts a mutable array to an immutable one. If you have an array of ubyte, ushort or int, and would like to use it as a string, you can use assumeUTF, which casts it respectively to string, wstring or dstring.
But both functions are in fact just casts.

Also keep in mind that in D a string literal will behave as a string, wstring or dstring based on the type of variable to which it is assigned.

This are just some hints, as I don't really understand what is not working for you. Do you mind showing a snippet?

The problem is things like

https://msdn.microsoft.com/en-us/library/windows/desktop/ms724902(v=vs.85).aspx

require data buffers to be used. I can't just plug in a wstring to it, can I?

`First-chance exception: core.exception.UnicodeException illegal UTF-16 value at src\rt\util\utf.d(400)`

This happens when I call toLower on a wstring trying to lower all the characters.


Also, if I clear the buffer before it is used, to!wstring returns an empty string. Even though right before the call to to!wstring the buffer contains the string. If I just cast instead of call to!wstring, it works but the length is 1024, the original size of the buffer.

I'm slowing debugging the code and most things work but it's just a mess trying to sort out all the different things versions of chars and strings to make sure that things works and hopefully are robust.


Reply via email to