Re: toUTFz and WinAPI GetTextExtentPoint32W

2011-09-21 Thread Dmitry Olshansky
On 21.09.2011 4:04, Timon Gehr wrote: On 09/21/2011 01:57 AM, Christophe wrote: Jonathan M Davis , dans le message (digitalmars.D.learn:29637), a écrit : On Tuesday, September 20, 2011 14:43 Andrej Mitrovic wrote: On 9/20/11, Jonathan M Davisjmdavisp...@gmx.com wrote: Or

Re: toUTFz and WinAPI GetTextExtentPoint32W

2011-09-21 Thread Timon Gehr
On 09/21/2011 02:15 AM, Christophe wrote: Timon Gehr , dans le message (digitalmars.D.learn:29641), a écrit : Last point: WalkLength is not optimized for strings. std.utf.count should be. This short implementation of count was 3 to 8 times faster than walkLength is a simple benchmark: size_t

Re: toUTFz and WinAPI GetTextExtentPoint32W

2011-09-21 Thread Timon Gehr
On 09/21/2011 12:37 PM, Dmitry Olshansky wrote: On 21.09.2011 4:04, Timon Gehr wrote: On 09/21/2011 01:57 AM, Christophe wrote: Jonathan M Davis , dans le message (digitalmars.D.learn:29637), a écrit : On Tuesday, September 20, 2011 14:43 Andrej Mitrovic wrote: On 9/20/11, Jonathan M

Re: toUTFz and WinAPI GetTextExtentPoint32W

2011-09-21 Thread Christophe
Actually, I don't buy it. I guess the reason it's faster is that it doesn't check if the codepoint is valid. Why should it ? The documentation of std.utf.count says the string must be validly encoded, not that it will enforce that it is. Checking a string is valid everytime you use it would

Re: toUTFz and WinAPI GetTextExtentPoint32W

2011-09-21 Thread zeljkog
On 21.09.2011 01:57, Christophe wrote: size_t myCount(string text) { size_t n = text.length; for (uint i=0; itext.length; ++i) { auto s = text[i]6; n -= (s1) - ((s+1)2); } return n; } Here is a more readable and a bit faster version on dmd windows: size_t

Re: toUTFz and WinAPI GetTextExtentPoint32W

2011-09-21 Thread Dmitry Olshansky
On 21.09.2011 18:47, Christophe wrote: Actually, I don't buy it. I guess the reason it's faster is that it doesn't check if the codepoint is valid. Why should it ? The documentation of std.utf.count says the string must be validly encoded, not that it will enforce that it is. Checking a string

Re: toUTFz and WinAPI GetTextExtentPoint32W

2011-09-21 Thread zeljkog
On 21.09.2011 19:12, Christophe Travert wrote: Nice. It is better with gdc linux 64bits too. I wanted to avoid conditional expressions like ?: but it's actually slightly faster that way. It is not compiled in as conditional jump.

toUTFz and WinAPI GetTextExtentPoint32W

2011-09-20 Thread Andre
Hi, I want something like: bool test(HDC dc, string str, int len, SIZE* s) { wchar[] wstr = toUTFz!(wchar*)str; GetTextExtentPoint32W(dc wstr.ptr, wstr.length, s); ... I get the wchar[] stuff not working. I am struggling with pointer to array. Could you give some advice? Kind regards Andre

Re: toUTFz and WinAPI GetTextExtentPoint32W

2011-09-20 Thread Trass3r
bool test(HDC dc, string str, int len, SIZE* s) { wchar[] wstr = toUTFz!(wchar*)str; GetTextExtentPoint32W(dc wstr.ptr, wstr.length, s); toUTFz returns a wchar*, not a wchar[].

Re: toUTFz and WinAPI GetTextExtentPoint32W

2011-09-20 Thread Andre
Am Tue, 20 Sep 2011 19:27:03 +0200 schrieb Trass3r: bool test(HDC dc, string str, int len, SIZE* s) { wchar[] wstr = toUTFz!(wchar*)str; GetTextExtentPoint32W(dc wstr.ptr, wstr.length, s); toUTFz returns a wchar*, not a wchar[]. I am not familiar with pointers. I know I have to call

Re: toUTFz and WinAPI GetTextExtentPoint32W

2011-09-20 Thread Timon Gehr
On 09/20/2011 08:07 PM, Andre wrote: Am Tue, 20 Sep 2011 19:27:03 +0200 schrieb Trass3r: bool test(HDC dc, string str, int len, SIZE* s) { wchar[] wstr = toUTFz!(wchar*)str; GetTextExtentPoint32W(dc wstr.ptr, wstr.length, s); toUTFz returns a wchar*, not a wchar[]. I am not familiar with

Re: toUTFz and WinAPI GetTextExtentPoint32W

2011-09-20 Thread Trass3r
Are you sure that the call requires the string to be null terminated? I do not know that winapi function, but this might work: bool test(HDC dc, string str, SIZE* s) { auto wstr = to!(wchar[])str; GetTextExtentPoint32W(dc, wstr.ptr, wstr.length, s); ... It doesn't need to be null-terminated

Re: toUTFz and WinAPI GetTextExtentPoint32W

2011-09-20 Thread Timon Gehr
On 09/20/2011 08:34 PM, Trass3r wrote: Are you sure that the call requires the string to be null terminated? I do not know that winapi function, but this might work: bool test(HDC dc, string str, SIZE* s) { auto wstr = to!(wchar[])str; GetTextExtentPoint32W(dc, wstr.ptr, wstr.length, s); ...

Re: toUTFz and WinAPI GetTextExtentPoint32W

2011-09-20 Thread Timon Gehr
On 09/20/2011 08:24 PM, Timon Gehr wrote: On 09/20/2011 08:07 PM, Andre wrote: Am Tue, 20 Sep 2011 19:27:03 +0200 schrieb Trass3r: bool test(HDC dc, string str, int len, SIZE* s) { wchar[] wstr = toUTFz!(wchar*)str; GetTextExtentPoint32W(dc wstr.ptr, wstr.length, s); toUTFz returns a

Re: toUTFz and WinAPI GetTextExtentPoint32W

2011-09-20 Thread Andre
Am Tue, 20 Sep 2011 20:44:40 +0200 schrieb Timon Gehr: On 09/20/2011 08:24 PM, Timon Gehr wrote: On 09/20/2011 08:07 PM, Andre wrote: Am Tue, 20 Sep 2011 19:27:03 +0200 schrieb Trass3r: bool test(HDC dc, string str, int len, SIZE* s) { wchar[] wstr = toUTFz!(wchar*)str;

Re: toUTFz and WinAPI GetTextExtentPoint32W

2011-09-20 Thread Andrej Mitrovic
Don't use length, use std.utf.count, ala: import std.utf; alias toUTFz!(const(wchar)*, string) toUTF16z; GetTextExtentPoint32W(str.toUTF16z, std.utf.count(str), s); I like to keep that alias for my code since I was already using it beforehand. I'm pretty sure (ok maybe 80% sure) that

Re: toUTFz and WinAPI GetTextExtentPoint32W

2011-09-20 Thread Andrej Mitrovic
On 9/20/11, Jonathan M Davis jmdavisp...@gmx.com wrote: Or std.range.walkLength. I don't know why we really have std.utf.count. I just calls walkLength anyway. I suspect that it's a function that predates walkLength and was made to use walkLength after walkLength was introduced. But it's

Re: toUTFz and WinAPI GetTextExtentPoint32W

2011-09-20 Thread Andrej Mitrovic
One other thing, count can only take an array which seems too restrictive since walkLength can take any range at all. So maybe count should be just an alias to walkLength or it should possibly be removed (I'm against fully removing it because I already use it in code and I think the name does make

Re: toUTFz and WinAPI GetTextExtentPoint32W

2011-09-20 Thread Jonathan M Davis
On Tuesday, September 20, 2011 14:43 Andrej Mitrovic wrote: On 9/20/11, Jonathan M Davis jmdavisp...@gmx.com wrote: Or std.range.walkLength. I don't know why we really have std.utf.count. I just calls walkLength anyway. I suspect that it's a function that predates walkLength and was made

Re: toUTFz and WinAPI GetTextExtentPoint32W

2011-09-20 Thread Andrej Mitrovic
On 9/20/11, Jonathan M Davis jmdavisp...@gmx.com wrote: We specifically avoid having aliases in Phobos simply for having alternate function names. Aliases need to actually be useful, or they shouldn't be there. And function names have to be useful to library users. walkLength is an awful name

Re: toUTFz and WinAPI GetTextExtentPoint32W

2011-09-20 Thread Christophe
Jonathan M Davis , dans le message (digitalmars.D.learn:29637), a écrit : On Tuesday, September 20, 2011 14:43 Andrej Mitrovic wrote: On 9/20/11, Jonathan M Davis jmdavisp...@gmx.com wrote: Or std.range.walkLength. I don't know why we really have std.utf.count. I just calls walkLength

Re: toUTFz and WinAPI GetTextExtentPoint32W

2011-09-20 Thread Christophe
Timon Gehr , dans le message (digitalmars.D.learn:29641), a écrit : Last point: WalkLength is not optimized for strings. std.utf.count should be. This short implementation of count was 3 to 8 times faster than walkLength is a simple benchmark: size_t myCount(string text) { size_t n =