去掉代码中的注释

  • 主题发起人 主题发起人 import
  • 开始时间 开始时间
I

import

Unregistered / Unconfirmed
GUEST, unregistred user!
去掉代码中的注释: type
TModalStr = record
rBegin: string;
rEnd: string;
rAppend: string;
rSingle: Byte;
end;
const
cPascalCount = 5;
cPascalList: array[0 .. Pred(cPascalCount)] of TModalStr =
(
(rBegin: ''''; rEnd: ''''; rAppend: ''; rSingle: 1),
(rBegin: '{$'; rEnd: '}'; rAppend: ''; rSingle: 2),
(rBegin: '{'; rEnd: '}'; rAppend: ''; rSingle: 3),
(rBegin: '(*'; rEnd: '*)'; rAppend: ''; rSingle: 4),
(rBegin: '//'; rEnd: #13#10; rAppend: #13#10; rSingle: 5)
);
const
cSQLCount = 4;
cSQLList: array[0 .. Pred(cSQLCount)] of TModalStr =
(
(rBegin: ''''; rEnd: ''''; rAppend: ''; rSingle: 1),
(rBegin: '"'; rEnd: '"'; rAppend: ''; rSingle: 2),
(rBegin: '/*'; rEnd: '*/'; rAppend: ''; rSingle: 3),
(rBegin: '--'; rEnd: #13#10; rAppend: #13#10; rSingle: 4)
);
function GetModalStr(mStr: string; mModalStrList: array of TModalStr;
mSingles: TIntegerSet): string;
var
vSingle: Integer;
I, J: Integer;
T, K: Integer;
vEnd: string;
vAppend: string;
begin
Result := '';
vSingle := 0;
T := 0;
K := 0;
for I := 1 to Length(mStr) do begin
if T > 1 then begin
Dec(T);
Continue;
end;
if vSingle = 0 then begin
vEnd := '';
for J := Low(mModalStrList) to High(mModalStrList) do begin
K := Length(mModalStrList[J].rBegin);
if Copy(mStr, I, K) = mModalStrList[J].rBegin then begin
vEnd := mModalStrList[J].rEnd;
vAppend := mModalStrList[J].rAppend;
vSingle := mModalStrList[J].rSingle;
if vSingle in mSingles then
Result := Result + mModalStrList[J].rBegin;
T := K;
K := Length(vEnd);
Break;
end;
end;
if (vEnd = '') and (vSingle in mSingles) then
Result := Result + mStr;
end else if Copy(mStr, I, K) = vEnd then begin
if vSingle in mSingles then
Result := Result + vEnd
else Result := Result + vAppend;
vSingle := 0;
T := K;
end else if vSingle in mSingles then
Result := Result + mStr;
end;
end; { GetModalStr }
procedure TForm1.Button1Click(Sender: TObject);
begin
Memo2.Text := GetModalStr(Memo1.Text, cPascalList, [0..cPascalCount] - [3, 4, 5]);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Memo2.Text := GetModalStr(Memo1.Text, cSQLList, [0..cSQLCount] - [3, 4]);
end;
 

Similar threads

A
回复
0
查看
987
Andreas Hausladen
A
S
回复
0
查看
694
SUNSTONE的Delphi笔记
S
A
回复
0
查看
968
Andreas Hausladen
A
S
回复
0
查看
689
SUNSTONE的Delphi笔记
S
I
回复
0
查看
635
import
I
后退
顶部