[fpc-pascal] Concatenating CP Strings
nc-gaertnma at netcologne.de
Sat Sep 15 07:34:37 CEST 2018
On Sat, 15 Sep 2018 01:38:33 +0200
Martok <listbox at martoks-place.de> wrote:
> Hi all,
> concatenating codepage strings is documented to be a bit weird:
> 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.
There is a neat RTL function SetCodePage to set the CP of a string.
For your string having the wrong CP use this before concatenating:
To have the result in a specific codepage use
> 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),
Only on ancient Windows it was UCS2. Even on old Win7 it was UTF16. I
don't remember when the transition happened. Sadly, there are still
many Windows applications only supporting UCS2.
> but fpwidestring has correct handling for it.
More information about the fpc-pascal