Page 1 of 1

TFindFile Content Search Bug

PostPosted: May 6th, 2009, 9:06 am
by softboy99
i serach filename=*.doc

content = '123'

find some files which doesn't contain '123'.


also
i search some asian language strings(eg:Chinese simp),cannot find any result.



i use Delphi 2007 + tnt unicode v2.0.3, and your unidcode version TFindFile.

Re: TFindFile Content Search Bug

PostPosted: May 6th, 2009, 9:50 am
by softboy99
Code: Select all
function FileContainsPhrase(const FileName: WideString;
  const Phrase: TStringVariants; Options: TContentSearchOptions): Boolean;
const
  UNICODE_BOM: WideChar = #$FEFF;
  UNICODE_BOM_SWAPPED: WideChar = #$FFFE;
  UTF8_BOM: array[1..3] of AnsiChar = (#$EF, #$BB, #$BF);
var
  Stream: TFileStream;
  BOMBytes: array[1..3] of AnsiChar;
  BOM: WideChar absolute BOMBytes;
  BOMSize: Integer;
begin
  Stream := TFileStream.Create(FileName, fmOpenRead or fmShareDenyNone);
  try
    BOMSize := Stream.Read(BOM, SizeOf(BOM));
    if BOMSize = SizeOf(BOM) then
    begin
      if (BOM = UNICODE_BOM) or (BOM = UNICODE_BOM_SWAPPED) then
      begin
        Result := StreamContainsPhraseWide(Stream, PWideChar(Phrase.Unicode),
          Length(Phrase.Unicode), Options, BOM = UNICODE_BOM_SWAPPED);
        Exit;
      end
      else if (BOMBytes[1] = UTF8_BOM[1]) and (BOMBytes[2] = UTF8_BOM[2]) then
      begin
        Inc(BOMSize, Stream.Read(BOMBytes[3], SizeOf(BOMBytes[3])));
        if (BOMSize = SizeOf(UTF8_BOM)) and (BOMBytes[3] = UTF8_BOM[3]) then
        begin
          Result := StreamContainsPhraseUtf8(Stream, PAnsiChar(Phrase.Utf8),
            Length(Phrase.Utf8), Options);
          Exit;
        end;
      end;
    end;
    Stream.Seek(-BOMSize, soFromCurrent);
    Result := StreamContainsPhraseAnsi(Stream, PAnsiChar(Phrase.Ansi),
      Length(Phrase.Ansi), Options);
  finally
    Stream.Free;
  end;
end;


the problem is in BOM = UNICODE_BOM, It seems that the BOM never equals to UNICODE_BOM when you use chinese simpied string. so only StreamContainsPhraseAnsi is called.

Re: TFindFile Content Search Bug

PostPosted: May 6th, 2009, 10:03 am
by Kambiz
Please attach one of your text files, so that I can trace the issue.

Re: TFindFile Content Search Bug

PostPosted: May 7th, 2009, 12:42 am
by softboy99
search content ='机密'

Re: TFindFile Content Search Bug

PostPosted: May 7th, 2009, 12:59 am
by softboy99
http://www.totalcmd.net/plugring/TextSearch.html


you can refer to the solutions at the above link.

Re: TFindFile Content Search Bug

PostPosted: May 7th, 2009, 1:01 am
by softboy99
http://www.totalcmd.net/plugring/xPDFSearch.html


another functionality about search in PDF Files.

Re: TFindFile Content Search Bug

PostPosted: May 7th, 2009, 2:38 am
by Kambiz
I just got what you mean.

That's not a bug but a limitation. The component does a plain search for none text files.

Re: TFindFile Content Search Bug

PostPosted: May 8th, 2009, 2:17 am
by softboy99
oh, so bad.could you please add the ability to serach content in the non plaint text file?


i have attache the total commander's solution which is open source in my prievous post here.