[fpc-pascal] Concatenating CP Strings

Martok listbox at martoks-place.de
Sat Sep 15 01:38:33 CEST 2018


Hi all,

concatenating codepage strings is documented to be a bit weird:
<http://wiki.freepascal.org/FPC_Unicode_support#String_concatenations>

Knowing this, how does one achieve the following?

- have a string in any dynamic codepage
- append another string (possibly from different CP), or a literal
- have the result in the same dynamic codepage as before

Literally, "transcode the new part and plop it at the end"?

Using AnsiStrings does not work, as the declared CP is CP_ACP, which is not the
dynamic CP, and loss of data is likely. Using RawByteStrings does not work, as
they get converted to CP_ACP regardless of their current dynamic CP, and loss of
data is likely. Insert() does not work, because it doesn't care about characters
at all and just moves bytes.

Doing the entire thing manually with a temp string does work, but such a simple
task can't be that difficult, can it?


Thank you,

Martok



PS:
Also, somewhat related: how compatible are the different widestring managers
supposed to be? Windows doesn't support CP_UTF16(BE) (which really is UCS2 - aka
the MBCS alias of WideString), but fpwidestring has correct handling for it.




More information about the fpc-pascal mailing list