(Gast)
n/a Beiträge
|
Re: C-Like Formatfunktion
8. Apr 2008, 23:56
Delphi-Quellcode:
function UnescapeC(const s: string): string;
var i, cidx: integer; inEscape: Boolean;
procedure SpecialToChar(c: char): Char;
begin
case c of
'0': result := #0;
'a': result := #7;
'b': result := #8;
't': result := #9;
'n': result := #10;
'v': result := #11;
'f': result := #12;
'r': result := #13;
'e': result := #27;
end;
end;
begin
if not assigned(s) or Length(s) < 2 then
begin
result := s;
exit;
end;
cidx := 1;
inEscape := false;
SetLength(result, Length(s));
for i := 1 to Length(s) do
begin
case s[i] of
'\': begin
if inEscape then
begin
result[cidx] := '\';
Inc(cidx);
end;
inEscape := not inEscape;
end;
'0', 'a', 'b', 't', 'n', 'v', 'f', 'r', 'e':
begin
if inEscape then
result[cidx] := SpecialToChar(s[i]);
else
result[cidx] := s[i];
Inc(cidx);
inEscape := false;
end;
else
result[cidx] := s[i];
Inc(cidx);
end;
end;
SetLength(result, cidx-1);
end;
Habs nicht getestet, aber das sollte eigentlich funktionieren...
|
|
Zitat
|