anchor.diff:  
   //-- BG ---------------------------------------------------------- 14.12.2010 --
   procedure TBuffer.DetectCodePage;
  +var
  +  ByteCount: Integer;
   
     function IsIso2022JP: boolean;
     {look for iso-2022-jp Japanese file}
     const
  -    EscSequence: array [0..3] of AnsiString = (
  -      #$1b'$@', #$1b'$B', #$1b'(J', #$1b'(B');
  +    EscSequence: array [0..3] of PAnsiChar = (#$1b'$@'#0, #$1b'$B'#0, #$1b'(J'#0, #$1b'(B'#0);
     var
  -    DocS: AnsiString;
  -    I, J, K, L: integer;
  +    I, J, K, L: PAnsiChar;
     begin
       Result := False;
  -    DocS := FPos.AnsiChr;
  -    I := AnsiPos(EscSequence[0], DocS); {look for starting sequence}
  -    J := AnsiPos(EscSequence[1], DocS);
  -    I := Max(I, J); {pick a positive value}
  -    if I > 0 then
  +    I := StrNPosA(FPos.AnsiChr, EscSequence[0], ByteCount); {look for starting sequence}
  +    J := StrNPosA(FPos.AnsiChr, EscSequence[1], ByteCount);
  +    if I < J then
  +      I := J;
  +    if I <> nil then
       begin {now look for ending sequence after the start}
  -      K := AnsiPosX(EscSequence[2], DocS, I);
  -      L := AnsiPosX(EscSequence[3], DocS, I);
  -      K := Max(K, L); {pick a positive value}
  -      if K > 0 then {start and end sequence found}
  +      K := StrNPosA(I, EscSequence[2], ByteCount);
  +      L := StrNPosA(I, EscSequence[3], ByteCount);
  +      if K < L then
  +        K := L; {pick a positive value}
  +      if K <> nil then {start and end sequence found}
           Result := True;
       end;
     end;
   
  -var
  -  ByteCount: Integer;
   begin
     ByteCount := FEnd.AnsiChr - FPos.AnsiChr;
     if ByteCount >= 2 then
  
positive.code:   Bytes[1] := B;
  end;
  
  //------------------------------------------------------------------------------
  function AnsiPosX(const SubStr, S: AnsiString; Offset: Integer = 1): Integer;
  {find substring in S starting at Offset}
  var
    S1: AnsiString;
    I: Integer;
  begin
    if Offset <= 1 then
      Result := AnsiPos(SubStr, S)
    else
    begin
      S1 := Copy(S, Offset, Length(S) - Offset + 1);
      I := AnsiPos(SubStr, S1);
      if I > 0 then
        Result := I + Offset - 1
      else
        Result := 0;
    end;
  end;
  
  { TBuffCharSetCodePageInfo }
  
negative.code:       if FPos.AnsiChr < FEnd.AnsiChr then
        begin
          Len := GetNextJisAsShiftJis(Buffer2);
          MultiByteToWideChar(932, 0, PAnsiChar(@Buffer2[0]), Len, @Result, 1);
        end
        else
          Result := TBuffChar(0);
  