-
Notifications
You must be signed in to change notification settings - Fork 84
[GEN][ZH] Simplify repeated calls to removeLastChar with new truncate and trim methods #1257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
f53f178
f1064ea
b82d101
b5c039a
a61b34a
d10b002
f5fc609
38ff97e
c472df8
103fb41
d976040
b3f335d
4569dff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -215,19 +215,18 @@ std::vector<AsciiString> ReplaySimulation::resolveFilenameWildcards(const std::v | |
AsciiString dir1 = TheRecorder->getReplayDir(); | ||
AsciiString dir2 = *filename; | ||
AsciiString wildcard = *filename; | ||
const char* lastSep = dir2.reverseFind('\\'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The approach here assumes that there's not a mix of separator characters in a file name. Is this a plausible possibility? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To avoid such problem you can search for both and then take the address that is larger. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this string contains userinput from commandline, so it can contain |
||
if (lastSep == NULL) | ||
{ | ||
int len = dir2.getLength(); | ||
while (len) | ||
{ | ||
char c = dir2.getCharAt(len-1); | ||
if (c == '/' || c == '\\') | ||
{ | ||
wildcard.set(wildcard.str()+dir2.getLength()); | ||
break; | ||
} | ||
dir2.removeLastChar(); | ||
len--; | ||
} | ||
lastSep = dir2.reverseFind('/'); | ||
} | ||
|
||
if (lastSep != NULL) | ||
{ | ||
// include one extra char so the separator itself gets included | ||
int lenToLastSep = lastSep - dir2.str() + 1; | ||
dir2.truncateTo(lenToLastSep); | ||
wildcard.set(wildcard.str() + lenToLastSep); | ||
} | ||
|
||
FilenameList files; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -228,6 +228,16 @@ class AsciiString | |
*/ | ||
void trim( void ); | ||
|
||
/** | ||
Remove trailing whitespace from the string. | ||
*/ | ||
void trimEnd(void); | ||
|
||
/** | ||
Remove all consecutive occurances of c from the end of the string. | ||
*/ | ||
void trimEnd(const char c); | ||
|
||
/** | ||
Make the string lowercase | ||
*/ | ||
|
@@ -240,6 +250,19 @@ class AsciiString | |
*/ | ||
void removeLastChar(); | ||
|
||
/** | ||
Remove the final charCount characters in the string. If the string is empty, | ||
do nothing. | ||
*/ | ||
void truncateBy(const Int charCount); | ||
|
||
/** | ||
Truncate the string to a length of maxLength characters, not including null termination, | ||
by removing from the end. | ||
If the string is empty or shorter than maxLength, do nothing. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can move this line right behind above sentence without new line. |
||
*/ | ||
void truncateTo(const Int maxLength); | ||
|
||
/** | ||
Analogous to sprintf() -- this formats a string according to the | ||
given sprintf-style format string (and the variable argument list) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file just has whitespace changes now.