+ Added some documentation
+ Now verifies the given priority is valid git-svn-id: file:///srv/svn/repos/haiku/trunk/current@649 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -18,6 +18,9 @@ namespace Sniffer {
|
|||||||
|
|
||||||
class Expr;
|
class Expr;
|
||||||
|
|
||||||
|
/*! \brief A priority and a list of expressions to be used for sniffing out the
|
||||||
|
type of an untyped file.
|
||||||
|
*/
|
||||||
class Rule {
|
class Rule {
|
||||||
public:
|
public:
|
||||||
Rule();
|
Rule();
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
MIME sniffer rule implementation
|
MIME sniffer rule implementation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <sniffer/Err.h>
|
||||||
#include <sniffer/Expr.h>
|
#include <sniffer/Expr.h>
|
||||||
#include <sniffer/Rule.h>
|
#include <sniffer/Rule.h>
|
||||||
#include <DataIO.h>
|
#include <DataIO.h>
|
||||||
@@ -28,12 +29,13 @@ Rule::InitCheck() const {
|
|||||||
return fExprList ? B_OK : B_NO_INIT;
|
return fExprList ? B_OK : B_NO_INIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Returns the priority of the rule. 0.0 <= priority <= 1.0.
|
||||||
double
|
double
|
||||||
Rule::Priority() const {
|
Rule::Priority() const {
|
||||||
return fPriority;
|
return fPriority;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Sniffs the given data stream. Returns true if the rule matches, false if not.
|
||||||
bool
|
bool
|
||||||
Rule::Sniff(BPositionIO *data) const {
|
Rule::Sniff(BPositionIO *data) const {
|
||||||
if (InitCheck() != B_OK)
|
if (InitCheck() != B_OK)
|
||||||
@@ -56,10 +58,14 @@ Rule::Unset() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Called by Parser::Parse() after successfully parsing a sniffer rule.
|
||||||
void
|
void
|
||||||
Rule::SetTo(double priority, std::vector<Expr*>* list) {
|
Rule::SetTo(double priority, std::vector<Expr*>* list) {
|
||||||
Unset();
|
Unset();
|
||||||
|
if (0.0 <= priority && priority <= 1.0)
|
||||||
fPriority = priority;
|
fPriority = priority;
|
||||||
|
else
|
||||||
|
throw new Err("Sniffer pattern error: invalid priority", -1);
|
||||||
fExprList = list;
|
fExprList = list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user