Sign in Join

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

Mailing lists / fpc-pascal / 2012-08

rawbytestring

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

Marco van de Voort

In past unicode discussions, rawbytestring was offered as a solution to mixing utf8 and unicodestring (utf16).

I got the impression that rawbytestring was a kind of open array string, to which strings could be passed without implicit conversion. (saving a lot in overloading)

A week or two back I saw something in a delphi component that made me doubt that hypothesis and today I tested with a small program.

It turns out that rawbytestring is only such for 1-byte types, and anything else gets converted to the default ascii (1-byte) encoding, which is Windows-1252, resulting in lossy conversions.

FPC 2.7.1 is fully compatible. This makes simply changing general RTL routines that take strings to rawbytestring difficult? Or am I missing something?

output:

short 1252 1
ansi 1252 1
utf8 65001 1
unic 1252 1
wide 1252 1

program:

program sometest;
{$ifdef fpc}
{$mode delphi}
{$else}
{$APPTYPE CONSOLE}
{$endif}
uses
  SysUtils;
procedure testraw(s:string;x:rawbytestring);
begin
  writeln(s,' ',stringcodepage(x),' ' ,StringElementSize(x));
end;
var sshort : shortstring;
    sutf8 : UTF8String;
    sunicode : unicodestring;
    swide : widestring;
    sansi : ansistring;
begin
  sshort:='Fianc�';
  sansi:='Fianc�';
  sutf8:='Fianc�';
  sunicode:='Fianc�';
  swide:='Fianc�';
  testraw('short',sshort);
  testraw('ansi',sansi);
  testraw('utf8',sutf8);
  testraw('unic',sunicode);
  testraw('wide',swide);
  readln;
end.

Reply by email

Jonas Maebe
to Marco van de Voort
Marco van de Voort wrote
It turns out that rawbytestring is only such for 1-byte types, and anything else gets converted to the default ascii (1-byte) encoding, which is Windows-1252, resulting in lossy conversions.

Indeed, that was also mentioned afterwards in the previous discussions on this topic (see e.g. http://lists.freepascal.org/lists/fpc-devel/2011-September/026377.html )

FPC 2.7.1 is fully compatible. This makes simply changing general RTL routines that take strings to rawbytestring difficult? Or am I missing something?

No, you indeed need separate overloads with rawbytestring and unicodestring (and possibly widestring, although I don't think that's necessary; even Delphi doesn't do that, afaik).

Jonas

Reply by email