Skip to content

Conversation

@bobtista
Copy link

Extends the clang-tidy readability-container-size-empty check to our other string types

  • AsciiString/UnicodeString: getLength() == 0isEmpty()

  • StringClass/WideStringClass: Get_Length() == 0Is_Empty()

  • Also handles !=, >, and <= comparisons

  • Documentation - README with build and usage instructions

Example Fixes

// Before
if (str.getLength() == 0) { ... }
if (str.Get_Length() > 0) { ... }

// After
if (str.isEmpty()) { ... }
if (!str.Is_Empty()) { ... }## Usage

clang-tidy -p build/clang-tidy
--checks='-*,generals-use-is-empty'
-load tools/clang-tidy-plugin/build/lib/libGeneralsGameCodeClangTidyPlugin.so
-fix-errors
file.cpp## Testing

@xezon xezon added Tools Affects Tools only Refactor Edits the code with insignificant behavior changes, is never user facing and removed Refactor Edits the code with insignificant behavior changes, is never user facing labels Dec 14, 2025
@xezon xezon changed the title tools: add custom clang-tidy plugin for isEmpty() checks chore: Add custom clang-tidy plugin for isEmpty() checks Dec 14, 2025
xezon
xezon previously approved these changes Dec 14, 2025
@xezon
Copy link

xezon commented Dec 14, 2025

Is AsciiString::compare, AsciiString::compareNoCase, UnicodeString::compare, ... also supported?

@bobtista
Copy link
Author

Is AsciiString::compare, AsciiString::compareNoCase, UnicodeString::compare, ... also supported?

Yes, both are implemented inline:
compare() uses wcscmp()
compareNoCase() uses _wcsicmp()
All four methods are in the Core headers

@xezon
Copy link

xezon commented Dec 15, 2025

I mean will it work together with the clang tidy refactor:

if (myAscii.compare(otherAscii)) {}

@xezon
Copy link

xezon commented Dec 17, 2025

I looked in this change for keywords "compare" and "compareNoCase" and there was no match found. So I suspect that is missing.

@xezon xezon dismissed their stale review December 17, 2025 18:05

Looks incomplete

@bobtista
Copy link
Author

Is AsciiString::compare, AsciiString::compareNoCase, UnicodeString::compare, ... also supported?

I misunderstood., sorry! Added this for both compare and compareNoCase

// Before
if (myAscii.compare("") == 0) { }
if (myUnicode.compare(L"") == 0) { }

// After
if (myAscii.isEmpty()) { }
if (myUnicode.isEmpty()) { }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Tools Affects Tools only

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants