btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / apps / text_search / FileIterator.cpp
blob8a4a9453711c9221a9a36810da5e3aba34075832
1 /*
2 * Copyright 2008, Stephan Aßmus <superstippi@gmx.de>.
3 * Copyright 1998-2007, Matthijs Hollemans.
5 * Distributed under the terms of the MIT License.
6 */
9 #include "FileIterator.h"
11 #include <string.h>
13 #include <Entry.h>
14 #include <NodeInfo.h>
15 #include <Path.h>
18 FileIterator::FileIterator()
23 FileIterator::~FileIterator()
28 bool
29 FileIterator::_ExamineFile(BEntry& entry, char* buffer, bool textFilesOnly)
31 BPath path;
32 if (entry.GetPath(&path) != B_OK)
33 return false;
35 strcpy(buffer, path.Path());
37 if (!textFilesOnly)
38 return true;
40 BMimeType mimeType;
41 BNode node(&entry);
42 BNodeInfo nodeInfo(&node);
43 char mimeTypeString[B_MIME_TYPE_LENGTH];
45 if (nodeInfo.GetType(mimeTypeString) != B_OK) {
46 // try to get a MIME type before failing
47 if (BMimeType::GuessMimeType(path.Path(), &mimeType) != B_OK)
48 return false;
50 nodeInfo.SetType(mimeType.Type());
51 } else
52 mimeType.SetTo(mimeTypeString);
54 BMimeType superType;
55 if (mimeType.GetSupertype(&superType) == B_OK) {
56 if (strcmp("text", superType.Type()) == 0
57 || strcmp("message", superType.Type()) == 0) {
58 return true;
61 // Make an exception for XHTML files
62 if (strcmp("application/xhtml+xml", mimeTypeString) == 0)
63 return true;
65 return false;