diff --git a/headers/private/storage/sniffer/Rule.h b/headers/private/storage/sniffer/Rule.h index 500ed5d1d0..2ef8ed38f5 100644 --- a/headers/private/storage/sniffer/Rule.h +++ b/headers/private/storage/sniffer/Rule.h @@ -18,6 +18,9 @@ namespace Sniffer { class Expr; +/*! \brief A priority and a list of expressions to be used for sniffing out the + type of an untyped file. +*/ class Rule { public: Rule(); diff --git a/src/kits/storage/sniffer/Rule.cpp b/src/kits/storage/sniffer/Rule.cpp index 4a291c238f..57bdf350aa 100644 --- a/src/kits/storage/sniffer/Rule.cpp +++ b/src/kits/storage/sniffer/Rule.cpp @@ -7,6 +7,7 @@ MIME sniffer rule implementation */ +#include #include #include #include @@ -28,12 +29,13 @@ Rule::InitCheck() const { return fExprList ? B_OK : B_NO_INIT; } - +//! Returns the priority of the rule. 0.0 <= priority <= 1.0. double Rule::Priority() const { return fPriority; } +//! Sniffs the given data stream. Returns true if the rule matches, false if not. bool Rule::Sniff(BPositionIO *data) const { if (InitCheck() != B_OK) @@ -56,10 +58,14 @@ Rule::Unset() { } } +//! Called by Parser::Parse() after successfully parsing a sniffer rule. void Rule::SetTo(double priority, std::vector* list) { Unset(); - fPriority = priority; + if (0.0 <= priority && priority <= 1.0) + fPriority = priority; + else + throw new Err("Sniffer pattern error: invalid priority", -1); fExprList = list; }