[fpc-devel] ThousandSeparator
Hans-Peter Diettrich
DrDiettrich1 at aol.com
Tue Nov 25 22:25:35 CET 2014
Mattias Gaertner schrieb:
> Does concatenating a string and a WideChar create a UnicodeString? Can
> this become a problem?
Concatenation requires 2 strings, so everything depends on the concrete
code. Regardless of eventual compiler magics, something like this will
happen:
var c: WideChar; s, cs: string;
cs := c; //dunno if accepted by the compiler
s := s + cs;
The WideChar can be converted into an Unicode (UTF-8 or UTF-16) string.
Afterwards this string may need another conversion, when the other
string has a different encoding. In the worst case *both* strings are
converted to the default Unicode representation (Delphi: UTF-16,
Lazarus: UTF-8?), before they are concatenated. Another conversion may
occur when the resulting string is assigned to a variable.
All this may become simpler when CP_ACP is used (at least in Delpi), and
the separator is given in that encoding, as a single byte/AnsiChar in
case of an SBCS CP_ACP. When Lazarus instead uses UTF-8 (MBCS) for
CP_ACP, the character occupies more than one byte, so that this
simplification is impossible. This suggests to store the delimiter as an
string, instead of a WideChar, whereupon a concatenation of the strings
may not require any further conversion.
Finally, when the expression (s+cs) is of type RawByteString (depending
on the involved function declarations), the result will be stored in the
target variable *without* another conversion. Then the static and
dynamic encoding of s may be different afterwards.
DoDi
More information about the fpc-devel
mailing list