mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-11 21:55:56 +02:00
LCL: Read po file: some optimizations
git-svn-id: trunk@34231 -
This commit is contained in:
parent
7680480e17
commit
f50fcef931
@ -569,16 +569,6 @@ msgid " Do not show splash screen"
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
}
|
}
|
||||||
const
|
|
||||||
sCommentIdentifier: PChar = '#: ';
|
|
||||||
sCharSetIdentifier: PChar = '"Content-Type: text/plain; charset=';
|
|
||||||
sMsgID: PChar = 'msgid "';
|
|
||||||
sMsgStr: PChar = 'msgstr "';
|
|
||||||
sMsgCtxt: Pchar = 'msgctxt "';
|
|
||||||
sFlags: Pchar = '#, ';
|
|
||||||
sPrevMsgID: PChar = '#| msgid "';
|
|
||||||
sPrevStr: PChar = '#| "';
|
|
||||||
|
|
||||||
const
|
const
|
||||||
ciNone = 0;
|
ciNone = 0;
|
||||||
ciMsgID = 1;
|
ciMsgID = 1;
|
||||||
@ -602,6 +592,7 @@ var
|
|||||||
OldLineStartPos: PtrUInt;
|
OldLineStartPos: PtrUInt;
|
||||||
NewSrc: String;
|
NewSrc: String;
|
||||||
s: String;
|
s: String;
|
||||||
|
Handled: Boolean;
|
||||||
|
|
||||||
procedure ResetVars;
|
procedure ResetVars;
|
||||||
begin
|
begin
|
||||||
@ -656,23 +647,11 @@ var
|
|||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TestPrefixStr(AIndex: Integer): boolean;
|
procedure StartNextLine(AIndex: Integer; TxtStart: PChar);
|
||||||
var
|
|
||||||
s: PChar;
|
|
||||||
l: Integer;
|
|
||||||
begin
|
begin
|
||||||
case aIndex of
|
StoreCollectedLine;
|
||||||
ciMsgID: s:=sMsgId;
|
CollectedIndex := AIndex;
|
||||||
ciMsgStr: s:=sMsgStr;
|
Line:=UTF8CStringToUTF8String(TxtStart,LineEnd-TxtStart);
|
||||||
ciPrevMsgId: s:=sPrevMsgId;
|
|
||||||
end;
|
|
||||||
result := IsKey(LineStart, s);
|
|
||||||
if Result then begin
|
|
||||||
StoreCollectedLine;
|
|
||||||
CollectedIndex := AIndex;
|
|
||||||
L := Length(s);
|
|
||||||
Line:=UTF8CStringToUTF8String(LineStart+L,LineLen-L-1);
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
@ -694,49 +673,84 @@ begin
|
|||||||
while (not (LineEnd^ in [#0,#10,#13])) do inc(LineEnd);
|
while (not (LineEnd^ in [#0,#10,#13])) do inc(LineEnd);
|
||||||
LineLen:=LineEnd-LineStart;
|
LineLen:=LineEnd-LineStart;
|
||||||
if LineLen>0 then begin
|
if LineLen>0 then begin
|
||||||
if IsKey(LineStart,sCommentIdentifier) then begin
|
Handled:=false;
|
||||||
AddEntry;
|
case LineStart^ of
|
||||||
Identifier:=copy(s,LineStart-p+4,LineLen-3);
|
'#':
|
||||||
// the RTL creates identifier paths with point instead of colons
|
|
||||||
// fix it:
|
|
||||||
for i:=1 to length(Identifier) do
|
|
||||||
if Identifier[i]=':' then
|
|
||||||
Identifier[i]:='.';
|
|
||||||
end else if TestPrefixStr(ciMsgId) then begin
|
|
||||||
end else if TestPrefixStr(ciMsgStr) then begin
|
|
||||||
end else if TestPrefixStr(ciPrevMsgId) then begin
|
|
||||||
end else if IsKey(LineStart, sMsgCtxt) then begin
|
|
||||||
Context:= Copy(LineStart, 10, LineLen-10);
|
|
||||||
end else if IsKey(LineStart, sFlags) then begin
|
|
||||||
Flags := copy(LineStart, 4, LineLen-3);
|
|
||||||
end else if (LineStart^='"') then begin
|
|
||||||
if (MsgID='') and IsKey(LineStart,sCharSetIdentifier) then
|
|
||||||
begin
|
begin
|
||||||
FCharSet:=copy(LineStart,36,LineLen-38);
|
case LineStart[1] of
|
||||||
if SysUtils.CompareText(FCharSet,'UTF-8')<>0 then begin
|
':':
|
||||||
// convert encoding to UTF-8
|
if LineStart[2]=' ' then begin
|
||||||
OldLineStartPos:=PtrUInt(LineStart-PChar(s))+1;
|
// '#: '
|
||||||
NewSrc:=ConvertEncoding(copy(s,OldLineStartPos,length(s)),
|
AddEntry;
|
||||||
FCharSet,EncodingUTF8);
|
Identifier:=copy(s,LineStart-p+4,LineLen-3);
|
||||||
// replace text and update all pointers
|
// the RTL creates identifier paths with point instead of colons
|
||||||
s:=copy(s,1,OldLineStartPos-1)+NewSrc;
|
// fix it:
|
||||||
l:=length(s);
|
for i:=1 to length(Identifier) do
|
||||||
p:=PChar(s);
|
if Identifier[i]=':' then
|
||||||
TextEnd:=p+l;
|
Identifier[i]:='.';
|
||||||
LineStart:=p+(OldLineStartPos-1);
|
Handled:=true;
|
||||||
LineEnd:=LineStart;
|
end;
|
||||||
while (not (LineEnd^ in [#0,#10,#13])) do inc(LineEnd);
|
'|':
|
||||||
LineLen:=LineEnd-LineStart;
|
if IsKey(LineStart,'#| msgid "') then begin
|
||||||
|
StartNextLine(ciPrevMsgId,LineStart+length('#| msgid "'));
|
||||||
|
Handled:=true;
|
||||||
|
end else if IsKey(LineStart, '#| "') then begin
|
||||||
|
Line := Line + UTF8CStringToUTF8String(LineStart+5,LineLen-6);
|
||||||
|
Handled:=true;
|
||||||
|
end;
|
||||||
|
',':
|
||||||
|
if LineStart[2]=' ' then begin
|
||||||
|
// '#, '
|
||||||
|
Flags := copy(LineStart, 4, LineLen-3);
|
||||||
|
Handled:=true;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
if not Handled then begin
|
||||||
|
// '#'
|
||||||
|
if Comments<>'' then
|
||||||
|
Comments := Comments + LineEnding;
|
||||||
|
Comments := Comments + Copy(LineStart, 1, LineLen);
|
||||||
|
Handled:=true;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
Line := Line + UTF8CStringToUTF8String(LineStart+1,LineLen-2);
|
'm':
|
||||||
end else if IsKey(LineStart, sPrevStr) then begin
|
if IsKey(LineStart,'msgid "') then begin
|
||||||
Line := Line + UTF8CStringToUTF8String(LineStart+5,LineLen-6);
|
StartNextLine(ciMsgId,LineStart+length('msgid "'));
|
||||||
end else if LineStart^='#' then begin
|
Handled:=true;
|
||||||
if Comments<>'' then
|
end else if IsKey(LineStart,'msgstr "') then begin
|
||||||
Comments := Comments + LineEnding;
|
StartNextLine(ciMsgStr,LineStart+length('msgstr "'));
|
||||||
Comments := Comments + Copy(LineStart, 1, LineLen);
|
Handled:=true;
|
||||||
end else
|
end else if IsKey(LineStart, 'msgctxt "') then begin
|
||||||
|
Context:= Copy(LineStart, 10, LineLen-10);
|
||||||
|
Handled:=true;
|
||||||
|
end;
|
||||||
|
'"':
|
||||||
|
begin
|
||||||
|
if (MsgID='')
|
||||||
|
and IsKey(LineStart,'"Content-Type: text/plain; charset=') then
|
||||||
|
begin
|
||||||
|
FCharSet:=copy(LineStart,36,LineLen-38);
|
||||||
|
if SysUtils.CompareText(FCharSet,'UTF-8')<>0 then begin
|
||||||
|
// convert encoding to UTF-8
|
||||||
|
OldLineStartPos:=PtrUInt(LineStart-PChar(s))+1;
|
||||||
|
NewSrc:=ConvertEncoding(copy(s,OldLineStartPos,length(s)),
|
||||||
|
FCharSet,EncodingUTF8);
|
||||||
|
// replace text and update all pointers
|
||||||
|
s:=copy(s,1,OldLineStartPos-1)+NewSrc;
|
||||||
|
l:=length(s);
|
||||||
|
p:=PChar(s);
|
||||||
|
TextEnd:=p+l;
|
||||||
|
LineStart:=p+(OldLineStartPos-1);
|
||||||
|
LineEnd:=LineStart;
|
||||||
|
while (not (LineEnd^ in [#0,#10,#13])) do inc(LineEnd);
|
||||||
|
LineLen:=LineEnd-LineStart;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
Line := Line + UTF8CStringToUTF8String(LineStart+1,LineLen-2);
|
||||||
|
Handled:=true;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
if not Handled then
|
||||||
AddEntry;
|
AddEntry;
|
||||||
end;
|
end;
|
||||||
LineStart:=LineEnd+1;
|
LineStart:=LineEnd+1;
|
||||||
|
Loading…
Reference in New Issue
Block a user