xref: /haiku/src/kits/storage/sniffer/Range.cpp (revision b247f935d133a42c427cad8a759a1bf2f65bc290)
1 //----------------------------------------------------------------------
2 //  This software is part of the OpenBeOS distribution and is covered
3 //  by the MIT License.
4 //---------------------------------------------------------------------
5 /*!
6 	\file Range.cpp
7 	MIME sniffer range implementation
8 */
9 
10 #include <sniffer/Err.h>
11 #include <sniffer/Range.h>
12 #include <sniffer/Parser.h>
13 #include <stdio.h>
14 
15 using namespace BPrivate::Storage::Sniffer;
16 
17 Range::Range(int32 start, int32 end)
18 	: fStart(-1)
19 	, fEnd(-1)
20 	, fCStatus(B_NO_INIT)
21 {
22 	SetTo(start, end);
23 }
24 
25 status_t
26 Range::InitCheck() const {
27 	return fCStatus;
28 }
29 
30 Err*
31 Range::GetErr() const {
32 	if (fCStatus == B_OK)
33 		return NULL;
34 	else {
35 		char start_str[32];
36 		char end_str[32];
37 		sprintf(start_str, "%" B_PRId32, fStart);
38 		sprintf(end_str, "%" B_PRId32, fEnd);
39 		return new Err(std::string("Sniffer Parser Error -- Invalid range: [") + start_str + ":" + end_str + "]", -1);
40 	}
41 }
42 
43 int32
44 Range::Start() const {
45 	return fStart;
46 }
47 
48 int32
49 Range::End() const {
50 	return fEnd;
51 }
52 
53 void
54 Range::SetTo(int32 start, int32 end) {
55 		fStart = start;
56 		fEnd = end;
57 	if (start > end) {
58 		fCStatus = B_BAD_VALUE;
59 	} else {
60 		fCStatus = B_OK;
61 	}
62 }
63 
64 
65 
66