On 19/9/2011 08:19, Paul Ishenin wrote:
19.09.2011 20:05, Hans-Peter Diettrich wrote:
IMO the use of RawByteString will not help much, except for (possibly) simpler code and less overloaded procedures. Avoiding implicit conversions instead will require *fixed* string types and encodings, for different tasks with different needs. E.g. a TFileName string type will allow to eliminate all conversions, when a string is known to hold file or path names (by design). Likewise an LCLString (widget, component) type could do the same for the LCL widgetset interface. The FPC decisions about string container classes (TStrings...) will tell where to put the break line, between user and widget string types.

My statement about RawByteString need to be read in the context of code where I replaced UTF8String to AnsiString.

Just to point that RawByteString should be used in very specific cases like stated in the link below

http://stackoverflow.com/questions/498315/delphi-2009-rawbytestring-vagaries

Regarding change to UTF8ToUTF16 function RawByteString should not be used.

function UTF8ToUTF16(const S: UTF8String): UTF16String;

Currently does not matter if is UTF8String or AnsiString, but when the new string type starts to be used, there's no problem using UTF8String.

In fact the use of UTF8String will be necessary otherwise explicit conversions with extra hidden temporary variables inside the function will be necessary as is the case with RawByteString.

Also PChar should be changed to PAnsiChar since PChar can point to a word (UTF16 RTL) or a byte (UTF8 RTL)

I explained in a mail in the devel list (where you see UnicodeString read as UTF8String)

I'm talking about:

function FileGetAttr(const FileName: UnicodeString): Longint;
begin
  Result:=Integer(Windows.GetFileAttributesW(PWideChar(FileName)));
end;


Inside the procedure there will be no conversion since is already UTF16, just a typecast to PWideChar which in fact is a function

The conversion will be done before the function call only if necessary (eg UTF8 -> UTF16). The decision to convert or not is done at compiler time.


With RawByteString

function FileGetAttr(const FileName: RawByteString): Longint;
begin
Result:=Integer(Windows.GetFileAttributesW(PWideChar(UnicodeString(FileName))));
end;


Here the decision to convert or not is done at runtime by checking the CodePage of FileName. Also there's one more temp variable due to UnicodeString typecast.

In summary:
With UnicodeString decision to convert at design time
With RawByteString decision to convert at run time + one more temp variable


Luiz

--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to