[review] new string type

Steven Schveighoffer schveiguy at yahoo.com
Wed Dec 1 13:35:51 PST 2010


On Tue, 30 Nov 2010 18:31:05 -0500, Ellery Newcomer  
<ellery-newcomer at utulsa.edu> wrote:

> On 11/30/2010 12:52 PM, Steven Schveighoffer wrote:
>> On Tue, 30 Nov 2010 13:34:50 -0500, Jonathan M Davis
>>
>>> 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).
>>
>
> There definitely is value in being able to index and slice into utf  
> strings without resulting in invalid utf, but I think the fact that it  
> indexes on code unit and returns code point is sufficiently strange that  
> it qualifies as abuse of operator overloading.

Maybe :)  The other alternative is to throw an exception if you try to  
access a code unit that is not the beginning of a code point.

That might actually be less weird, I'll try doing that on the next  
iteration.

I find that iteration over string characters using index is a very rare  
thing anyways, you either use foreach, which should give you dchars, or  
you use something like find, which should never give you an invalid index.

-Steve


More information about the Digitalmars-d mailing list