Why the hell doesn't foreach decode strings

Simen Kjaeraas simen.kjaras at gmail.com
Mon Oct 24 08:58:15 PDT 2011


On Mon, 24 Oct 2011 16:02:24 +0200, Steven Schveighoffer  
<schveiguy at yahoo.com> wrote:

> On Sat, 22 Oct 2011 05:20:41 -0400, Walter Bright  
> <newshound2 at digitalmars.com> wrote:
>
>> On 10/22/2011 2:21 AM, Peter Alexander wrote:
>>> Which operations do you believe would be less efficient?
>>
>> All of the ones that don't require decoding, such as searching, would  
>> be less efficient if decoding was done.
>
> Searching that does not do decoding is fundamentally incorrect.  That  
> is, if you want to find a substring in a string, you cannot just compare  
> chars.

Assuming both string are valid UTF-8, you can. Continuation bytes can never
be confused with the first byte of a code point, and the first byte always
identifies how many continuation bytes there should be.

-- 
   Simen


More information about the Digitalmars-d mailing list