Skip to content

Commit 103fb41

Browse files
committed
Backport to Generals: Use trimEnd, truncateBy and truncateTo instead of removeLastChar.
1 parent c472df8 commit 103fb41

File tree

16 files changed

+33
-82
lines changed

16 files changed

+33
-82
lines changed

Generals/Code/GameEngine/Source/Common/CommandLine.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,7 @@ static void ConvertShortMapPathToLongMapPath(AsciiString &mapName)
9595
DEBUG_CRASH(("Invalid map name %s", mapName.str()));
9696
}
9797
// remove the .map from the end.
98-
token.removeLastChar();
99-
token.removeLastChar();
100-
token.removeLastChar();
101-
token.removeLastChar();
98+
token.truncateBy(4);
10299

103100
actualpath.concat(token);
104101
actualpath.concat('\\');

Generals/Code/GameEngine/Source/Common/GameEngine.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -897,9 +897,7 @@ void updateTGAtoDDS()
897897
}
898898

899899
// replace tga with dds
900-
filenameDDS.removeLastChar(); // a
901-
filenameDDS.removeLastChar(); // g
902-
filenameDDS.removeLastChar(); // t
900+
filenameDDS.truncateBy(3); // "tga"
903901
filenameDDS.concat("dds");
904902

905903
Bool needsToBeUpdated = FALSE;

Generals/Code/GameEngine/Source/Common/Recorder.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,7 @@ void RecorderClass::cleanUpReplayFile( void )
297297
return;
298298

299299
AsciiString debugFname = fname;
300-
debugFname.removeLastChar();
301-
debugFname.removeLastChar();
302-
debugFname.removeLastChar();
300+
debugFname.truncateBy(3);
303301
debugFname.concat("txt");
304302
UnsignedInt fileSize = 0;
305303
FILE *fp = fopen(logFileName, "rb");

Generals/Code/GameEngine/Source/Common/StatsCollector.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,7 @@ void StatsCollector::createFileName( void )
317317
const char *fname = name.reverseFind('\\');
318318
if (fname)
319319
name = fname+1;
320-
name.removeLastChar(); // p
321-
name.removeLastChar(); // a
322-
name.removeLastChar(); // m
323-
name.removeLastChar(); // .
320+
name.truncateBy(4); // ".map"
324321
m_statsFileName.clear();
325322
#if defined(RTS_DEBUG)
326323
if (TheGlobalData->m_saveStats)

Generals/Code/GameEngine/Source/Common/System/SaveGame/GameState.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,8 @@ static void findHighFileNumber( AsciiString filename, void *userData )
408408

409409
// strip off the extension at the end of the filename
410410
AsciiString nameOnly = filename;
411-
for( size_t count = 0; count < strlen( SAVE_GAME_EXTENSION ); count++ )
412-
nameOnly.removeLastChar();
413-
411+
nameOnly.truncateBy( strlen( SAVE_GAME_EXTENSION ) );
412+
414413
// convert filename (which is only numbers) to a number
415414
Int fileNumber = atoi( nameOnly.str() );
416415

Generals/Code/GameEngine/Source/Common/UserPreferences.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -802,11 +802,7 @@ Bool LadderPreferences::loadProfile( Int profileID )
802802
continue;
803803

804804
p.port = atoi( ptr + 1 );
805-
Int i=0;
806-
for (; i<strlen(ptr); ++i)
807-
{
808-
ladName.removeLastChar();
809-
}
805+
ladName.truncateBy(strlen(ptr));
810806
p.address = QuotedPrintableToAsciiString(ladName);
811807

812808
ptr = ladData.reverseFind(':');
@@ -815,10 +811,7 @@ Bool LadderPreferences::loadProfile( Int profileID )
815811
continue;
816812

817813
p.lastPlayDate = atoi( ptr + 1 );
818-
for (i=0; i<strlen(ptr); ++i)
819-
{
820-
ladData.removeLastChar();
821-
}
814+
ladData.truncateBy(strlen(ptr));
822815
p.name = QuotedPrintableToUnicodeString(ladData);
823816

824817
m_ladders[p.lastPlayDate] = p;

Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanLobbyMenu.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -422,17 +422,16 @@ void LanLobbyMenuInit( WindowLayout *layout, void *userData )
422422
//txtInput.translate(IPs.getMachineName());
423423
LANPreferences prefs;
424424
defaultName = prefs.getUserName();
425-
while (defaultName.getLength() > g_lanPlayerNameLength)
426-
defaultName.removeLastChar();
425+
defaultName.truncateTo(g_lanPlayerNameLength);
426+
427427
GadgetTextEntrySetText( textEntryPlayerName, defaultName);
428428
// Clear the text entry line
429429
GadgetTextEntrySetText(textEntryChat, UnicodeString::TheEmptyString);
430430

431431
GadgetListBoxReset(listboxPlayers);
432432
GadgetListBoxReset(listboxGames);
433433

434-
while (defaultName.getLength() > g_lanPlayerNameLength)
435-
defaultName.removeLastChar();
434+
defaultName.truncateTo(g_lanPlayerNameLength);
436435
TheLAN->RequestSetName(defaultName);
437436
TheLAN->RequestLocations();
438437

@@ -815,8 +814,7 @@ WindowMsgHandledType LanLobbyMenuSystem( GameWindow *window, UnsignedInt msg,
815814
else
816815
txtInput = UnicodeString::TheEmptyString;
817816

818-
while (txtInput.getLength() > g_lanPlayerNameLength)
819-
txtInput.removeLastChar();
817+
txtInput.truncateTo(g_lanPlayerNameLength);
820818

821819
if (!txtInput.isEmpty() && txtInput.getCharAt(txtInput.getLength()-1) == L',')
822820
txtInput.removeLastChar(); // we use , for strtok's so we can't allow them in names. :(

Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/NetworkDirectConnect.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,7 @@ void HostDirectConnectGame()
197197
prefs["UserName"] = UnicodeStringToQuotedPrintable(name);
198198
prefs.write();
199199

200-
while (name.getLength() > g_lanPlayerNameLength)
201-
name.removeLastChar();
200+
name.truncateTo(g_lanPlayerNameLength);
202201
TheLAN->RequestSetName(name);
203202
TheLAN->RequestGameCreate(localIPString, TRUE);
204203
}
@@ -241,8 +240,7 @@ void JoinDirectConnectGame()
241240
UpdateRemoteIPList();
242241
PopulateRemoteIPComboBox();
243242

244-
while (name.getLength() > g_lanPlayerNameLength)
245-
name.removeLastChar();
243+
name.truncateTo(g_lanPlayerNameLength);
246244
TheLAN->RequestSetName(name);
247245

248246
TheLAN->RequestGameJoinDirectConnect(ipaddress);
@@ -500,8 +498,7 @@ WindowMsgHandledType NetworkDirectConnectSystem( GameWindow *window, UnsignedInt
500498
prefs["UserName"] = UnicodeStringToQuotedPrintable(name);
501499
prefs.write();
502500

503-
while (name.getLength() > g_lanPlayerNameLength)
504-
name.removeLastChar();
501+
name.truncateTo(g_lanPlayerNameLength);
505502
TheLAN->RequestSetName(name);
506503

507504
buttonPushed = true;

Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/ReplayMenu.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ static Bool readReplayMapInfo(const AsciiString& filename, RecorderClass::Replay
124124
static void removeReplayExtension(UnicodeString& replayName)
125125
{
126126
const Int extensionLength = TheRecorder->getReplayExtention().getLength();
127-
for (Int k=0; k < extensionLength; ++k)
128-
replayName.removeLastChar();
127+
replayName.truncateBy(extensionLength);
129128
}
130129

131130
//-------------------------------------------------------------------------------------------------

Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLBuddyOverlay.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -550,10 +550,7 @@ void HandleBuddyResponses( void )
550550
} // end if
551551

552552
UnicodeString snippet = message.m_message;
553-
while (snippet.getLength() > 11)
554-
{
555-
snippet.removeLastChar();
556-
}
553+
snippet.truncateTo(11);
557554
UnicodeString s;
558555
s.format(TheGameText->fetch("Buddy:MessageNotification"), nick.str(), snippet.str());
559556
lastNotificationWasStatus = FALSE;

0 commit comments

Comments
 (0)