>>863 逆の働きをする関数 .NETスレから

type TCommentLineProc=procedure (str:String) of object;
procedure CommentProc(str:string;func:TCommentLineProc);
var lineno,n,cnt:Integer;
  nowc:Char;
function getn:char;
begin
 if n>cnt then Result:=#0
 else begin Result:=str[n]; inc(n);end;
 nowc:=Result;
end;
procedure comfunc(st:Integer;ed:string);
begin
while n <=cnt do begin
  if ByteType(str,n)= mbLeadByte then begin
  inc(n,2);
  continue;
  end;
 if getn=ed[1] then begin
 if (ed[2]=#0) or (getn=ed[1]) then break;
 end;
 end;
  func(copy(str,st,(n-st) ));
end;
begin

cnt:=Length(str);
n:=1;
while n <=cnt do begin
if ByteType(str,n)= mbLeadByte then begin
 inc(n,2);
continue;
end;
 getn;
 case nowc of
  '(': if getn='*' then comfunc(n-2,'*)');
  '{': comfunc(n-1,'}'#0);
  '/': if getn='/' then comfunc(n-2,#13#0);
  '''': begin
  while getn<>'''' do if n>cnt then break;
  end;
 end;

end;
end;