Record TCastleStringIterator

Unit

Declaration

type TCastleStringIterator = record

Description

Iterate over String that contains Unicode characters suitable for both FPC (with default String = AnsiString) and Delphi (with default String = UnicodeString).

This should be used for all iteration over strings in Castle Game Engine. It abstracts away various details about UTF-8 processing (in case of FPC) and UTF-16 processing (in case of Delphi). See https://castle-engine.io/coding_conventions#strings_unicode .

The typical usage looks like this:

var
  Iter: TCastleStringIterator;
begin
  Iter.Start('my_string');
  while Iter.GetNext do
  begin
    // do something with Iter.Current now
    WritelnLog('Got Unicode character: %d, %s', [
      Iter.Current,
      UnicodeCharToString(Iter.Current)
    ]);
  end;
end;

It is allowed to use Start again, with the same iterator (regardless if it finished or not), to start processing a new (or the same) String.

Overview

Methods

Public procedure Start(const S: String);
Public function GetNext: Boolean;

Properties

Public property Current: TUnicodeChar read FCurrent;

Description

Methods

Public procedure Start(const S: String);

Start processing the given String. Must be called before accessing Current or GetNext.

Public function GetNext: Boolean;

Call this in a loop. Must be called (and return True) before accessing Current.

Properties

Public property Current: TUnicodeChar read FCurrent;

After GetNext was called, and returned True, read this to get the current Unicode character. Do not use it after GetNext returned False.


Generated by PasDoc 0.16.0-snapshot.