[fpc-pascal] Iterator for Unicode encoded strings

Michael Van Canneyt michael at freepascal.org
Wed Apr 27 16:59:45 CEST 2016



On Wed, 27 Apr 2016, Graeme Geldenhuys wrote:

> Hi,
>
> This question really applies for all Unicode encodings (UTF-8, UTF-16
> and UTF-32). In the modern world you simply can't use indexed access
> into Object Pascal strings to retrieve a "character" (loosely what you
> see on the screen - ignoring combining diacritics). In my own projects I
> have custom written Iterators for various data types like StringList,
> ObjectLists etc, and that includes strings.
>
> I know FPC RTL supports the Iterator concept (not as advanced as what I
> have implemented), but still useful. As far as I know there are some
> standard iterator classes already implemented. Does FPC include such
> iterators for the various string types?

Simply said: No. The character iterator

var
  C : Char;
  S : String; // or unicode string

begin
   for c in S do

end.

Will iterate bytes or words, not characters.

Michael.



More information about the fpc-pascal mailing list