[review] new string type
Lars T. Kyllingstad
public at kyllingen.NOSPAMnet
Tue Nov 30 15:34:11 PST 2010
On Tue, 30 Nov 2010 13:52:20 -0500, Steven Schveighoffer wrote:
> On Tue, 30 Nov 2010 13:34:50 -0500, Jonathan M Davis
> <jmdavisProg at gmx.com> wrote:
>
> [...]
>
>> 4. Indexing is no longer O(1), which violates the guarantees of the
>> index operator.
>
> Indexing is still O(1).
>
>> 5. Slicing (other than a full slice) is no longer O(1), which violates
>> the
>> guarantees of the slicing operator.
>
> Slicing is still O(1).
>
> [...]
It feels extremely weird that the indices refer to code units and not
code points. If I write
auto str = mystring("hæ?");
writeln(str[1], " ", str[2]);
I expect it to print "æ ?", not "æ æ" like it does now.
On a side note: It seems to me that the only reason to have char, wchar,
and dchar as separate types in the language is that arrays of said types
are UTF-encoded strings. If a type such as the proposed one were to
become the default string type in D, it might as well wrap an array of
ubyte/ushort/uint, since direct user manipulation of the underlying array
will generally only happen in the rare cases when one wants to deal
directly with code units.
-Lars
More information about the Digitalmars-d
mailing list