Some fixes, added the missing compare operators
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1532 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+50
-16
@@ -474,7 +474,7 @@ BString::RemoveLast(const char *str)
|
|||||||
{
|
{
|
||||||
if (str) {
|
if (str) {
|
||||||
int32 len = strlen(str);
|
int32 len = strlen(str);
|
||||||
int32 pos = _FindBefore(str, len, -1);
|
int32 pos = _FindBefore(str, Length(), -1);
|
||||||
if (pos >= 0)
|
if (pos >= 0)
|
||||||
_ShrinkAtBy(pos, len);
|
_ShrinkAtBy(pos, len);
|
||||||
}
|
}
|
||||||
@@ -510,9 +510,11 @@ BString::RemoveSet(const char *setOfCharsToRemove)
|
|||||||
BString&
|
BString&
|
||||||
BString::MoveInto(BString &into, int32 from, int32 length)
|
BString::MoveInto(BString &into, int32 from, int32 length)
|
||||||
{
|
{
|
||||||
int32 len = min(Length() - from, length);
|
int32 len = Length() - from;
|
||||||
into.SetTo(String() + from, len);
|
len = min(len, length);
|
||||||
_privateData = _ShrinkAtBy(from, len);
|
into.SetTo(String() + from, length);
|
||||||
|
if (from + length <= Length())
|
||||||
|
_privateData = _ShrinkAtBy(from, len);
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -521,73 +523,105 @@ BString::MoveInto(BString &into, int32 from, int32 length)
|
|||||||
void
|
void
|
||||||
BString::MoveInto(char *into, int32 from, int32 length)
|
BString::MoveInto(char *into, int32 from, int32 length)
|
||||||
{
|
{
|
||||||
//TODO: Test
|
if (into) {
|
||||||
if (into && (from + length <= Length())) {
|
|
||||||
memcpy(into, String() + from, length);
|
memcpy(into, String() + from, length);
|
||||||
_privateData = _ShrinkAtBy(from, length);
|
if (from + length <= Length())
|
||||||
|
_privateData = _ShrinkAtBy(from, length);
|
||||||
into[length] = '\0';
|
into[length] = '\0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*---- Compare functions ---------------------------------------------------*/
|
/*---- Compare functions ---------------------------------------------------*/
|
||||||
|
bool
|
||||||
|
BString::operator<(const char *string) const
|
||||||
|
{
|
||||||
|
return strcmp(String(), string) < 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
BString::operator<=(const char *string) const
|
||||||
|
{
|
||||||
|
return strcmp(String(), string) <= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
BString::operator==(const char *string) const
|
||||||
|
{
|
||||||
|
return strcmp(String(), string) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
BString::operator>=(const char *string) const
|
||||||
|
{
|
||||||
|
return strcmp(String(), string) >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
BString::operator>(const char *string) const
|
||||||
|
{
|
||||||
|
return strcmp(String(), string) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
// These are implemented inline in the header file
|
|
||||||
|
|
||||||
/*---- strcmp-style compare functions --------------------------------------*/
|
/*---- strcmp-style compare functions --------------------------------------*/
|
||||||
int
|
int
|
||||||
BString::Compare(const BString &string) const
|
BString::Compare(const BString &string) const
|
||||||
{
|
{
|
||||||
return strcmp(_privateData, string.String());
|
return strcmp(String(), string.String());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
BString::Compare(const char *string) const
|
BString::Compare(const char *string) const
|
||||||
{
|
{
|
||||||
return strcmp(_privateData, string);
|
return strcmp(String(), string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
BString::Compare(const BString &string, int32 n) const
|
BString::Compare(const BString &string, int32 n) const
|
||||||
{
|
{
|
||||||
return strncmp(_privateData, string.String(), n);
|
return strncmp(String(), string.String(), n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
BString::Compare(const char *string, int32 n) const
|
BString::Compare(const char *string, int32 n) const
|
||||||
{
|
{
|
||||||
return strncmp(_privateData, string, n);
|
return strncmp(String(), string, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
BString::ICompare(const BString &string) const
|
BString::ICompare(const BString &string) const
|
||||||
{
|
{
|
||||||
return strcasecmp(_privateData, string.String());
|
return strcasecmp(String(), string.String());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
BString::ICompare(const char *str) const
|
BString::ICompare(const char *str) const
|
||||||
{
|
{
|
||||||
return strcasecmp(_privateData, str);
|
return strcasecmp(String(), str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
BString::ICompare(const BString &string, int32 n) const
|
BString::ICompare(const BString &string, int32 n) const
|
||||||
{
|
{
|
||||||
return strncasecmp(_privateData, string.String(), n);
|
return strncasecmp(String(), string.String(), n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
BString::ICompare(const char *str, int32 n) const
|
BString::ICompare(const char *str, int32 n) const
|
||||||
{
|
{
|
||||||
return strncasecmp(_privateData, str, n);
|
return strncasecmp(String(), str, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user