Added InitCheck() and GetErr()
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@606 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -13,9 +13,14 @@
|
||||
|
||||
namespace Sniffer {
|
||||
|
||||
class Err;
|
||||
|
||||
class Range {
|
||||
public:
|
||||
Range(int32 start, int32 end);
|
||||
|
||||
status_t InitCheck() const;
|
||||
Err* GetErr() const;
|
||||
|
||||
int32 Start() const;
|
||||
int32 End() const;
|
||||
@@ -24,6 +29,7 @@ public:
|
||||
private:
|
||||
int32 fStart;
|
||||
int32 fEnd;
|
||||
status_t fCStatus;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
MIME sniffer range implementation
|
||||
*/
|
||||
|
||||
#include <sniffer/Err.h>
|
||||
#include <sniffer/Range.h>
|
||||
#include <sniffer/Parser.h>
|
||||
#include <stdio.h>
|
||||
@@ -16,10 +17,29 @@ using namespace Sniffer;
|
||||
Range::Range(int32 start, int32 end)
|
||||
: fStart(-1)
|
||||
, fEnd(-1)
|
||||
, fCStatus(B_NO_INIT)
|
||||
{
|
||||
SetTo(start, end);
|
||||
}
|
||||
|
||||
status_t
|
||||
Range::InitCheck() const {
|
||||
return fCStatus;
|
||||
}
|
||||
|
||||
Err*
|
||||
Range::GetErr() const {
|
||||
if (fCStatus == B_OK)
|
||||
return NULL;
|
||||
else {
|
||||
char start_str[32];
|
||||
char end_str[32];
|
||||
sprintf(start_str, "%ld", fStart);
|
||||
sprintf(end_str, "%ld", fEnd);
|
||||
return new Err(std::string("Sniffer Parser Error -- Invalid range: [") + start_str + ":" + end_str + "]", -1);
|
||||
}
|
||||
}
|
||||
|
||||
int32
|
||||
Range::Start() const {
|
||||
return fStart;
|
||||
@@ -32,14 +52,11 @@ Range::End() const {
|
||||
|
||||
void
|
||||
Range::SetTo(int32 start, int32 end) {
|
||||
if (start > end) {
|
||||
char start_str[32];
|
||||
char end_str[32];
|
||||
sprintf(start_str, "%ld", start);
|
||||
sprintf(end_str, "%ld", end);
|
||||
throw new Err(std::string("Sniffer Parser Error -- Invalid range: [") + start_str + ":" + end_str + "]", -1);
|
||||
} else {
|
||||
fStart = start;
|
||||
fEnd = end;
|
||||
if (start > end) {
|
||||
fCStatus = B_BAD_VALUE;
|
||||
} else {
|
||||
fCStatus = B_OK;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user