anchor.diff:    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;
  +//-- BG ---------------------------------------------------------- 15.07.2012 --
  +function StrNCmpA(Str1, Str2: PAnsiChar; N: Integer): Integer;
  +var
  +  StrEnd: PAnsiChar;
  +begin
  +  StrEnd := Str1 + N;
  +  while Str1 < StrEnd do
  +  begin
  +    Result := Ord(Str1^) - Ord(Str2^);
  +    if (Result <> 0) or (Str1^ = #0) then
  +      Exit;
  +    Inc(Str1);
  +    Inc(Str2);
  +  end;
  +  Result := 0;
  +end;
  +
  +//-- BG ---------------------------------------------------------- 15.07.2012 --
  +function StrNPosA(Str, SubStr: PAnsiChar; N: Integer): PAnsiChar;
  +// returns a pointer to the first occurrence of SubStr in the first N chars of Str.
  +// Finds SubStr only, if the entire SubStr is within the first N chars.
  +// Example:
  +//   StrNPosA('expression', 'press', 7) finds pointer to 'pression' while
  +//   StrNPosA('expression', 'press', 6) retuns nil, as 'press' is not in the first 6 chars ('expres').
  +var
  +  L: Integer;
  +  StrEnd: PAnsiChar;
  +begin
  +  StrEnd := SubStr;
  +  while StrEnd^ <> #0 do
  +    Inc(StrEnd);
  +  L := StrEnd - SubStr;
  +  if L > 0 then  // Make sure substring not null string and SubStr fits into Str at all.
  +  begin
  +    Result := Str;
  +    StrEnd := Str + N - L;
  +    while (Result < StrEnd) and (Result^ <> #0) do
  +    begin
  +      if StrNCmpA(Result, SubStr, L) = 0 then
  +        Exit;
  +      Inc(Result);
  +    end;
  +  end;
  +  Result := nil;
   end;
   
   { TBuffCharSetCodePageInfo }
  
positive.code:       if FPos.AnsiChr < FEnd.AnsiChr then
        begin
          Len := GetNextEucAsShiftJis(Buffer2);
          MultiByteToWideChar(FCodePage, 0, PAnsiChar(@Buffer2[0]), Len, @Result, 1);
        end
        else
          Result := TBuffChar(0);
  
negative.code: 
  //-- 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 PAnsiChar = (#$1b'$@'#0, #$1b'$B'#0, #$1b'(J'#0, #$1b'(B'#0);
    var
      I, J, K, L: PAnsiChar;
    begin
      Result := False;
      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 := 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;
  
  begin
    ByteCount := FEnd.AnsiChr - FPos.AnsiChr;
    if ByteCount >= 2 then
  