Skip to content
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

Add is null or empty #228

Merged
merged 1 commit into from
Dec 7, 2023
Merged

Add is null or empty #228

merged 1 commit into from
Dec 7, 2023

Conversation

sirknightj
Copy link
Contributor

Issue #, if available:
N/A

Description of changes:

  • Add a new macro to check for null string or empty string. For readability purposes,
if (!IS_NULL_OR_EMPTY(str)) {

is better than these two

if (!(str == NULL || str[0] == '\0')) {
if (str != NULL && str[0] != '\0') {

Other considerations

Why don't we just use strlen(str) > 0?

  1. strlen has to traverse the entire string, so it's less efficient than a comparison with the null termination character.
  2. If str is NULL, using strlen directly may result in undefined behavior.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@sirknightj sirknightj added the enhancement New feature or request label Dec 7, 2023
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (83334d9) 75.12% compared to head (96dedbe) 75.12%.

❗ Current head 96dedbe differs from pull request most recent head 1514252. Consider uploading reports for the commit 1514252 to get more accurate results

Additional details and impacted files
@@           Coverage Diff            @@
##           develop     #228   +/-   ##
========================================
  Coverage    75.12%   75.12%           
========================================
  Files           52       52           
  Lines        10225    10225           
========================================
  Hits          7682     7682           
  Misses        2543     2543           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sirknightj sirknightj merged commit e611df2 into develop Dec 7, 2023
12 checks passed
@sirknightj sirknightj deleted the add-is-null-or-empty branch December 7, 2023 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants