1//----------------------------------------------------------------------
2//  This software is part of the Haiku distribution and is covered
3//  by the MIT License.
4//---------------------------------------------------------------------
5/*!
6	\file sniffer/Pattern.h
7	Mime Sniffer Pattern declarations
8*/
9#ifndef _SNIFFER_PATTERN_H
10#define _SNIFFER_PATTERN_H
11
12#include <SupportDefs.h>
13#include <string>
14#include <sniffer/Range.h>
15
16class BPositionIO;
17
18namespace BPrivate {
19namespace Storage {
20namespace Sniffer {
21
22class Err;
23
24//! A byte string and optional mask to be compared against a data stream.
25/*! The byte string and mask (if supplied) must be of the same length. */
26class Pattern {
27public:
28	Pattern(const std::string &string, const std::string &mask);
29	Pattern(const std::string &string);
30	~Pattern();
31
32	status_t InitCheck() const;
33	Err* GetErr() const;
34
35	bool Sniff(Range range, BPositionIO *data, bool caseInsensitive) const;
36	ssize_t BytesNeeded() const;
37
38	status_t SetTo(const std::string &string, const std::string &mask);
39private:
40	bool Sniff(off_t start, off_t size, BPositionIO *data, bool caseInsensitive) const;
41
42	void SetStatus(status_t status, const char *msg = NULL);
43	void SetErrorMessage(const char *msg);
44
45	std::string fString;
46	std::string fMask;
47
48	status_t fCStatus;
49	Err *fErrorMessage;
50};
51
52};	// namespace Sniffer
53};	// namespace Storage
54};	// namespace BPrivate
55
56#endif	// _SNIFFER_PATTERN_H
57
58
59