BString: Add StartsWith() and EndsWith() methods
This commit is contained in:
@@ -221,6 +221,14 @@ public:
|
|||||||
int32 IFindLast(const char* string,
|
int32 IFindLast(const char* string,
|
||||||
int32 beforeOffset) const;
|
int32 beforeOffset) const;
|
||||||
|
|
||||||
|
bool StartsWith(const BString& string) const;
|
||||||
|
bool StartsWith(const char* string) const;
|
||||||
|
bool StartsWith(const char* string, int32 length) const;
|
||||||
|
|
||||||
|
bool EndsWith(const BString& string) const;
|
||||||
|
bool EndsWith(const char* string) const;
|
||||||
|
bool EndsWith(const char* string, int32 length) const;
|
||||||
|
|
||||||
// Replacing
|
// Replacing
|
||||||
BString& ReplaceFirst(char replaceThis, char withThis);
|
BString& ReplaceFirst(char replaceThis, char withThis);
|
||||||
BString& ReplaceLast(char replaceThis, char withThis);
|
BString& ReplaceLast(char replaceThis, char withThis);
|
||||||
|
|||||||
@@ -1362,6 +1362,55 @@ BString::IFindLast(const char* string, int32 beforeOffset) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
BString::StartsWith(const BString& string) const
|
||||||
|
{
|
||||||
|
return StartsWith(string.String(), string.Length());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
BString::StartsWith(const char* string) const
|
||||||
|
{
|
||||||
|
return StartsWith(string, strlen(string));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
BString::StartsWith(const char* string, int32 length) const
|
||||||
|
{
|
||||||
|
if (length > Length())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return memcmp(String(), string, length) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
BString::EndsWith(const BString& string) const
|
||||||
|
{
|
||||||
|
return EndsWith(string.String(), string.Length());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
BString::EndsWith(const char* string) const
|
||||||
|
{
|
||||||
|
return EndsWith(string, strlen(string));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
BString::EndsWith(const char* string, int32 length) const
|
||||||
|
{
|
||||||
|
int32 offset = Length() - length;
|
||||||
|
if (offset < 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return memcmp(String() + offset, string, length) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark - Replacing
|
// #pragma mark - Replacing
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user