LCL: Read po file: some optimizations

git-svn-id: trunk@34231 -
This commit is contained in:
mattias 2011-12-16 21:04:06 +00:00
parent 7680480e17
commit f50fcef931

View File

@ -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
ciMsgID: s:=sMsgId;
ciMsgStr: s:=sMsgStr;
ciPrevMsgId: s:=sPrevMsgId;
end;
result := IsKey(LineStart, s);
if Result then begin
StoreCollectedLine; StoreCollectedLine;
CollectedIndex := AIndex; CollectedIndex := AIndex;
L := Length(s); Line:=UTF8CStringToUTF8String(TxtStart,LineEnd-TxtStart);
Line:=UTF8CStringToUTF8String(LineStart+L,LineLen-L-1);
end;
end; end;
begin begin
@ -694,7 +673,14 @@ 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;
case LineStart^ of
'#':
begin
case LineStart[1] of
':':
if LineStart[2]=' ' then begin
// '#: '
AddEntry; AddEntry;
Identifier:=copy(s,LineStart-p+4,LineLen-3); Identifier:=copy(s,LineStart-p+4,LineLen-3);
// the RTL creates identifier paths with point instead of colons // the RTL creates identifier paths with point instead of colons
@ -702,15 +688,46 @@ begin
for i:=1 to length(Identifier) do for i:=1 to length(Identifier) do
if Identifier[i]=':' then if Identifier[i]=':' then
Identifier[i]:='.'; Identifier[i]:='.';
end else if TestPrefixStr(ciMsgId) then begin Handled:=true;
end else if TestPrefixStr(ciMsgStr) then begin end;
end else if TestPrefixStr(ciPrevMsgId) then begin '|':
end else if IsKey(LineStart, sMsgCtxt) then begin if IsKey(LineStart,'#| msgid "') then begin
Context:= Copy(LineStart, 10, LineLen-10); StartNextLine(ciPrevMsgId,LineStart+length('#| msgid "'));
end else if IsKey(LineStart, sFlags) then begin 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); Flags := copy(LineStart, 4, LineLen-3);
end else if (LineStart^='"') then begin Handled:=true;
if (MsgID='') and IsKey(LineStart,sCharSetIdentifier) then end;
end;
if not Handled then begin
// '#'
if Comments<>'' then
Comments := Comments + LineEnding;
Comments := Comments + Copy(LineStart, 1, LineLen);
Handled:=true;
end;
end;
'm':
if IsKey(LineStart,'msgid "') then begin
StartNextLine(ciMsgId,LineStart+length('msgid "'));
Handled:=true;
end else if IsKey(LineStart,'msgstr "') then begin
StartNextLine(ciMsgStr,LineStart+length('msgstr "'));
Handled:=true;
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 begin
FCharSet:=copy(LineStart,36,LineLen-38); FCharSet:=copy(LineStart,36,LineLen-38);
if SysUtils.CompareText(FCharSet,'UTF-8')<>0 then begin if SysUtils.CompareText(FCharSet,'UTF-8')<>0 then begin
@ -730,13 +747,10 @@ begin
end; end;
end; end;
Line := Line + UTF8CStringToUTF8String(LineStart+1,LineLen-2); Line := Line + UTF8CStringToUTF8String(LineStart+1,LineLen-2);
end else if IsKey(LineStart, sPrevStr) then begin Handled:=true;
Line := Line + UTF8CStringToUTF8String(LineStart+5,LineLen-6); end;
end else if LineStart^='#' then begin end;
if Comments<>'' then if not Handled then
Comments := Comments + LineEnding;
Comments := Comments + Copy(LineStart, 1, LineLen);
end else
AddEntry; AddEntry;
end; end;
LineStart:=LineEnd+1; LineStart:=LineEnd+1;