Skip to content

Commit 3ddb860

Browse files
committed
Foundation Classes - AsciiString RemoveAll do not trunk the string #136
Updated RemoveAll to trunk the string and reuse single method for case sensitive and not sensitive
1 parent f180697 commit 3ddb860

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

src/TCollection/TCollection_AsciiString.cxx

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -924,32 +924,31 @@ Standard_OStream& operator << (Standard_OStream& astream,
924924
// ----------------------------------------------------------------------------
925925
void TCollection_AsciiString::RemoveAll(const Standard_Character what,
926926
const Standard_Boolean CaseSensitive)
927-
{
928-
if (mylength == 0) return;
929-
int c = 0;
930-
if (CaseSensitive) {
931-
for (int i=0; i < mylength; i++)
932-
if (mystring[i] != what) mystring[c++] = mystring[i];
927+
{
928+
if (mylength == 0)
929+
{
930+
return;
933931
}
934-
else {
935-
Standard_Character upperwhat = ::UpperCase(what);
936-
for (int i=0; i < mylength; i++) {
937-
if (::UpperCase(mystring[i]) != upperwhat) mystring[c++] = mystring[i];
932+
const Standard_Character aTargetChar = CaseSensitive ? what : ::UpperCase(what);
933+
int aNewLength = 0;
934+
for (int i = 0; i < mylength; ++i)
935+
{
936+
const Standard_Character aCurrentChar = CaseSensitive ? mystring[i] : ::UpperCase(mystring[i]);
937+
if (aCurrentChar != aTargetChar)
938+
{
939+
mystring[aNewLength++] = mystring[i];
938940
}
939941
}
940-
mylength = c;
942+
mylength = aNewLength;
943+
mystring[mylength] = '\0';
941944
}
942945

943946
// ----------------------------------------------------------------------------
944947
// RemoveAll
945948
// ----------------------------------------------------------------------------
946949
void TCollection_AsciiString::RemoveAll(const Standard_Character what)
947950
{
948-
if (mylength == 0) return;
949-
int c = 0;
950-
for (int i=0; i < mylength; i++)
951-
if (mystring[i] != what) mystring[c++] = mystring[i];
952-
mylength = c;
951+
RemoveAll(what, Standard_True);
953952
}
954953

955954
// ----------------------------------------------------------------------------

0 commit comments

Comments
 (0)