Fixes for bugs exposed by the tests
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1488 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+19
-25
@@ -33,8 +33,8 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
// System Includes -------------------------------------------------------------
|
// System Includes -------------------------------------------------------------
|
||||||
#include <Debug.h>
|
|
||||||
#define DEBUG 1
|
#define DEBUG 1
|
||||||
|
#include <Debug.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
|
||||||
// Temporary Includes
|
// Temporary Includes
|
||||||
@@ -209,8 +209,9 @@ void
|
|||||||
BString::CopyInto(char *into, int32 fromOffset, int32 length) const
|
BString::CopyInto(char *into, int32 fromOffset, int32 length) const
|
||||||
{
|
{
|
||||||
if (into) {
|
if (into) {
|
||||||
int32 len = min(Length() - fromOffset , length);
|
int32 len = Length() - fromOffset;
|
||||||
strncpy(into, _privateData + fromOffset, len);
|
len = min(len, length);
|
||||||
|
memcpy(into, _privateData + fromOffset, len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -362,7 +363,7 @@ BString&
|
|||||||
BString::Insert(const BString &string, int32 pos)
|
BString::Insert(const BString &string, int32 pos)
|
||||||
{
|
{
|
||||||
if (&string != this)
|
if (&string != this)
|
||||||
Insert(string.String(), pos);
|
Insert(string.String(), pos); //TODO: Optimize
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -371,7 +372,7 @@ BString&
|
|||||||
BString::Insert(const BString &string, int32 length, int32 pos)
|
BString::Insert(const BString &string, int32 length, int32 pos)
|
||||||
{
|
{
|
||||||
if (&string != this)
|
if (&string != this)
|
||||||
Insert(string.String(), length, pos);
|
Insert(string.String(), length, pos); //TODO: Optimize
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -380,7 +381,7 @@ BString&
|
|||||||
BString::Insert(const BString &string, int32 fromOffset, int32 length, int32 pos)
|
BString::Insert(const BString &string, int32 fromOffset, int32 length, int32 pos)
|
||||||
{
|
{
|
||||||
if (&string != this)
|
if (&string != this)
|
||||||
Insert(string.String(), fromOffset, length, pos);
|
Insert(string.String(), fromOffset, length, pos); //TODO: Optimize
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -403,11 +404,9 @@ BString::Truncate(int32 newLength, bool lazy = true)
|
|||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
if (newLength < Length()) {
|
if (newLength < Length()) {
|
||||||
#if 0
|
|
||||||
if (lazy)
|
//TODO: Implement lazy truncate?
|
||||||
; //ToDo: Implement?
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
_privateData = _GrowBy(newLength - Length()); //Negative
|
_privateData = _GrowBy(newLength - Length()); //Negative
|
||||||
_privateData[Length()] = '\0';
|
_privateData[Length()] = '\0';
|
||||||
}
|
}
|
||||||
@@ -418,7 +417,7 @@ BString::Truncate(int32 newLength, bool lazy = true)
|
|||||||
BString&
|
BString&
|
||||||
BString::Remove(int32 from, int32 length)
|
BString::Remove(int32 from, int32 length)
|
||||||
{
|
{
|
||||||
_privateData = _ShrinkAtBy(from, length);
|
_ShrinkAtBy(from, length);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -452,7 +451,7 @@ BString::RemoveAll(const BString &string)
|
|||||||
{
|
{
|
||||||
int32 pos = B_ERROR;
|
int32 pos = B_ERROR;
|
||||||
while ((pos = _FindAfter(string.String(), 0, -1)) >= 0)
|
while ((pos = _FindAfter(string.String(), 0, -1)) >= 0)
|
||||||
_privateData = _ShrinkAtBy(pos, string.Length());
|
_ShrinkAtBy(pos, string.Length());
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -464,7 +463,7 @@ BString::RemoveFirst(const char *str)
|
|||||||
if (str) {
|
if (str) {
|
||||||
int32 pos = _FindAfter(str, 0, -1);
|
int32 pos = _FindAfter(str, 0, -1);
|
||||||
if (pos >= 0)
|
if (pos >= 0)
|
||||||
_privateData = _ShrinkAtBy(pos, strlen(str));
|
_ShrinkAtBy(pos, strlen(str));
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -477,7 +476,7 @@ BString::RemoveLast(const char *str)
|
|||||||
int32 len = strlen(str);
|
int32 len = strlen(str);
|
||||||
int32 pos = _FindBefore(str, len, -1);
|
int32 pos = _FindBefore(str, len, -1);
|
||||||
if (pos >= 0)
|
if (pos >= 0)
|
||||||
_privateData = _ShrinkAtBy(pos, len);
|
_ShrinkAtBy(pos, len);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -487,10 +486,10 @@ BString&
|
|||||||
BString::RemoveAll(const char *str)
|
BString::RemoveAll(const char *str)
|
||||||
{
|
{
|
||||||
if (str) {
|
if (str) {
|
||||||
int32 pos = B_ERROR;
|
int32 pos;
|
||||||
int32 len = strlen(str);
|
int32 len = strlen(str);
|
||||||
while ((pos = _FindAfter(str, 0, -1)) >= 0)
|
while ((pos = _FindAfter(str, 0, -1)) >= 0)
|
||||||
_privateData = _ShrinkAtBy(pos, len);
|
_ShrinkAtBy(pos, len);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -1393,10 +1392,11 @@ BString::_OpenAtBy(int32 offset, int32 length)
|
|||||||
char*
|
char*
|
||||||
BString::_ShrinkAtBy(int32 offset, int32 length)
|
BString::_ShrinkAtBy(int32 offset, int32 length)
|
||||||
{
|
{
|
||||||
ASSERT(offset + length <= Length());
|
|
||||||
|
|
||||||
int32 oldLength = Length();
|
int32 oldLength = Length();
|
||||||
|
|
||||||
|
if (offset > oldLength || offset + length > oldLength)
|
||||||
|
return _privateData;
|
||||||
|
|
||||||
memmove(_privateData + offset, _privateData + offset + length,
|
memmove(_privateData + offset, _privateData + offset + length,
|
||||||
Length() - offset - length);
|
Length() - offset - length);
|
||||||
|
|
||||||
@@ -1476,9 +1476,6 @@ BString::_FindBefore(const char *str, int32 offset, int32) const
|
|||||||
|
|
||||||
int len2 = strlen(str);
|
int len2 = strlen(str);
|
||||||
|
|
||||||
if (len2 == 0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
char *ptr1 = _privateData + offset - len2;
|
char *ptr1 = _privateData + offset - len2;
|
||||||
|
|
||||||
while (ptr1 >= _privateData) {
|
while (ptr1 >= _privateData) {
|
||||||
@@ -1502,9 +1499,6 @@ BString::_IFindBefore(const char *str, int32 offset, int32) const
|
|||||||
|
|
||||||
int len2 = strlen(str);
|
int len2 = strlen(str);
|
||||||
|
|
||||||
if (len2 == 0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
char *ptr1 = _privateData + offset - len2;
|
char *ptr1 = _privateData + offset - len2;
|
||||||
|
|
||||||
while (ptr1 >= _privateData) {
|
while (ptr1 >= _privateData) {
|
||||||
|
|||||||
Reference in New Issue
Block a user