История изменений
Исправление bormant, (текущая версия) :
cVal поведением похожа на Val, в том числе не допускает мусора после числа:
type
TComplex = array [0..1] of Real;
function RTrim(const s: String): String;
var i: Integer;
begin
i:=Length(s); while (i>0) and (s[i]<=' ') do Dec(i);
RTrim:=Copy(s,1,i);
end;
procedure cVal(const s: String; var c: TComplex; var code: Integer);
{ Вход: "_*(_*ДействЧисло_*;_*ДействЧисло_*)" }
var t: TComplex; i, j: Integer;
begin
i:=1;
while (i<=Length(s)) and (s[i]<=' ') do Inc(i);
if (i>Length(s)) or (s[i]<>'(') then begin
code:=i; Exit;
end;
Inc(i); j:=Pos(';',s);
Val(RTrim(Copy(s,i,j-i)),t[0],code);
if code>0 then begin
Inc(code,i); Exit;
end;
Inc(j); i:=Pos(')',s);
Val(RTrim(Copy(s,j,i-j)),t[1],code);
if code>0 then begin
Inc(code,j); Exit;
end;
if i<Length(s) then begin
code:=i+1; Exit;
end;
c:=t;
end;
Исправление bormant, :
cVal поведением похожа на Val, в том числе не допускает мусора после числа:
type
TComplex = array [0..1] of Real;
function RTrim(const s: String): String;
var i: Integer;
begin
i:=Length(s); while (i>0) and (s[i]<=' ') do Dec(i);
RTrim:=Copy(s,1,i);
end;
procedure cVal(const s: String; var c: TComplex; var code: Integer);
{ Вход: "_*(_*ДействЧисло_*;_*ДействЧисло_*)" }
var t: TComplex; i, j: Integer;
begin
i:=1;
while (i<=Length(s)) and (s[i]<=' ') do Inc(i);
if (i>Length(s)) or (s[i]<>'(') then begin
code:=i; Exit;
end;
Inc(i); j:=Pos(';',s);
Val(RTrim(Copy(s,i,j-i)),t[0],code);
if code>0 then begin
Inc(code,i); Exit;
end;
Inc(j); i:=Pos(')',s);
Val(RTrim(Copy(s,j,i-j)),t[1],code);
if code>0 then begin
Inc(code,j); Exit;
end;
if i<Length(s) then begin
code:=i; Exit;
end;
c:=t;
end;
Исходная версия bormant, :
cVal поведением похожа на Val, в том числе не допускает мусора после числа:
type
TComplex = array [0..1] of Real;
function RTrim(const s: String): String;
var i: Integer;
begin
i:=Length(s); while (i>0) and (s[i]<=' ') do Dec(i);
RTrim:=Copy(s,1,i);
end;
procedure cVal(const s: String; var c: TComplex; var code: Integer);
{ Вход: "_*(_*ДействЧисло_*;_*ДействЧисло_*)" }
var t: TComplex; i, j: Integer;
begin
i:=1;
while (i<=Length(s)) and (s[i]<=' ') do Inc(i);
if (i>Length(s)) or (s[i]<>'(') then begin
code:=i; Exit;
end;
Inc(i); j:=Pos(';',s);
Val(RTrim(Copy(s,i+1,j-i)),t[0],code);
if code>0 then begin
Inc(code,i); Exit;
end;
Inc(j); i:=Pos(')',s);
Val(RTrim(Copy(s,j,i-j)),t[1],code);
if code>0 then begin
Inc(code,j); Exit;
end;
if i<Length(s) then begin
code:=i; Exit;
end;
c:=t;
end;