De-Referencing A Pointer
James Dunne
james.jdunne at gmail.com
Wed Mar 22 07:59:09 PST 2006
James Dunne wrote:
> Rory Starkweather wrote:
>
>> ...
>
> As much as I'd love to help you out, I'm also hopelessly lost. Can you
> ZIP up your project and document your test cases and post them on the NG
> or e-mail them to me personally? The e-mail I post with on the
> newsgroups is my valid e-mail.
>
The working code is attached with a sample Excel spreadsheet with
embedded VBA test code.
Since VB uses equivalents of D's wchar* strings, you cannot easily use
D's phobos string handling functions, since most of them expect char[]
arguments, not wchar[].
My conclusion is that we really need wchar[] and dchar[] string-handling
functions in phobos, or at least be assured that all the string-handling
functions which accept char[] arguments assume UTF-8 encoding, not just
ASCII.
I had to look at the std.string.d module's find() method to see if it is
accepting ASCII or UTF-8, and I couldn't figure out which! The code is:
int find(char[] s, dchar c)
{
char* p;
if (c <= 0x7F)
{ // Plain old ASCII
p = cast(char*)memchr(s, c, s.length);
if (p)
return p - cast(char *)s;
else
return -1;
}
// c is a universal character
foreach (int i, dchar c2; s)
{
if (c == c2)
return i;
}
return -1;
}
This doesn't make a lick of sense to me why one can iterate over a
char[] with foreach, expecting dchars to come out of it outside the
range of ASCII... is there something going on under the hood that I'm
not aware of? Is this code trying to imply that the char[] is being
treated as UTF-8 magically?
--
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/MU/S d-pu s:+ a-->? C++++$ UL+++ P--- L+++ !E W-- N++ o? K? w--- O
M--@ V? PS PE Y+ PGP- t+ 5 X+ !R tv-->!tv b- DI++(+) D++ G e++>e
h>--->++ r+++ y+++
------END GEEK CODE BLOCK------
James Dunne
-------------- next part --------------
A non-text attachment was scrubbed...
Name: DInStr - works.zip
Type: application/octet-stream
Size: 9439 bytes
Desc: not available
Url : http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20060322/41744f25/attachment.obj
More information about the Digitalmars-d-learn
mailing list