106
Bug reports / function cut() io non comprendere
« on: December 06, 2007, 11:21:31 PM »
procedure cut();
var
from, upTo, l: integer;
s: string;
begin
(1) s:=par(2);
(2) l:=length(s);
(3) from:=strToIntDef(par(0), 1);
(4) upTo:=strToIntDef(par(1), l);
(5) if from < 0 then from:=l+from+1;
(6) if upTo >= 0 then upTo:=from+upTo-1
(7) else upTo:=l+upTo;
(8) result:=substr(s, from, upTo);
end; // cut
(0) {{cut|-3|-4|ABCDEFGH}}
(1) s='ABCDEFGH'
(2) l=
(3) from=-3
(4) upTo:=-4
(5) if from < 0 then from:=l+from+1; --> from=8-3+1=6
(6) if upTo >= 0 then upTo:=from+upTo-1
(7) else upTo:=l+upTo; --> upto=8-4=4
(8) result:=substr(s, from, upTo) ---> substr(s,6,4)=copy(s,6,4-6+1)=copy(s,6,-1)=?????
quelle est dans ton idée l'usage de nombres negatifs dans la macro cut ??
non documentée dans le wiki:
if name = 'replace' then
result:=replaceText(par(2), par(1), p);
var
from, upTo, l: integer;
s: string;
begin
(1) s:=par(2);
(2) l:=length(s);
(3) from:=strToIntDef(par(0), 1);
(4) upTo:=strToIntDef(par(1), l);
(5) if from < 0 then from:=l+from+1;
(6) if upTo >= 0 then upTo:=from+upTo-1
(7) else upTo:=l+upTo;
(8) result:=substr(s, from, upTo);
end; // cut
(0) {{cut|-3|-4|ABCDEFGH}}
(1) s='ABCDEFGH'
(2) l=
(3) from=-3
(4) upTo:=-4
(5) if from < 0 then from:=l+from+1; --> from=8-3+1=6
(6) if upTo >= 0 then upTo:=from+upTo-1
(7) else upTo:=l+upTo; --> upto=8-4=4
(8) result:=substr(s, from, upTo) ---> substr(s,6,4)=copy(s,6,4-6+1)=copy(s,6,-1)=?????
quelle est dans ton idée l'usage de nombres negatifs dans la macro cut ??
non documentée dans le wiki:
if name = 'replace' then
result:=replaceText(par(2), par(1), p);