* ArgumentList now inherits from BObjectList instead of aggregating it.
* Fixed BString::ICompare() checks. * Minor other improvements. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@43144 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -12,7 +12,7 @@ namespace IMAP {
|
|||||||
|
|
||||||
ArgumentList::ArgumentList()
|
ArgumentList::ArgumentList()
|
||||||
:
|
:
|
||||||
fArguments(5, true)
|
BObjectList<Argument>(5, true)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -22,12 +22,26 @@ ArgumentList::~ArgumentList()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
ArgumentList::Contains(const char* string) const
|
||||||
|
{
|
||||||
|
for (int32 i = 0; i < CountItems(); i++) {
|
||||||
|
if (StringArgument* argument
|
||||||
|
= dynamic_cast<StringArgument*>(ItemAt(i))) {
|
||||||
|
if (argument->String().ICompare(string) == 0)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
BString
|
BString
|
||||||
ArgumentList::StringAt(int32 index) const
|
ArgumentList::StringAt(int32 index) const
|
||||||
{
|
{
|
||||||
if (index >= 0 && index < fArguments.CountItems()) {
|
if (index >= 0 && index < CountItems()) {
|
||||||
if (StringArgument* argument = dynamic_cast<StringArgument*>(
|
if (StringArgument* argument
|
||||||
fArguments.ItemAt(index)))
|
= dynamic_cast<StringArgument*>(ItemAt(index)))
|
||||||
return argument->String();
|
return argument->String();
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
@@ -37,8 +51,8 @@ ArgumentList::StringAt(int32 index) const
|
|||||||
bool
|
bool
|
||||||
ArgumentList::IsStringAt(int32 index) const
|
ArgumentList::IsStringAt(int32 index) const
|
||||||
{
|
{
|
||||||
if (index >= 0 && index < fArguments.CountItems()) {
|
if (index >= 0 && index < CountItems()) {
|
||||||
if (dynamic_cast<StringArgument*>(fArguments.ItemAt(index)) != NULL)
|
if (dynamic_cast<StringArgument*>(ItemAt(index)) != NULL)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -48,20 +62,19 @@ ArgumentList::IsStringAt(int32 index) const
|
|||||||
bool
|
bool
|
||||||
ArgumentList::EqualsAt(int32 index, const char* string) const
|
ArgumentList::EqualsAt(int32 index, const char* string) const
|
||||||
{
|
{
|
||||||
return StringAt(index).ICompare(string);
|
return StringAt(index).ICompare(string) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const ArgumentList&
|
ArgumentList&
|
||||||
ArgumentList::ListAt(int32 index) const
|
ArgumentList::ListAt(int32 index) const
|
||||||
{
|
{
|
||||||
if (index >= 0 && index < fArguments.CountItems()) {
|
if (index >= 0 && index < CountItems()) {
|
||||||
if (ListArgument* argument = dynamic_cast<ListArgument*>(
|
if (ListArgument* argument = dynamic_cast<ListArgument*>(ItemAt(index)))
|
||||||
fArguments.ItemAt(index)))
|
|
||||||
return argument->List();
|
return argument->List();
|
||||||
}
|
}
|
||||||
|
|
||||||
static ArgumentList empty(0, true);
|
static ArgumentList empty;
|
||||||
return empty;
|
return empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,9 +82,8 @@ ArgumentList::ListAt(int32 index) const
|
|||||||
bool
|
bool
|
||||||
ArgumentList::IsListAt(int32 index) const
|
ArgumentList::IsListAt(int32 index) const
|
||||||
{
|
{
|
||||||
if (index >= 0 && index < fArguments.CountItems()) {
|
if (index >= 0 && index < CountItems()) {
|
||||||
if (ListArgument* argument = dynamic_cast<ListArgument*>(
|
if (ListArgument* argument = dynamic_cast<ListArgument*>(ItemAt(index)))
|
||||||
fArguments.ItemAt(index)))
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -81,9 +93,8 @@ ArgumentList::IsListAt(int32 index) const
|
|||||||
bool
|
bool
|
||||||
ArgumentList::IsListAt(int32 index, char kind) const
|
ArgumentList::IsListAt(int32 index, char kind) const
|
||||||
{
|
{
|
||||||
if (index >= 0 && index < fArguments.CountItems()) {
|
if (index >= 0 && index < CountItems()) {
|
||||||
if (ListArgument* argument = dynamic_cast<ListArgument*>(
|
if (ListArgument* argument = dynamic_cast<ListArgument*>(ItemAt(index)))
|
||||||
fArguments.ItemAt(index)))
|
|
||||||
return argument->Kind() == kind;
|
return argument->Kind() == kind;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -109,6 +120,20 @@ ArgumentList::IsIntegerAt(int32 index) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BString
|
||||||
|
ArgumentList::ToString() const
|
||||||
|
{
|
||||||
|
BString string;
|
||||||
|
|
||||||
|
for (int32 i = 0; i < CountItems(); i++) {
|
||||||
|
if (i > 0)
|
||||||
|
string += ", ";
|
||||||
|
string += ItemAt(i)->ToString();
|
||||||
|
}
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
@@ -122,40 +147,12 @@ Argument::~Argument()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*static*/ BString
|
|
||||||
Argument::ToString(const ArgumentList& arguments)
|
|
||||||
{
|
|
||||||
BString string;
|
|
||||||
|
|
||||||
for (int32 i = 0; i < arguments.CountItems(); i++) {
|
|
||||||
if (i > 0)
|
|
||||||
string += ", ";
|
|
||||||
string += arguments.ItemAt(i)->ToString();
|
|
||||||
}
|
|
||||||
return string;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool
|
|
||||||
Argument::Contains(const ArgumentList& arguments, const char* string) const
|
|
||||||
{
|
|
||||||
for (int32 i = 0; i < arguments.CountItems(); i++) {
|
|
||||||
if (StringArgument* argument = dynamic_cast<StringArgument*>(
|
|
||||||
arguments.ItemAt(i))) {
|
|
||||||
if (argument->String().ICompare(string))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
ListArgument::ListArgument()
|
ListArgument::ListArgument(char kind)
|
||||||
:
|
:
|
||||||
fList(5, true)
|
fKind(kind)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,9 +160,9 @@ ListArgument::ListArgument()
|
|||||||
BString
|
BString
|
||||||
ListArgument::ToString() const
|
ListArgument::ToString() const
|
||||||
{
|
{
|
||||||
BString string("(");
|
BString string(fKind == '[' ? "[" : "(");
|
||||||
string += Argument::ToString(response.Arguments());
|
string += fList.ToString();
|
||||||
string += ")";
|
string += fKind == '[' ? "]" : ")";
|
||||||
|
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
@@ -181,6 +178,13 @@ StringArgument::StringArgument(const BString& string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
StringArgument::StringArgument(const StringArgument& other)
|
||||||
|
:
|
||||||
|
fString(other.fString)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
BString
|
BString
|
||||||
StringArgument::ToString() const
|
StringArgument::ToString() const
|
||||||
{
|
{
|
||||||
@@ -227,8 +231,7 @@ ExpectedParseException::ExpectedParseException(char expected, char instead)
|
|||||||
Response::Response()
|
Response::Response()
|
||||||
:
|
:
|
||||||
fTag(0),
|
fTag(0),
|
||||||
fArguments(5, true),
|
fContinuation(false)
|
||||||
fContinued(false)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,7 +246,7 @@ Response::SetTo(const char* line) throw(ParseException)
|
|||||||
{
|
{
|
||||||
MakeEmpty();
|
MakeEmpty();
|
||||||
fTag = 0;
|
fTag = 0;
|
||||||
fContinued = false;
|
fContinuation = false;
|
||||||
|
|
||||||
if (line[0] == '*') {
|
if (line[0] == '*') {
|
||||||
// Untagged response
|
// Untagged response
|
||||||
@@ -252,7 +255,7 @@ Response::SetTo(const char* line) throw(ParseException)
|
|||||||
} else if (line[0] == '+') {
|
} else if (line[0] == '+') {
|
||||||
// Continuation
|
// Continuation
|
||||||
Consume(line, '+');
|
Consume(line, '+');
|
||||||
fContinued = true;
|
fContinuation = true;
|
||||||
} else {
|
} else {
|
||||||
// Tagged response
|
// Tagged response
|
||||||
Consume(line, 'A');
|
Consume(line, 'A');
|
||||||
@@ -262,7 +265,7 @@ Response::SetTo(const char* line) throw(ParseException)
|
|||||||
Consume(line, ' ');
|
Consume(line, ' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
char c = ParseLine(this, line);
|
char c = ParseLine(*this, line);
|
||||||
if (c != '\0')
|
if (c != '\0')
|
||||||
throw ExpectedParseException('\0', c);
|
throw ExpectedParseException('\0', c);
|
||||||
}
|
}
|
||||||
@@ -271,7 +274,7 @@ Response::SetTo(const char* line) throw(ParseException)
|
|||||||
bool
|
bool
|
||||||
Response::IsCommand(const char* command) const
|
Response::IsCommand(const char* command) const
|
||||||
{
|
{
|
||||||
return IsStringAt(0, command);
|
return IsUntagged() && EqualsAt(0, command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -18,37 +18,25 @@ namespace IMAP {
|
|||||||
class Argument;
|
class Argument;
|
||||||
|
|
||||||
|
|
||||||
class ArgumentList {
|
class ArgumentList : public BObjectList<Argument> {
|
||||||
public:
|
public:
|
||||||
ArgumentList();
|
ArgumentList();
|
||||||
~ArgumentList();
|
~ArgumentList();
|
||||||
|
|
||||||
size_t CountItems()
|
|
||||||
{ return (size_t)fArguments.CountItems(); }
|
|
||||||
Argument& ItemAt(size_t index) const
|
|
||||||
{ return *fArguments.ItemAt(index); }
|
|
||||||
void MakeEmpty()
|
|
||||||
{ fArguments.MakeEmpty(); }
|
|
||||||
bool AddItem(Argument* argument)
|
|
||||||
{ return fArguments.AddItem(argument); }
|
|
||||||
Argument* RemoveItem(size_t index)
|
|
||||||
{ return fArguments.RemoveItemAt(index); }
|
|
||||||
|
|
||||||
BString ToString() const;
|
|
||||||
bool Contains(const char* string) const;
|
bool Contains(const char* string) const;
|
||||||
|
|
||||||
BString StringAt(int32 index) const;
|
BString StringAt(int32 index) const;
|
||||||
bool IsStringAt(int32 index) const;
|
bool IsStringAt(int32 index) const;
|
||||||
bool EqualsAt(int32 index,
|
bool EqualsAt(int32 index,
|
||||||
const char* string) const;
|
const char* string) const;
|
||||||
const ArgumentList& ListAt(int32 index) const;
|
|
||||||
|
ArgumentList& ListAt(int32 index) const;
|
||||||
bool IsListAt(int32 index) const;
|
bool IsListAt(int32 index) const;
|
||||||
bool IsListAt(int32 index, char kind) const;
|
bool IsListAt(int32 index, char kind) const;
|
||||||
|
|
||||||
int32 IntegerAt(int32 index) const;
|
int32 IntegerAt(int32 index) const;
|
||||||
bool IsIntegerAt(int32 index) const;
|
bool IsIntegerAt(int32 index) const;
|
||||||
|
|
||||||
private:
|
BString ToString() const;
|
||||||
BObjectList<Argument> fArguments;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -79,6 +67,7 @@ private:
|
|||||||
class StringArgument : public Argument {
|
class StringArgument : public Argument {
|
||||||
public:
|
public:
|
||||||
StringArgument(const BString& string);
|
StringArgument(const BString& string);
|
||||||
|
StringArgument(const StringArgument& other);
|
||||||
|
|
||||||
const BString& String() { return fString; }
|
const BString& String() { return fString; }
|
||||||
|
|
||||||
@@ -122,7 +111,7 @@ public:
|
|||||||
bool IsUntagged() const { return fTag == 0; }
|
bool IsUntagged() const { return fTag == 0; }
|
||||||
int32 Tag() const { return fTag; }
|
int32 Tag() const { return fTag; }
|
||||||
bool IsCommand(const char* command) const;
|
bool IsCommand(const char* command) const;
|
||||||
bool IsContinued() const { return fContinued; }
|
bool IsContinuation() const { return fContinuation; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
char ParseLine(ArgumentList& arguments,
|
char ParseLine(ArgumentList& arguments,
|
||||||
@@ -140,7 +129,7 @@ protected:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
int32 fTag;
|
int32 fTag;
|
||||||
bool fContinued;
|
bool fContinuation;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user