Hello FPC developers!
Currently the FPC RTL incorrectly handles binary streams where property
of type WideString stored as UTF8 string.
In sources (reader.inc) there is comment:
if NextValue in [vaWString,vaUString,vaUTF8String] then
//vaUTF8String needs conversion? 2008-09-06 mse
Proposed the patch to read WideString properties in right way.
Especially this is important for those (like me) who use object
streaming as data file format.
Attached the patch.
Best regards,
and happy holidays
Anton Kavalenka
Index: reader.inc
===================================================================
--- reader.inc (revision 12454)
+++ reader.inc (working copy)
@@ -307,19 +307,21 @@
i: Integer;
begin
case StringType of
- vaString:
+ vaLString,vaUTF8String:
+ i:=ReadDWord;
+ else
+ //vaString:
begin
Read(b, 1);
i := b;
end;
- vaLString:
- i:=ReadDWord;
end;
SetLength(Result, i);
if i > 0 then
Read(Pointer(@Result[1])^, i);
end;
+
function TBinaryObjectReader.ReadWideString: WideString;
var
len: DWord;
@@ -1415,12 +1417,16 @@
var
s: String;
i: Integer;
+ vt:TValueType;
begin
if NextValue in [vaWString,vaUString,vaUTF8String] then
- //vaUTF8String needs conversion? 2008-09-06 mse
+ //vaUTF8String needs conversion? 2008-09-06 mse, YES!! AntonK
begin
- ReadValue;
- Result := FDriver.ReadWideString
+ vt:=ReadValue;
+ if vt=vaUTF8String then
+ Result :=
utf8decode(fDriver.ReadString(vaLString))
+ else
+ Result := FDriver.ReadWideString
end
else
begin
_______________________________________________
fpc-devel maillist - fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel