Copy a number of Unicode characters from given string, from given position.
This is like standard Pascal Copy , but safe for Unicode, and working with both FPC and Delphi default String (see https://castle-engine.io/coding_conventions#strings_unicode ).
StartIndex is 1-based, i.e. the first Unicode character in String has index 1, last Unicode character has index StringLength(S).
In case CountToCopy, it is guaranteed to only copy the maximum possible characters, without causing any memory overruns.
Note that it doesn't try to deal with strings that may end abruptly in the middle of a Unicode character (that may span multiple Pascal Char (AnsiChar or WideChar) values, possible both in case of UTF-8 in AnsiString and UTF-16 in UnicodeString). The results of such abrupt ending are undefined: this routine may copy the partial (unfinished) Unicode character, or it may reject the unfinished partial character altogether.
This works taking into account that:
with FPC, we expect String = AnsiString and holding UTF-8 data,
with Delphi we expect String = UnicodeString and holding UTF-16 data.
See https://castle-engine.io/coding_conventions#strings_unicode .
|