Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2012-12

Casting UTF8String, WideString and UnicodeString into AnsiString and vice versa

4 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Jonas Maebe
to ik
ik wrote 7 lines
I made casting of UTF8String, WideString and UnicodeString to AnsiString: https://github.com/ik5/fp-msgpack/blob/master/src/msgpack.pas#L452 As an example. My tests works. but are there things/contents that can break this casting, or change the content itself in some way ?

It creates a new temporary string with the default code page for that string type (e.g., DefaultSystemCodePage for ansistring), and converts the original string's content to this new encoding.

Jonas

Reply by email

ik
to Jonas Maebe
Jonas Maebe wrote 12 lines
On 03 Dec 2012, at 18:12, ik wrote: > I made casting of UTF8String, WideString and UnicodeString to AnsiString: > https://github.com/ik5/fp-msgpack/blob/master/src/msgpack.pas#L452 > > As an example. > > My tests works. but are there things/contents that can break this > casting, or change the content itself in some way ? It creates a new temporary string with the default code page for that string type (e.g., DefaultSystemCodePage for ansistring), and converts the original string's content to this new encoding.

Isn't that only 2.7.1 feature ?!

Show quoted text 5 lines
Jonas_______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Jonas Maebe
to ik
ik wrote 15 lines
On Mon, Dec 3, 2012 at 7:31 PM, Jonas Maebe wrote: > > On 03 Dec 2012, at 18:12, ik wrote: > >> I made casting of UTF8String, WideString and UnicodeString to AnsiString: >> https://github.com/ik5/fp-msgpack/blob/master/src/msgpack.pas#L452 >> >> As an example. >> >> My tests works. but are there things/contents that can break this >> casting, or change the content itself in some way ? > > It creates a new temporary string with the default code page for that string type (e.g., DefaultSystemCodePage for ansistring), and converts the original string's content to this new encoding. Isn't that only 2.7.1 feature ?!

Well, you didn't specify a particular version, and you asked about what could break such casting. And other than the string-specific codepages for ansistring/utf8string, the rest still holds (e.g. casting a unicodestring to ansistring can easily result in data loss even in 2.6.x, because there will be a conversion to the default system code page).

Jonas

Reply by email