chore(string): Implement removeExtension() function for string classes and add find/reverseFind to UnicodeString#2635
Conversation
|
| Filename | Overview |
|---|---|
| Core/Libraries/Include/Lib/PathUtil.h | New utility header with inline getExtension overloads for char* and wchar_t*; functions are inline (ODR-safe), use maxPtr for safe null-safe separator comparison, and correctly handle paths with dots in directory components. |
| Core/Libraries/Include/Lib/BaseType.h | Adds maxPtr/minPtr pointer templates with nullptr-safe semantics; used to replace unsafe relational comparison between a null and a non-null pointer that was flagged in the prior review. |
| Core/GameEngine/Source/Common/System/FileSystem.cpp | Implements FileSystem::removeExtension for both string types using correct pointer-difference arithmetic (ext - path.str()) rather than the sizeof bug present in the earlier draft. |
| Core/GameEngine/Include/Common/FileSystem.h | Adds static bool removeExtension declarations for AsciiString and UnicodeString overloads; change log comment uses a 2026 date consistent with the team's rule. |
| Core/GameEngine/Include/Common/UnicodeString.h | Adds find/reverseFind inline methods wrapping wcschr/wcsrchr, giving UnicodeString parity with AsciiString; implementation is straightforward and correct. |
| Generals/Code/GameEngine/Source/Common/System/SaveGame/GameState.cpp | Removes the static removeExtension helper that was unused dead code; no functional changes to live code paths. |
| GeneralsMD/Code/GameEngine/Source/Common/System/SaveGame/GameState.cpp | Same dead-code removal as the Generals variant; no functional changes. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["FileSystem::removeExtension(path)"] --> B["getExtension(path.str())"]
B --> C{"strrchr for '.'"}
C -- "no dot found" --> D["return nullptr"]
C -- "dot found" --> E["maxPtr(strrchr '/' , strrchr '\\')"]
E --> F{"lastSeparator &&\nlastDot < lastSeparator?"}
F -- "yes (dot in dir name)" --> D
F -- "no (dot in filename)" --> G["return pointer to dot"]
G --> H["path.truncateTo(ext - path.str())"]
H --> I["return true"]
D --> J["return false"]
Reviews (19): Last reviewed commit: "chore(filesystem): Implement getExtensio..." | Re-trigger Greptile
|
will fix this tomorrow |
663220e to
9e42c19
Compare
|
Fixed before bed in the end, should be okay now and working as expected. |
9e42c19 to
385ccbb
Compare
|
updated based on feedback. |
385ccbb to
e8394f0
Compare
|
Updated the implementation to take the dots position into account by checking if it appears before path seperators. |
e8394f0 to
9cfecdf
Compare
|
Appeasing the AI overMunkee |
9cfecdf to
90d8760
Compare
|
Helps when i do it properly. |
90d8760 to
82c96c5
Compare
|
This should be good now, speeling mistake corrected and pull number added to commits. |
82c96c5 to
a1f328f
Compare
a1f328f to
e388c1c
Compare
|
Updated to move the functionality into the file system |
e388c1c to
c9d9d86
Compare
c9d9d86 to
af0605e
Compare
|
Just a rebase with Main since BaseType is updated on main |
af0605e to
76e0c2c
Compare
|
Edited based on majority of recent feedback, just waiting on discussion on two points. |
76e0c2c to
873e16b
Compare
873e16b to
7813d5d
Compare
7813d5d to
eea4264
Compare
|
Updated based on feedback and implemented pointer comparison template functions. |
eea4264 to
6e205b1
Compare
xezon
left a comment
There was a problem hiding this comment.
Looks correct.
Maybe there can be a follow up in the future where former extension searches are replaced with the new functions.
6e205b1 to
3f2c744
Compare
|
Greptile says:
|
3f2c744 to
0c60fdb
Compare
Ah missed that when copying the header. |
|
Greptile has another comment Comment:
template <typename PTR>
inline PTR maxPtr(PTR x, PTR y) noexcept
{
static_assert(std::is_pointer<PTR>::value, "maxPtr is for pointer types only");
// ...
}Same for |
Had to double check if that would work with VC6 since |
0c60fdb to
0d6d58d
Compare
|
updated with static asserts. |
xezon
left a comment
There was a problem hiding this comment.
The commits are titled as "feat" which implies that a new feature was added. But isn't this more a chore than feature? Because user facing nothing changes.
| return static_cast<NUM>(y & ~(y >> 1)); | ||
| } | ||
|
|
||
| // TheSuperHackers @info The max and min pointer template functions should only ever be used with pointers! |
There was a problem hiding this comment.
This comment can now be removed because the static assert already documents and enforces it sufficiently.
I didn't think it needed to be considered user facing in context of the game itself. will change it to chore. |
…Extension() functions (#2635)
0d6d58d to
f85f88b
Compare
|
cleaned up the commit titles a touch as well |
I am not sure either. But typically we would expect a feature as something the user can see. Adding a few new functions that do not really change the game behavior are probably not recognized as a new feature. |
Merge by rebase
This PR has a small chore to remove the unused static
removeExtensions()function found in the gamestate.cpp file.It also implements some missing functions within UnicodeString for
findandreverseFindto give it parity withasciiStringOverall it implements the
getExtension()andremoveExtension()functions for AsciiString and UnicodeStrings withinTheFileSystem.