[fpc-devel] Re: enumerators

Alexander Klenin klenin at gmail.com
Mon Nov 15 02:05:11 CET 2010


On Mon, Nov 15, 2010 at 08:25, Marco van de Voort <marcov at stack.nl> wrote:
> In our previous episode, Hans-Peter Diettrich said:
>> At least the example code has to be made work, i.e. the nonsense statement
>>    DoSomething(ch(i));
>> has to be changed into something like
>>    DoSomething(GetUTF8char(s,i));
>> before we can can talk honestly about the order of the loop.
>
> The other of the algorithm is then still O(n^2), since UTF8Char will already
> be O(n)?

Yes, that was the idea.
Additionally I hypothesized that if/when FPC supports such type as UTF8String,
it will surely have overloaded Length and [] to work properly on it ;-)

I have written this example during for..in loop discussion as an illustration,
and did not update it since then.
Indeed, to work in the current FPC for..to loop would be something like

for i := 1 to GetUTF8Length(s) do
  Writeln(GetUTF8Char(s, i));

except I am not sure about the "canonical" function names
to work with utf-8 strings.
If the above version is correct, I will update the wiki.

-- 
Alexander S. Klenin



More information about the fpc-devel mailing list