More BString functions. Constructors, CountChars() and operators "=" and "+=" are tested with cppunit and work fine.
Added string_helper.cpp and .h to compile String.cpp correctly. Those will be removed as soon as we have our working libc. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1313 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
3589bfc66b
commit
53fd1e70a4
|
@ -36,6 +36,8 @@
|
|||
// System Includes -------------------------------------------------------------
|
||||
#include <String.h>
|
||||
|
||||
// Temporary Includes
|
||||
#include "string_helper.h"
|
||||
|
||||
/*---- Construction --------------------------------------------------------*/
|
||||
BString::BString()
|
||||
|
@ -628,6 +630,36 @@ BString::FindFirst(char c, int32 fromOffset) const
|
|||
}
|
||||
|
||||
|
||||
int32
|
||||
BString::FindLast(const BString &string) const
|
||||
{
|
||||
return _FindBefore(string.String(), Length(), -1);
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
BString::FindLast(const char *str) const
|
||||
{
|
||||
return _FindBefore(str, Length(), -1);
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
BString::FindLast(const BString &string, int32 beforeOffset) const
|
||||
{
|
||||
return _FindBefore(string.String(), beforeOffset, -1);
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
BString::FindLast(char c) const
|
||||
{
|
||||
char tmp[2] = { c, '\0' };
|
||||
|
||||
return _FindBefore(tmp, Length(), -1);
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
BString::IFindFirst(const BString &string) const
|
||||
{
|
||||
|
@ -656,6 +688,34 @@ BString::IFindFirst(const char *string, int32 fromOffset) const
|
|||
}
|
||||
|
||||
|
||||
int32
|
||||
BString::IFindLast(const BString &string) const
|
||||
{
|
||||
return _IFindBefore(string.String(), Length(), -1);
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
BString::IFindLast(const char *string) const
|
||||
{
|
||||
return _IFindBefore(string, Length(), -1);
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
BString::IFindLast(const BString &string, int32 beforeOffset) const
|
||||
{
|
||||
return _IFindBefore(string.String(), beforeOffset, -1);
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
BString::IFindLast(const char *string, int32 beforeOffset) const
|
||||
{
|
||||
return _IFindBefore(string, beforeOffset, -1);
|
||||
}
|
||||
|
||||
|
||||
/*---- Replacing -----------------------------------------------------------*/
|
||||
BString&
|
||||
BString::ReplaceFirst(char replaceThis, char withThis)
|
||||
|
@ -1163,23 +1223,53 @@ BString::_ShortFindAfter(const char *str, int32 ) const
|
|||
|
||||
|
||||
int32
|
||||
BString::_FindBefore(const char *str, int32 offset, int32 ) const
|
||||
BString::_FindBefore(const char *str, int32 offset, int32) const
|
||||
{
|
||||
assert(str != NULL);
|
||||
if (!str)
|
||||
return 0;
|
||||
|
||||
if (offset <= 0)
|
||||
return B_ERROR;
|
||||
|
||||
//TODO: Implement
|
||||
int len2 = strlen(str);
|
||||
|
||||
if (len2 == 0)
|
||||
return 0;
|
||||
|
||||
char *ptr1 = _privateData + offset - len2;
|
||||
|
||||
while (ptr1 >= _privateData) {
|
||||
if (!memcmp(ptr1, str, len2))
|
||||
return ptr1 - _privateData;
|
||||
ptr1--;
|
||||
}
|
||||
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
BString::_IFindBefore(const char *str, int32 , int32 ) const
|
||||
BString::_IFindBefore(const char *str, int32 offset, int32) const
|
||||
{
|
||||
assert(str != NULL);
|
||||
//TODO: Implement
|
||||
if (!str)
|
||||
return 0;
|
||||
|
||||
if (offset <= 0)
|
||||
return B_ERROR;
|
||||
|
||||
int len2 = strlen(str);
|
||||
|
||||
if (len2 == 0)
|
||||
return 0;
|
||||
|
||||
char *ptr1 = _privateData + offset - len2;
|
||||
|
||||
while (ptr1 >= _privateData) {
|
||||
if (!strncasecmp(ptr1, str, len2))
|
||||
return ptr1 - _privateData;
|
||||
ptr1--;
|
||||
}
|
||||
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
|
@ -1193,6 +1283,7 @@ BString::_SetLength(int32 length)
|
|||
|
||||
#if DEBUG
|
||||
// TODO: Implement?
|
||||
// AFAIK, these are not implemented in BeOS R5
|
||||
BString::_SetUsingAsCString(bool) {}
|
||||
BString::_AssertNotUsingAsCString() {}
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
//Those functions are here just to compile BString.
|
||||
//They will be removed as soon as our libc compiles.
|
||||
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
char *
|
||||
strcasestr(const char *s, const char *find)
|
||||
{
|
||||
char c, sc;
|
||||
size_t len;
|
||||
|
||||
if ((c = *find++) != 0) {
|
||||
c = tolower((unsigned char)c);
|
||||
len = strlen(find);
|
||||
do {
|
||||
do {
|
||||
if ((sc = *s++) == 0)
|
||||
return NULL;
|
||||
} while ((char)tolower((unsigned char)sc) != c);
|
||||
} while (strncasecmp(s, find, len) != 0);
|
||||
s--;
|
||||
}
|
||||
return (char *)s;
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
//Those functions are here just to compile BString.
|
||||
//They will be removed as soon as our libc compiles.
|
||||
|
||||
#ifndef __stringhelper_h
|
||||
#define __stringhelper_h
|
||||
|
||||
extern char *strcasestr(const char *s, const char *find);
|
||||
|
||||
#endif //__stringhelper_h
|
|
@ -7,4 +7,5 @@ SUPPORT_KIT_SOURCE =
|
|||
Locker.cpp
|
||||
StopWatch.cpp
|
||||
#String.cpp
|
||||
#string_helper.cpp
|
||||
;
|
||||
|
|
Loading…
Reference in New Issue