Skip to content

refactor(ini): Simplify token related INI code#2596

Merged
xezon merged 9 commits intoTheSuperHackers:mainfrom
Caball009:ini_small_refactor
Apr 16, 2026
Merged

refactor(ini): Simplify token related INI code#2596
xezon merged 9 commits intoTheSuperHackers:mainfrom
Caball009:ini_small_refactor

Conversation

@Caball009
Copy link
Copy Markdown

A handful of miscellaneous changes to the INI code. Should have zero change in behavior.

Generals and Zero Hour code are not separated, but the commit diffs are pretty clean.

@Caball009 Caball009 added Minor Severity: Minor < Major < Critical < Blocker Refactor Edits the code with insignificant behavior changes, is never user facing labels Apr 12, 2026
@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Apr 12, 2026

Greptile Summary

This PR refactors the INI parsing class for cleanliness and consistency: it converts separator and token accessor methods from instance methods backed by member fields to inline static methods returning string literals, makes getNextToken/getNextTokenOrNull/getNextSubToken static (they already only used global strtok state), removes the trivial empty destructor, and tidies call-sites across both Generals/ and GeneralsMD/ trees (normalising token != nullptrtoken, while-loops to for-loops, and replacing getNextTokenOrNull+null-check patterns with getNextToken). The PR author states zero behavioral change, and review confirms this — all comparisons of getEndToken() ("End" vs the old "END") remain via stricmp, and the CPP_11(= delete) macro addresses the earlier copy-protection concern.

Confidence Score: 5/5

This PR is safe to merge — all changes are zero-behavior refactoring with no new logic or data-flow introduced.

Every change is a mechanical cleanup: member separator fields replaced by static inline methods returning the same string literals, trivial empty destructor removed, getNextToken/OrNull/SubToken made static (they already only used global strtok state), and loop-condition style harmonised. The copy-protection concern from a prior review thread is properly addressed via CPP_11(= delete). No P0 or P1 findings remain.

No files require special attention.

Important Files Changed

Filename Overview
Core/GameEngine/Include/Common/INI.h Core INI class header: separator fields removed and replaced with static inline methods; copy/assignment protected via CPP_11(= delete); getNextToken/getNextTokenOrNull/getNextSubToken made static; trivial destructor declaration removed.
Core/GameEngine/Source/Common/INI/INI.cpp INI.cpp: constructor no longer initialises removed separator members; empty destructor body removed; null-seps guard removed from getNextToken/getNextTokenOrNull; parseSoundsList converted to constexpr + for-loop; minor token != nullptr → token cleanup throughout.
Generals/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp parseDebrisObjectNames: variable renamed from debrisName to token; pre-existing double-advance preserved (acknowledged, separate PR incoming).
Generals/Code/GameEngine/Source/GameLogic/Object/Update/AutoDepositUpdate.cpp parseUpgradePair: getNextTokenOrNull+manual null-check replaced with getNextToken (which throws on null — same exception type, equivalent behavior).
GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/OCLUpdate.cpp parseFactionObjectCreationList: same getNextTokenOrNull+null-check → getNextToken refactor as AutoDepositUpdate.
Generals/Code/GameEngine/Include/Common/BitFlagsIO.h BitFlags::parse: token != nullptr → token in loop condition, no functional change.

Class Diagram

%%{init: {'theme': 'neutral'}}%%
classDiagram
    class INI {
        -INI(const INI&) = delete
        -INI& operator=(const INI&) = delete
        +INI()
        +isEOF() bool
        +getFilename() AsciiString
        +getLoadType() INILoadType
        +getLineNum() UnsignedInt
        +getSeps()$ const char*
        +getSepsPercent()$ const char*
        +getSepsColon()$ const char*
        +getSepsQuote()$ const char*
        +getEndToken()$ const char*
        +getNextToken(seps)$ const char*
        +getNextTokenOrNull(seps)$ const char*
        +getNextSubToken(expected)$ const char*
        +initFromINI(what, parseTable) void
        +initFromINIMulti(what, parseTableList) void
        -m_readBuffer char*
        -m_readBufferUsed unsigned
        -m_filename AsciiString
        -m_loadType INILoadType
        -m_lineNum UnsignedInt
        -m_buffer char[]
        -m_endOfFile Bool
    }
    note for INI "Separator strings removed as member fields;\nnow returned by static inline methods.\ngetNextToken/OrNull/SubToken also made static."
Loading

Reviews (5): Last reviewed commit: "Merge branch 'main' into ini_small_refac..." | Re-trigger Greptile

Comment thread Core/GameEngine/Include/Common/INI.h
Comment thread Core/GameEngine/Include/Common/INI.h
Comment thread Core/GameEngine/Include/Common/INI.h
Comment thread Core/GameEngine/Source/Common/INI/INI.cpp Outdated
Comment thread Core/GameEngine/Source/Common/INI/INI.cpp Outdated
Copy link
Copy Markdown

@xezon xezon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs rebase.

Copy link
Copy Markdown

@xezon xezon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks stable

@xezon xezon changed the title refactor(ini): Make the INI code cleaner and more consistent refactor(ini): Simplify some INI code Apr 16, 2026
@xezon xezon changed the title refactor(ini): Simplify some INI code refactor(ini): Simplify token related INI code Apr 16, 2026
@xezon xezon merged commit 20d6cc0 into TheSuperHackers:main Apr 16, 2026
17 checks passed
@Caball009 Caball009 deleted the ini_small_refactor branch April 16, 2026 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Minor Severity: Minor < Major < Critical < Blocker Refactor Edits the code with insignificant behavior changes, is never user facing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants