More functions, more bug fixes.
Just Escaping/Deescaping and some Replacing functions missing git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1336 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+76
-13
@@ -188,10 +188,8 @@ BString::Adopt(BString &from, int32 length)
|
|||||||
BString&
|
BString&
|
||||||
BString::SetTo(char c, int32 count)
|
BString::SetTo(char c, int32 count)
|
||||||
{
|
{
|
||||||
char *tmp = (char*)malloc(count);
|
_GrowBy(count - Length());
|
||||||
memset(tmp, c, count);
|
memset(_privateData, c, count);
|
||||||
_DoAssign(tmp, count);
|
|
||||||
free(tmp);
|
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -731,7 +729,7 @@ BString&
|
|||||||
BString::ReplaceLast(char replaceThis, char withThis)
|
BString::ReplaceLast(char replaceThis, char withThis)
|
||||||
{
|
{
|
||||||
int32 pos = FindLast(replaceThis, Length());
|
int32 pos = FindLast(replaceThis, Length());
|
||||||
if (pos <= Length())
|
if (pos >= 0)
|
||||||
_privateData[pos] = withThis;
|
_privateData[pos] = withThis;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -769,7 +767,21 @@ BString::Replace(char replaceThis, char withThis, int32 maxReplaceCount, int32 f
|
|||||||
BString&
|
BString&
|
||||||
BString::ReplaceFirst(const char *replaceThis, const char *withThis)
|
BString::ReplaceFirst(const char *replaceThis, const char *withThis)
|
||||||
{
|
{
|
||||||
//TODO: Implement
|
if (replaceThis == NULL)
|
||||||
|
return *this;
|
||||||
|
|
||||||
|
int32 len = (withThis ? strlen(withThis) : 0);
|
||||||
|
int32 difference = len - strlen(replaceThis);
|
||||||
|
|
||||||
|
int32 pos = _FindAfter(replaceThis, 0, -1);
|
||||||
|
if (pos >= 0) {
|
||||||
|
if (difference > 0)
|
||||||
|
_OpenAtBy(pos, difference);
|
||||||
|
else if (difference < 0)
|
||||||
|
_ShrinkAtBy(pos, -difference);
|
||||||
|
memcpy(_privateData + pos, withThis, len);
|
||||||
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -777,7 +789,21 @@ BString::ReplaceFirst(const char *replaceThis, const char *withThis)
|
|||||||
BString&
|
BString&
|
||||||
BString::ReplaceLast(const char *replaceThis, const char *withThis)
|
BString::ReplaceLast(const char *replaceThis, const char *withThis)
|
||||||
{
|
{
|
||||||
//TODO: Implement
|
if (replaceThis == NULL)
|
||||||
|
return *this;
|
||||||
|
|
||||||
|
int32 len = (withThis ? strlen(withThis) : 0);
|
||||||
|
int32 difference = len - strlen(replaceThis);
|
||||||
|
|
||||||
|
int32 pos = _FindBefore(replaceThis, Length(), -1);
|
||||||
|
if (pos >= 0) {
|
||||||
|
if (difference > 0)
|
||||||
|
_OpenAtBy(pos, difference);
|
||||||
|
else if (difference < 0)
|
||||||
|
_ShrinkAtBy(pos, -difference);
|
||||||
|
memcpy(_privateData + pos, withThis, len);
|
||||||
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -801,7 +827,10 @@ BString::Replace(const char *replaceThis, const char *withThis, int32 maxReplace
|
|||||||
BString&
|
BString&
|
||||||
BString::IReplaceFirst(char replaceThis, char withThis)
|
BString::IReplaceFirst(char replaceThis, char withThis)
|
||||||
{
|
{
|
||||||
//TODO: Implement
|
int32 pos = IFindFirst(replaceThis, 0);
|
||||||
|
if (pos >= 0)
|
||||||
|
_privateData[pos] = withThis;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -809,7 +838,10 @@ BString::IReplaceFirst(char replaceThis, char withThis)
|
|||||||
BString&
|
BString&
|
||||||
BString::IReplaceLast(char replaceThis, char withThis)
|
BString::IReplaceLast(char replaceThis, char withThis)
|
||||||
{
|
{
|
||||||
//TODO: Implement
|
int32 pos = IFindLast(replaceThis, 0);
|
||||||
|
if (pos >= 0)
|
||||||
|
_privateData[pos] = withThis;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -833,7 +865,21 @@ BString::IReplace(char replaceThis, char withThis, int32 maxReplaceCount, int32
|
|||||||
BString&
|
BString&
|
||||||
BString::IReplaceFirst(const char *replaceThis, const char *withThis)
|
BString::IReplaceFirst(const char *replaceThis, const char *withThis)
|
||||||
{
|
{
|
||||||
//TODO: Implement
|
if (replaceThis == NULL)
|
||||||
|
return *this;
|
||||||
|
|
||||||
|
int32 len = (withThis ? strlen(withThis) : 0);
|
||||||
|
int32 difference = len - strlen(replaceThis);
|
||||||
|
|
||||||
|
int32 pos = _IFindAfter(replaceThis, 0, -1);
|
||||||
|
if (pos >= 0) {
|
||||||
|
if (difference > 0)
|
||||||
|
_OpenAtBy(pos, difference);
|
||||||
|
else if (difference < 0)
|
||||||
|
_ShrinkAtBy(pos, -difference);
|
||||||
|
memcpy(_privateData + pos, withThis, len);
|
||||||
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -841,7 +887,21 @@ BString::IReplaceFirst(const char *replaceThis, const char *withThis)
|
|||||||
BString&
|
BString&
|
||||||
BString::IReplaceLast(const char *replaceThis, const char *withThis)
|
BString::IReplaceLast(const char *replaceThis, const char *withThis)
|
||||||
{
|
{
|
||||||
//TODO: Implement
|
if (replaceThis == NULL)
|
||||||
|
return *this;
|
||||||
|
|
||||||
|
int32 len = (withThis ? strlen(withThis) : 0);
|
||||||
|
int32 difference = len - strlen(replaceThis);
|
||||||
|
|
||||||
|
int32 pos = _FindBefore(replaceThis, Length(), -1);
|
||||||
|
if (pos >= 0) {
|
||||||
|
if (difference > 0)
|
||||||
|
_OpenAtBy(pos, difference);
|
||||||
|
else if (difference < 0)
|
||||||
|
_ShrinkAtBy(pos, -difference);
|
||||||
|
memcpy(_privateData + pos, withThis, len);
|
||||||
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1183,7 +1243,8 @@ BString::_DoPrepend(const char *str, int32 count)
|
|||||||
int32
|
int32
|
||||||
BString::_FindAfter(const char *str, int32 offset, int32) const
|
BString::_FindAfter(const char *str, int32 offset, int32) const
|
||||||
{
|
{
|
||||||
assert(str != NULL);
|
if (!str)
|
||||||
|
return 0;
|
||||||
|
|
||||||
if (offset > Length())
|
if (offset > Length())
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
@@ -1200,7 +1261,9 @@ BString::_FindAfter(const char *str, int32 offset, int32) const
|
|||||||
int32
|
int32
|
||||||
BString::_IFindAfter(const char *str, int32 offset, int32 ) const
|
BString::_IFindAfter(const char *str, int32 offset, int32 ) const
|
||||||
{
|
{
|
||||||
assert(str != NULL);
|
if (!str)
|
||||||
|
return 0;
|
||||||
|
|
||||||
if (offset > Length())
|
if (offset > Length())
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user