#1 2020-01-13 18:41:25

Apo
Member
Registered: 2019-05-02
Posts: 5

Recommendation for string conversion issues

Hello,

I am converting some of my (old) code to use DocVariant as a JSON implementation.

But by including SynCommons in uses the compiler generated several explicit conversion warnings from / to string.
Due to SynCommons reintroducing various methods like  Trim, etc. that uses RawUTF8.

function OneFunction (AString : String) : String;
begin
    Result := Trim(AString);  //This generate a warning since SynCommons.Trim expects RawUTF8
end;

I would not want to change everything to RawUTF8.

Some options I think:

- Leave SynCommons as the first uses unit. So that SysUtils, etc. override these functions.

- Use RawByteString as parameters.

- Explicit name of a unit: SysUtils.Trim (...)


What would be the suggestion to better resolve these conflicts? Along with maintaining the best performance possible?

NOTE: This code is being compiled in Delphi 10.3 / FPC. I do not need Unicode compatibility with previous versions of Delphi.

Offline

#2 2020-01-13 21:01:14

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: Recommendation for string conversion issues

Put the right order in the "uses" clause is IMHO the right way to do it.

For instance, set SysUtils after SynCommons if you want trim(string) to be called.

Offline

#3 2020-01-14 14:22:48

Apo
Member
Registered: 2019-05-02
Posts: 5

Re: Recommendation for string conversion issues

Thanks.

I will go in this direction.

Offline

#4 2020-01-14 18:55:16

zed
Member
From: Belarus
Registered: 2015-02-26
Posts: 105

Re: Recommendation for string conversion issues

I wold prefer explicit form: SysUtils.Trim(...)

Offline

#5 2020-01-14 19:06:46

Apo
Member
Registered: 2019-05-02
Posts: 5

Re: Recommendation for string conversion issues

Thanks for the opinion.

And to write new SynCommons-dependent utility units as you usually do?

Uses RawUTF8 in all parameters?

Offline

Board footer

Powered by FluxBB