* Added desperately missing Trim() method.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32035 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
8bf23e3caa
commit
e90b90daf6
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright 2001-2009, Haiku Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
* Copyright 2001-2009, Haiku Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef __BSTRING__
|
||||
#define __BSTRING__
|
||||
|
||||
@ -219,13 +219,17 @@ public:
|
||||
|
||||
// Escaping and De-escaping
|
||||
BString& CharacterEscape(const char* original,
|
||||
const char* setOfCharsToEscape, char escapeWith);
|
||||
const char* setOfCharsToEscape,
|
||||
char escapeWith);
|
||||
BString& CharacterEscape(const char* setOfCharsToEscape,
|
||||
char escapeWith);
|
||||
BString& CharacterDeescape(const char* original,
|
||||
char escapeChar);
|
||||
BString& CharacterDeescape(char escapeChar);
|
||||
|
||||
// Trimming
|
||||
BString& Trim();
|
||||
|
||||
// Insert
|
||||
BString& operator<<(const char* string);
|
||||
BString& operator<<(const BString& string);
|
||||
|
@ -10,6 +10,7 @@
|
||||
* Julun <host.haiku@gmx.de>
|
||||
*/
|
||||
|
||||
|
||||
/*! String class supporting common string operations. */
|
||||
|
||||
|
||||
@ -1613,6 +1614,42 @@ BString::CharacterDeescape(char escapeChar)
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark - Trimming
|
||||
|
||||
|
||||
BString&
|
||||
BString::Trim()
|
||||
{
|
||||
const char* string = String();
|
||||
|
||||
int32 startCount = 0;
|
||||
while (isspace(string[startCount])) {
|
||||
startCount++;
|
||||
}
|
||||
|
||||
int32 endCount = 0;
|
||||
while (isspace(string[Length() - endCount - 1])) {
|
||||
endCount++;
|
||||
}
|
||||
|
||||
if (startCount == 0 && endCount == 0)
|
||||
return *this;
|
||||
|
||||
// We actually need to trim
|
||||
|
||||
size_t length = Length() - startCount - endCount;
|
||||
if (startCount == 0) {
|
||||
_MakeWritable(length, true);
|
||||
} else if (_MakeWritable() == B_OK) {
|
||||
memmove(fPrivateData, fPrivateData + startCount, length);
|
||||
fPrivateData[length] = '\0';
|
||||
_SetLength(length);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark - Insert
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user