Making all strings UTF ranges has some risk of WTF

Simen kjaeraas simen.kjaras at gmail.com
Thu Feb 4 03:39:06 PST 2010


grauzone <none at example.net> wrote:
>
> Change the type of string literals from char[] (or whatever the string  
> type is in D2) to a wrapper struct defined in object.d:
>
> struct string {
>      char[] raw;
> }
>
> Now string.length is invalid, and you don't have to do weird stuff as in  
> (b) or (c).
>
>  From here on, you could do 2 things:
> 1. add accessor methods to string like string classes in other languages  
> do
> 2. leave the wrapper struct as it is (just add the required range foo),  
> and require the user to use either a) the range API (with utf-8 decoding  
> etc.) or b) access the raw "byte" string with string.raw.

This seems to me a job for @disable:

struct string {
     immutable( char )[] payload;
     alias payload this;
     @disable int length( ) { return 0; }
}

-- 
Simen



More information about the Digitalmars-d mailing list