mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-26 14:17:23 +01:00
Converter: improve WideString conversion. Not all nums are 3 characters long. Issue #23116
git-svn-id: trunk@41975 -
This commit is contained in:
parent
5ef97c0b5c
commit
2a00da9fec
@ -192,16 +192,20 @@ end;
|
|||||||
function TDFMConverter.FixWideString(aInStream, aOutStream: TMemoryStream): TModalResult;
|
function TDFMConverter.FixWideString(aInStream, aOutStream: TMemoryStream): TModalResult;
|
||||||
// Convert Windows WideString syntax (#xxx) to UTF8
|
// Convert Windows WideString syntax (#xxx) to UTF8
|
||||||
|
|
||||||
function UnicodeNumber(const InS: string; Ind: integer): string;
|
function UnicodeNumber(const InS: string; var Ind: integer): string;
|
||||||
// Convert the number to UTF8
|
// Convert the number to UTF8
|
||||||
var
|
var
|
||||||
c: Integer;
|
Start, c: Integer;
|
||||||
begin
|
begin
|
||||||
c := StrToInt(copy(InS, Ind, 3));
|
Inc(Ind); // Skip '#'
|
||||||
if c > 255 then
|
Start:=Ind;
|
||||||
Result := UnicodeToUTF8(c)
|
while InS[Ind] in ['0'..'9'] do
|
||||||
|
Inc(Ind); // Collect numbers
|
||||||
|
c:=StrToInt(Copy(InS, Start, Ind-Start));
|
||||||
|
if c>255 then
|
||||||
|
Result:=UnicodeToUTF8(c)
|
||||||
else
|
else
|
||||||
Result := SysToUTF8(chr(c)); // or use a function in lconvencoding.
|
Result:=SysToUTF8(chr(c));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function CollectString(const InS: string; var Ind: integer): string;
|
function CollectString(const InS: string; var Ind: integer): string;
|
||||||
@ -215,17 +219,18 @@ function TDFMConverter.FixWideString(aInStream, aOutStream: TMemoryStream): TMod
|
|||||||
repeat
|
repeat
|
||||||
ch:=InS[Ind];
|
ch:=InS[Ind];
|
||||||
if ch in [#13,#10] then Break;
|
if ch in [#13,#10] then Break;
|
||||||
if ch = '''' then
|
if ch = '''' then begin
|
||||||
InQuote:=not InQuote
|
InQuote:=not InQuote; // Toggle quote
|
||||||
else if InQuote then
|
Inc(Ind);
|
||||||
Result:=Result+ch
|
|
||||||
else if ch = '#' then begin
|
|
||||||
Result:=Result+UnicodeNumber(InS, Ind+1);
|
|
||||||
Inc(Ind, 3);
|
|
||||||
end
|
end
|
||||||
|
else if InQuote then begin
|
||||||
|
Result:=Result+ch; // Inside quotes copy characters as is.
|
||||||
|
Inc(Ind);
|
||||||
|
end
|
||||||
|
else if ch = '#' then
|
||||||
|
Result:=Result+UnicodeNumber(InS, Ind)
|
||||||
else
|
else
|
||||||
Break;
|
Break;
|
||||||
Inc(Ind);
|
|
||||||
until False;
|
until False;
|
||||||
Result:=QuotedStr(Result);
|
Result:=QuotedStr(Result);
|
||||||
end;
|
end;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user