canonical/mir

Replace `str(n)?cmp` with `std::string_view::operator==`

Open

#4,567 opened on Dec 16, 2025

View on GitHub
 (5 comments) (0 reactions) (1 assignee)C++ (137 forks)auto 404
Good first issue

Repository metrics

Stars
 (775 stars)
PR merge metrics
 (PR metrics pending)

Description

Lots of places in ourcodebase read strings from the environment or some external source and compare them to other strings. The use of str(n)?cmp can sometimes be confusing, and while std::string_view{string1} == std::string_view{string2} is a bit more verbose, it's a lot easier to reason about at a glance than strcmp(string1,string2) != 0.

Additionally, strncmp can be usually replaced with std::string_view::starts_with.

Examples:

https://github.com/canonical/mir/blob/7a9370befcace079fcc6d2103d5a33218462f86e/examples/miral-shell/shell_main.cpp#L59-L61

https://github.com/canonical/mir/blob/7a9370befcace079fcc6d2103d5a33218462f86e/tests/mir_test_framework/test_wlcs_display_server.cpp#L485

If std::string_view{...} == std::string_view{...} is too verbose, maybe wrapping that in a utility function would be a good middle ground?

Contributor guide