All pastes #349125 Raw Edit

Flawless

public text v1 · immutable
·published 2007-02-10 16:03 UTC
rendered paste body
function XStrStream_Move_u7bit(this: PStrStreamRec; const Count: XInt): XBool; xcc;
type
  PSrcType = PCharInt1;
  TSrcType = XCharInt1;
var
  P: PSrcType;
  EP: XBool;
  FP: PSrcType;
  LP: PSrcType;
  Err: XResult;
label
  Leave;
var
  Tmp: XInt;
begin
  Tmp := Count;
  EP  := False;
  FP  := this^.First;
  LP  := this^.Last;
  P   := this^.Pos;

  if Tmp = XMaxInt then
  begin
    P := LP;
    this^.PosIndex := this^.LastIndex;
    Err := xsOk;
    goto Leave;
  end;

  if Tmp = XMinInt then
  begin
    P := FP;
    this^.PosIndex := 0;
    Err := xsOk;
    goto Leave;
  end;

  while Tmp > 0 do
  begin
    if XUInt(P) < XUInt(LP) then
      Inc(P)
    else
      EP := True;
    if EP then Break;
    Inc(this^.PosIndex);
    Dec(Tmp);
  end;

  while Tmp < 0 do
  begin
    if XUInt(P) > XUInt(FP) then
      Dec(P)
    else
      EP := True;
    if EP then Break;
    Dec(this^.PosIndex);
    Inc(Tmp);
  end;

  Err := xsOk;
Leave:
  this^.Pos := P;
  Result := (Err = xsOk) and not EP;
end;