[fpc-pascal] How to know the string type of a variable?

J├╝rgen Hestermann juergen.hestermann at gmx.de
Tue Dec 31 12:01:41 CET 2013

Am 2013-12-30 20:17, schrieb Mattias Gaertner:
 > On Mon, 30 Dec 2013 19:19:20 +0200
 > Juha Manninen <juha.manninen62 at gmail.com> wrote:
 >> On Mon, Dec 30, 2013 at 2:35 PM, Marcos Douglas <md at delfire.net> wrote:
 >>> Is possible to know what string type of a variable (AnsiString,
 >>> UTF8String, RawByteString, etc)?
 >> When UTF-8 encoded string is stored in AnsiString (as in LCL), this
 >> test should tell you if it actually is UTF-8 string:
 >>   if Length(s) <> UTF8Length(s) then
 >>   begin
 >>     // UTF-8
 >>   end;
 > This is wrong.
 > There is no test for UTF-8 versus 8-bit windows codepage.
 > A good heuristic is this:
 > if FindInvalidUTF8Character(PChar(Pointer(s)),length(s))<0 then
 >   // UTF-8

But as you wrote:
It is a heuristic.
It may fail.

I am beginning to realize why software is so buggy
nowadays if it has to be based on heuristics...

More information about the fpc-pascal mailing list