Skip to content

for Qstrings and QByteArrays prefer isEmpty() over size() and length()#1409

Merged
tsteven4 merged 2 commits intoGPSBabel:masterfrom
tsteven4:emptyqstrings
Feb 13, 2025
Merged

for Qstrings and QByteArrays prefer isEmpty() over size() and length()#1409
tsteven4 merged 2 commits intoGPSBabel:masterfrom
tsteven4:emptyqstrings

Conversation

@tsteven4
Copy link
Copy Markdown
Collaborator

@tsteven4 tsteven4 commented Feb 13, 2025

This applies the clang-tidy readability-container-size-empty check to QString and QByteArrays.

This check normally doesn't work because unlike QList QString and QByteArray don't have an empty() method. By editing qstring.h and qbytearray.h an empty() method can be added. When running clang-tidy use the export-fixes option as the fixes will use empty() instead of isEmpty(). Edit the fixes file changing the replacment text to use isEmpty() instead of empty(): 'g/ReplacementText/s/\.empty()/.isEmpty()/g' and 'g/ReplacementText/s/->empty()/->isEmpty()/g', and then run clang-apply-replacements.

You may note some replacements where the original code didn't use size() or length(), but instead used equality comparisons to "" or QString(). These were generated by the readability-container-size-empty check, and should work fine. I did compare the optionList generated by formatload and found it equivalent.

@tsteven4 tsteven4 merged commit a7cd1c9 into GPSBabel:master Feb 13, 2025
21 checks passed
@robertlipe
Copy link
Copy Markdown
Collaborator

robertlipe commented Feb 13, 2025 via email

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants